feat(Headless): Allow passing a view mode in Headless SDK's fetch page API
AI Disclosure: Yes used GPT-5.4
Add explicit viewMode support to headless routed page fetches so headless apps can request content-template rendering for a specific view mode, such as teaser, outside the Canvas preview iframe flow. This also keeps existing Canvas preview behavior working by continuing to fall back to the draft session’s stored preview view mode when no explicit viewMode is passed.
- Drupal canvas_headless content API now honors top-level viewMode for general routed content requests, not only preview-scoped ones.
/canvas/content-api?requestUri=/node/1&viewMode=teaser
@drupal-canvas/headlessnow supportsfetchPage(path, { viewMode }).@drupal-canvas/headless-next,@drupal-canvas/headless-nuxt, and@drupal-canvas/headless-astronow expose the samefetchPage(..., { viewMode })option.- Content API cache variation now accounts for explicit viewMode requests.
Testing instructions
- In Drupal, create content templates and for at least two view modes (ex. full, teaser) on the same content type and some nodes for it.
- In the Canvas repo, build the updated packages and prepare linking:
npm run buildnpm run packages:buildnpm link -wsdrush cr
- Check out and use the template changes from: https://github.com/drupal-canvas/headless-templates/pull/7
- In each headless template app you want to test, install/link the local packages and start the app (for nextjs template use
npm run dev -- --webpack) - Verify standalone app behavior.
- Open: http://localhost:3000/node/1
- Confirm it renders the default/full template
- Open: http://localhost:3000/node/1?viewMode=teaser
- Confirm it renders the teaser template
- Verify no regressions in Canvas UI
- Open the same content template in Canvas UI
- Switch between the available view modes
- Confirm the iframe preview renders the expected template for each selected view mode
Edited by Harumi Jang