Preview
Developer preview
Developer Preview
This page documents the developer preview of the SDK, version 20.81.1-alpha.25.sha-f076f9b857.
The preview handler (GET /api/preview) connects Canvas to your app:
- Canvas opens
/api/preview?secret=…&path=…in the preview panel. - The handler checks the secret against
UNIFORM_PREVIEW_SECRET, and enables Next.js draft mode. - The handler redirects to the page with a 307 redirect.
- The middleware sees draft mode, and writes the draft state into the code. When the URL has
is_incontext_editing_mode, it writes the editor state. - The page renders draft content and adds the visual editing script. In the editor state, it also adds the editing markers.
Draft requests do not use edge mode. The browser chooses the personalization and test variants.
Change the preview path#
By default, the handler redirects to the path of the project map node. If the composition has no node, it uses the slug. Use resolveFullPath when your URLs are different from the project map paths:
app/api/preview/route.ts
The handler does not add the locale to the redirect URL of a composition. If your route uses the locale, put it into the path in resolveFullPath.
Pattern previews#
When Canvas shows a pattern, the handler redirects to playgroundPath with the id of the pattern. The middleware then rewrites the request to ${playgroundPath}/[code].
warning
The middleware finds a pattern preview only when the path is the same as playgroundPath. If processPlaygroundPath of the preview handler changes the path, for example to add a locale, the middleware does not find the pattern preview. Then the preview gives a 404.
Turn off draft mode#
Open /api/preview?disable=true&path=/about to turn off draft mode and go to /about.