Skip to content

Commit 66fe6b2

Browse files
committed
fix: enhance local development and presentation configuration
- Updated local development check to ensure compatibility with Astro's environment. - Modified preview URL handling to include initial value and allow origins for iframe communication. - Clarified environment variable documentation for SANITY_API_READ_TOKEN and added notes for local visual editing setup.
1 parent 292a44e commit 66fe6b2

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

apps/sanity/sanity.config.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@ const presentationEnabled =
5959
process.env.SANITY_STUDIO_DISABLE_PRESENTATION !== "true";
6060

6161
// Use local Astro dev server for presentation preview when running Studio locally
62-
const isLocal = typeof import.meta !== "undefined" && import.meta.env?.DEV;
62+
const isLocal =
63+
typeof import.meta !== "undefined" &&
64+
(import.meta as unknown as { env?: { DEV?: boolean } }).env?.DEV;
6365
const localPreviewOrigin = "http://localhost:4321";
6466

6567
// ── Shared helpers ───────────────────────────────────────────────────
@@ -223,12 +225,14 @@ function buildPlugins(previewUrl: string): PluginOptions[] {
223225
},
224226
},
225227
previewUrl: {
226-
origin: previewUrl,
228+
initial: previewUrl,
227229
previewMode: {
228230
enable: "/api/draft-mode/enable",
229231
disable: "/api/draft-mode/disable",
230232
},
231233
},
234+
// Required: allow preview iframe origin to send postMessage to Studio (visual editing)
235+
allowOrigins: [previewUrl],
232236
}),
233237
]
234238
: []),

apps/web/.env.example

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22
SANITY_PROJECT_ID=hfh83o0w
33
SANITY_DATASET=production
44
SANITY_API_TOKEN=
5-
# SANITY_API_READ_TOKEN = viewer token for draft mode / Visual Editing (optional; required for Presentation tool)
5+
# SANITY_API_READ_TOKEN = viewer token for draft mode / Visual Editing (required for Presentation tool; set in .dev.vars for Cloudflare)
6+
7+
# Visual Editing (optional; for local dev or when not using draft-mode cookie)
8+
# PUBLIC_SANITY_VISUAL_EDITING_ENABLED=true
9+
# When running Studio locally, point overlay "edit" links to your Studio:
10+
# PUBLIC_SANITY_STUDIO_URL=http://localhost:3333
611

712
# Auth (better-auth)
813
BETTER_AUTH_SECRET=

apps/web/src/pages/api/draft-mode/enable.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
* the Sanity dataset). Sets a __sanity_preview cookie and redirects.
77
*
88
* Requires SANITY_API_READ_TOKEN (viewer rights). No SANITY_PREVIEW_SECRET needed.
9+
* With Cloudflare: set in .dev.vars (local) or Wrangler secrets (production).
10+
* Astro v6: use only 'import { env } from "cloudflare:workers"' (locals.runtime.env was removed).
911
*/
1012
import type { APIRoute } from "astro";
1113
import { createClient } from "@sanity/client";

0 commit comments

Comments
 (0)