Skip to content

Commit 04a1fd6

Browse files
committed
chore: merge latest origin/dev into refactor_sanity_schema_structure
2 parents da202ff + 9d2f200 commit 04a1fd6

10 files changed

Lines changed: 67 additions & 17 deletions

File tree

‎apps/sanity/sanity.config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ const apiVersion = process.env.SANITY_STUDIO_API_VERSION || "2025-09-30";
4444
const presentationEnabled =
4545
process.env.SANITY_STUDIO_DISABLE_PRESENTATION !== "true";
4646

47-
// Use local dev server for presentation preview when running Studio locally
47+
// Use local Astro dev server for presentation preview when running Studio locally
4848
const isLocal =
4949
typeof import.meta !== "undefined" &&
5050
(import.meta as unknown as { env?: { DEV?: boolean } }).env?.DEV;

‎apps/site/src/components/DraftModeToggle.astro‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ const returnTo = Astro.url.pathname + Astro.url.search;
1010
<form
1111
method="POST"
1212
action="/api/draft-mode/disable"
13-
class="fixed bottom-4 right-4 z-50"
13+
data-sanity-preview
14+
class="fixed bottom-4 left-4 z-50"
1415
>
1516
<input type="hidden" name="returnTo" value={returnTo} />
1617
<button
1718
type="submit"
18-
class="rounded-full bg-primary px-4 py-2 text-sm font-medium text-primary-foreground shadow-lg hover:bg-primary/90 transition-colors"
19+
class="rounded-full bg-red-600 px-4 py-2 text-sm font-medium text-white shadow-lg hover:bg-red-700 transition-colors"
1920
>
2021
Exit draft mode
2122
</button>

‎apps/site/src/layouts/BaseLayout.astro‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,24 @@ const graph = buildGraph([
193193
<Footer />
194194
</div>
195195
{preview && <DraftModeToggle />}
196+
<script>
197+
import { enableVisualEditing } from "@sanity/visual-editing-standalone";
198+
199+
if (
200+
window.self !== window.top ||
201+
document.querySelector("[data-sanity-preview]")
202+
) {
203+
enableVisualEditing({
204+
refresh: (payload) => {
205+
if (payload.source === "mutation" || payload.source === "manual") {
206+
window.location.reload();
207+
return Promise.resolve();
208+
}
209+
return false;
210+
},
211+
});
212+
}
213+
</script>
196214
<ChatModal />
197215
<AnalyticsBeacon />
198216
</body>

‎apps/site/src/lib/sanity/config.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const DEFAULTS = {
2828
projectId: "hfh83o0w",
2929
dataset: "production",
3030
apiVersion: "2025-09-30",
31-
studioUrl: "https://codingcat.dev.sanity.studio/production",
31+
studioUrl: "https://codingcat-prod.sanity.studio",
3232
} as const;
3333

3434
function read(env: EnvLike | undefined, key: string): string | undefined {

‎apps/site/src/lib/sanity/preview.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ export function resolvePreview({
4646
perspectiveParam,
4747
}: ResolvePreviewInput): PreviewContext {
4848
const siteWide = env?.PUBLIC_SANITY_VISUAL_EDITING_ENABLED === "true";
49-
if (!siteWide && !hasPreviewCookie) {
49+
if (!siteWide && !hasPreviewCookie && !perspectiveParam) {
5050
return { enabled: false };
5151
}
5252

‎apps/site/src/middleware.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,11 @@ export const onRequest = defineMiddleware(async (context, next) => {
9090
"max-age=31536000; includeSubDomains; preload",
9191
);
9292
response.headers.set("X-Content-Type-Options", "nosniff");
93-
response.headers.set("X-Frame-Options", "SAMEORIGIN");
9493
response.headers.set("Referrer-Policy", "strict-origin-when-cross-origin");
95-
response.headers.set("Content-Security-Policy", "frame-ancestors 'self'");
94+
response.headers.set(
95+
"Content-Security-Policy",
96+
"frame-ancestors 'self' https://*.sanity.studio https://*.sanity.io https://sanity.io http://localhost:3333",
97+
);
9698

9799
// AIPREF / AI Preference Headers
98100
response.headers.set("Content-Usage", "train-ai=n, search=y");

‎apps/site/src/pages/api/draft-mode/disable.ts‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,33 @@ export const POST: APIRoute = async ({ request, url, cookies, redirect }) => {
4545
returnTo = url.searchParams.get("returnTo");
4646
}
4747

48+
const isHttps = url.protocol === "https:";
4849
cookies.delete(PREVIEW_COOKIE, { path: "/" });
49-
cookies.set(PREVIEW_COOKIE, "", { maxAge: 0, path: "/" });
50+
cookies.set(PREVIEW_COOKIE, "", {
51+
maxAge: 0,
52+
path: "/",
53+
httpOnly: true,
54+
secure: isHttps,
55+
sameSite: isHttps ? "none" : "lax",
56+
partitioned: isHttps,
57+
});
5058

5159
return redirect(resolveDestination(returnTo), 303);
5260
};
5361

5462
export const GET: APIRoute = async ({ url, cookies, redirect }) => {
5563
const returnTo = url.searchParams.get("returnTo");
64+
const isHttps = url.protocol === "https:";
5665

5766
cookies.delete(PREVIEW_COOKIE, { path: "/" });
58-
cookies.set(PREVIEW_COOKIE, "", { maxAge: 0, path: "/" });
67+
cookies.set(PREVIEW_COOKIE, "", {
68+
maxAge: 0,
69+
path: "/",
70+
httpOnly: true,
71+
secure: isHttps,
72+
sameSite: isHttps ? "none" : "lax",
73+
partitioned: isHttps,
74+
});
5975

6076
return redirect(resolveDestination(returnTo), 307);
6177
};

‎apps/site/src/pages/api/draft-mode/enable.ts‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,15 @@ export const GET: APIRoute = async ({ url, cookies, redirect }) => {
1010
(import.meta.env as Record<string, string | undefined>)
1111
?.SANITY_API_READ_TOKEN;
1212

13-
// Query params supported: secret, slug, returnTo
14-
const secret = url.searchParams.get("secret");
13+
// Query params supported: sanity-preview-secret/secret, sanity-preview-pathname/returnTo, slug, sanity-preview-perspective
14+
const secret =
15+
url.searchParams.get("sanity-preview-secret") ??
16+
url.searchParams.get("secret");
1517
const slug = url.searchParams.get("slug");
16-
const returnTo = url.searchParams.get("returnTo");
18+
const returnTo =
19+
url.searchParams.get("sanity-preview-pathname") ??
20+
url.searchParams.get("returnTo");
21+
const perspective = url.searchParams.get("sanity-preview-perspective");
1722

1823
if (!readToken) {
1924
console.warn(
@@ -35,11 +40,18 @@ export const GET: APIRoute = async ({ url, cookies, redirect }) => {
3540
destination = "/";
3641
}
3742

43+
if (perspective && !destination.includes("sanity-preview-perspective=")) {
44+
const sep = destination.includes("?") ? "&" : "?";
45+
destination = `${destination}${sep}sanity-preview-perspective=${encodeURIComponent(perspective)}`;
46+
}
47+
48+
const isHttps = url.protocol === "https:";
3849
cookies.set(PREVIEW_COOKIE, "true", {
3950
path: "/",
4051
httpOnly: true,
41-
secure: true,
42-
sameSite: "lax",
52+
secure: isHttps,
53+
sameSite: isHttps ? "none" : "lax",
54+
partitioned: isHttps,
4355
});
4456

4557
return redirect(destination, 307);

‎apps/site/tests/tier1-features.test.mjs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -877,7 +877,8 @@ describe("Tier 1 - Feature Coverage", () => {
877877
assert.equal(setCookieVal, "true");
878878
assert.equal(setCookieOpts.httpOnly, true);
879879
assert.equal(setCookieOpts.secure, true);
880-
assert.equal(setCookieOpts.sameSite, "lax");
880+
assert.equal(setCookieOpts.sameSite, "none");
881+
assert.equal(setCookieOpts.partitioned, true);
881882
});
882883

883884
it("6.7 POST and GET /api/draft-mode/disable clears __sanity_preview cookie and redirects", async () => {

‎apps/site/wrangler.jsonc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"PUBLIC_SANITY_PROJECT_ID": "hfh83o0w",
3939
"PUBLIC_SANITY_DATASET": "dev",
4040
"PUBLIC_SANITY_API_VERSION": "2025-09-30",
41-
"PUBLIC_SANITY_STUDIO_URL": "https://codingcat-dev.sanity.studio/dev",
41+
"PUBLIC_SANITY_STUDIO_URL": "https://codingcat-dev.sanity.studio",
4242
"SITE_URL": "https://dev.codingcat.dev",
4343
"FLIPCORE_API_URL": "https://api.flipfeeds.dev",
4444
"PUBLIC_FLIPCORE_WEB_URL": "https://flipfeeds.dev"
@@ -77,7 +77,7 @@
7777
"PUBLIC_SANITY_PROJECT_ID": "hfh83o0w",
7878
"PUBLIC_SANITY_DATASET": "production",
7979
"PUBLIC_SANITY_API_VERSION": "2025-09-30",
80-
"PUBLIC_SANITY_STUDIO_URL": "https://codingcat-dev.sanity.studio/production",
80+
"PUBLIC_SANITY_STUDIO_URL": "https://codingcat-prod.sanity.studio",
8181
"SITE_URL": "https://codingcat.dev",
8282
"FLIPCORE_API_URL": "https://api.flipfeeds.com",
8383
"PUBLIC_FLIPCORE_WEB_URL": "https://flipfeeds.com"

0 commit comments

Comments
 (0)