Skip to content

[nextjs][create-content-sdk-app] Fix cross-origin editing cookies#520

Open
glorynguyen wants to merge 3 commits into
Sitecore:devfrom
glorynguyen:feature/fix-editing-cookies-samesite-vercel
Open

[nextjs][create-content-sdk-app] Fix cross-origin editing cookies#520
glorynguyen wants to merge 3 commits into
Sitecore:devfrom
glorynguyen:feature/fix-editing-cookies-samesite-vercel

Conversation

@glorynguyen

@glorynguyen glorynguyen commented Jun 17, 2026

Copy link
Copy Markdown

Description / Motivation

When the Content SDK Next.js App Router template is deployed to Vercel (or other serverless platforms), XM Cloud editing mode breaks completely:

  1. Editing cookies (__prerender_bypass, sc_mode, etc.) use default SameSite=Lax, which browsers block inside the cross-origin XM Cloud editor iframe (pages.sitecorecloud.io → rendering host)
  2. draftMode().isEnabled returns false in page.tsx because draft cookies don't propagate between Vercel serverless functions

This PR fixes both issues at two levels:

  • SDK level: createEditingRenderRouteHandlers() now patches all editing cookies with SameSite=None; Secure
  • Template level: Route handlers add a defense-in-depth cookie wrapper; page templates detect editing mode via URL searchParams as fallback when draftMode() fails

Editing on localhost remains unaffected.

Testing Details

  • Unit Test Added
  • Manual Test/Other (Please elaborate)

All 10 packages pass yarn test-packages (799 nextjs tests pass). yarn lint-packages passes with 0 errors. yarn api-extractor:verify passes with no public API surface changes. Manual verification: deploy to Vercel, open page in XM Cloud editor, confirm editing cookies show SameSite=None; Secure in DevTools, confirm page renders in editing mode.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

… draft mode detection on Vercel

- Patch editing cookies with SameSite=None; Secure in createEditingRenderRouteHandlers for cross-origin iframe compatibility
- Add cookie patching wrapper in App Router template route handlers as defense-in-depth
- Add fallback editing detection via URL searchParams when draftMode() returns false on serverless platforms
- Update both nextjs-app-router and nextjs-app-router-cache-components templates
@changeset-bot

changeset-bot Bot commented Jun 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 5c968d2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 2 packages
Name Type
@sitecore-content-sdk/nextjs Patch
create-content-sdk-app Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@glorynguyen glorynguyen changed the title [nextjs][create-content-sdk-app] Fix cross-origin editing cookies and… [nextjs][create-content-sdk-app] Fix cross-origin editing cookies Jun 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant