Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 1 addition & 14 deletions apps/site/src/components/DraftModeToggle.astro
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const returnTo = Astro.url.pathname + Astro.url.search;
<form
method="POST"
action="/api/draft-mode/disable"
data-sanity-preview
class="fixed bottom-4 right-4 z-50"
>
<input type="hidden" name="returnTo" value={returnTo} />
Expand All @@ -20,17 +21,3 @@ const returnTo = Astro.url.pathname + Astro.url.search;
Exit draft mode
</button>
</form>

<script>
import { enableVisualEditing } from "@sanity/visual-editing-standalone";

enableVisualEditing({
refresh: (payload) => {
if (payload.source === "mutation" || payload.source === "manual") {
window.location.reload();
return Promise.resolve();
}
return false;
},
});
</script>
18 changes: 18 additions & 0 deletions apps/site/src/layouts/BaseLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,24 @@ const graph = buildGraph([
<Footer />
</div>
{preview && <DraftModeToggle />}
<script>
import { enableVisualEditing } from "@sanity/visual-editing-standalone";

if (
window.self !== window.top ||
document.querySelector("[data-sanity-preview]")
) {
enableVisualEditing({
refresh: (payload) => {
if (payload.source === "mutation" || payload.source === "manual") {
window.location.reload();
return Promise.resolve();
}
return false;
},
});
}
</script>
<ChatModal />
<AnalyticsBeacon />
</body>
Expand Down
2 changes: 1 addition & 1 deletion apps/site/src/lib/sanity/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export function resolvePreview({
perspectiveParam,
}: ResolvePreviewInput): PreviewContext {
const siteWide = env?.PUBLIC_SANITY_VISUAL_EDITING_ENABLED === "true";
if (!siteWide && !hasPreviewCookie) {
if (!siteWide && !hasPreviewCookie && !perspectiveParam) {
return { enabled: false };
}

Expand Down
2 changes: 1 addition & 1 deletion apps/site/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export const onRequest = defineMiddleware(async (context, next) => {
response.headers.set("Referrer-Policy", "strict-origin-when-cross-origin");
response.headers.set(
"Content-Security-Policy",
"frame-ancestors 'self' https://*.sanity.studio http://localhost:3333",
"frame-ancestors 'self' https://*.sanity.studio https://*.sanity.io https://sanity.io http://localhost:3333",
);

// AIPREF / AI Preference Headers
Expand Down
Loading