Sets up an API route for enabling draft mode, can be paired with the previewUrl.previewMode.enable in sanity/presentation.
Can also be used with sanity-plugin-iframe-pane.
When the preview loads in a cross-site iframe (Presentation Tool), draft-mode
cookies are set with the CHIPS Partitioned attribute so Safari 18.4+ stores
them despite third-party cookie blocking. Top-level / same-site requests keep
unpartitioned cookies so draftMode().disable() continues to work.
Some browsers reject even Partitioned cookies in cross-site iframes, for
example Firefox with Enhanced Tracking Protection configured to block all
third-party cookies ("Cookie has been rejected as third-party"). Because a
silent redirect would then land on a preview that can never enter draft
mode, cross-site iframe requests are redirected back to this route once with
a probe search param to verify the cookies were stored. If they were not,
the route responds with an interstitial that requests unpartitioned cookie
access through the Storage Access API and retries, or explains how to
unblock the preview when the browser refuses. Requests that carry the
Sec-Fetch-Storage-Access: inactive header are asked to retry with the
already-granted permission activated (Storage Access Headers).
Sets up an API route for enabling draft mode, can be paired with the
previewUrl.previewMode.enableinsanity/presentation. Can also be used withsanity-plugin-iframe-pane.When the preview loads in a cross-site iframe (Presentation Tool), draft-mode cookies are set with the CHIPS
Partitionedattribute so Safari 18.4+ stores them despite third-party cookie blocking. Top-level / same-site requests keep unpartitioned cookies sodraftMode().disable()continues to work.Some browsers reject even
Partitionedcookies in cross-site iframes, for example Firefox with Enhanced Tracking Protection configured to block all third-party cookies ("Cookie has been rejected as third-party"). Because a silent redirect would then land on a preview that can never enter draft mode, cross-site iframe requests are redirected back to this route once with a probe search param to verify the cookies were stored. If they were not, the route responds with an interstitial that requests unpartitioned cookie access through the Storage Access API and retries, or explains how to unblock the preview when the browser refuses. Requests that carry theSec-Fetch-Storage-Access: inactiveheader are asked to retry with the already-granted permission activated (Storage Access Headers).