← all posts
2026.11.24 · 4 min

Druxt 0.25.2; Drupal Canvas sites, no Drupal required

DrupalDruxtNuxt#Drupal Canvas

Druxt 0.25.2 renders Drupal Canvas pages in Nuxt, and you can try it in this post without installing anything. Press Run and a Nuxt 2 site boots in your browser. It reads a recording of a Drupal CMS site's API, so no Drupal is running behind it.

Druxt is the Fully Decoupled Drupal framework for Nuxt 2. Canvas is the page builder in Drupal CMS, and sites that have it installed now build. This release also keeps signed-in requests out of the server cache from the first request, makes v-model follow forms and filters, and reports why a resource failed to load. Upgrading takes one command and two checks.

Drupal CMS's Dashi site, rendered by Druxt 0.25.2 and Nuxt 2

Runs in your browser on StackBlitz, with nothing to install. It loads only when you press Run.

A Nuxt 2 site on druxt-site 0.15.2 and @druxt-contrib/canvas, reading the Dashi preset of Decoupled Drupal Mock. The source is on GitHub.

What's in the demo

I wanted a demo you could run without setting up Drupal. It runs two things side by side. The first is Decoupled Drupal Mock with its Dashi preset, which replays the JSON:API, Decoupled Router and menu responses recorded from a Drupal CMS 2.2.9 site running Canvas 1.12.0. The second is Nuxt, with this configuration:

nuxt.config.js
export default {
  modules: ['druxt-site', '@druxt-contrib/canvas'],
  druxt: {
    baseUrl: 'http://localhost:3005',
    proxy: { api: true },
  },
}
Dashi's front page, a Canvas page, rendered by the demo from the recording.

The front page and /canvas-external are Canvas pages. Druxt resolves them by path, with no Nuxt page files. Follow a link from the front page to a recipe or article, and Vue components read that node's fields to lay it out the way Dashi does.

To serve the same pages from your own Drupal, point baseUrl at it. @druxt-contrib/canvas renders each Canvas component through a Vue wrapper that you write, and the Druxt Canvas docs explain how to name them.

Building against Canvas

druxt-schema 0.12.2 builds sites that have Canvas installed (#1022). Druxt reads every entity view and form display at build time, and Canvas 1.12.0 answers 500 when JSON:API asks for the second page of them. Druxt now requests them in smaller batches, filtered by entity type and bundle. Canvas 1.13.0 still has the bug, and it's reported against Canvas.

If you patched Canvas to get your build through, you can keep the patch or remove it. Keep it if one bundle has more than 50 view or form displays, because the build still fails without it. The demo's recording returns every page, so you'll only see this fix on a live site.

Signed-in requests skip the cache

0.25.0 added a server cache for the JSON:API index and menus. It skips any request that carries credentials, but it only saw a token added by an Axios interceptor once the response came back. Until then, a signed-in visitor could get a response cached for anonymous visitors. 0.25.2 runs your request interceptors on a copy of each request before it checks the cache, so the cache turns off from the first request (#1018).

Register a plugin like this one under plugins in nuxt.config.js, reading the token from wherever your site stores it:

plugins/druxt-token.js
export default ({ $druxt, store }) => {
  $druxt.axios.interceptors.request.use((config) => {
    if (store.state.token) {
      config.headers.Authorization = `Bearer ${store.state.token}`
    }
    return config
  })
}

If an interceptor has side effects, such as logging, it can skip that dry run by checking config[Symbol.for('druxt.processCache.probe')]. If an interceptor is an async function, the cache skips it and only sees its token when the first response arrives, so set that token on the Axios defaults instead. @nuxtjs/auth-next already does this unless token.global is off. Menus work the same way, including when an interceptor adds credentials only to menu requests.

v-model that follows the form

v-model on the Druxt component now updates when the module changes its value (#1005), so an entity form reports each edit to its parent:

pages/edit/_uuid.vue
<template>
  <div>
    <Druxt
      v-model="entity"
      module="entity-form"
      :props-data="{ type: 'node--page', uuid }"
    />
    <pre>{{ entity }}</pre>
  </div>
</template>

<script>
export default {
  asyncData: ({ params }) => ({ uuid: params.uuid }),
  data: () => ({ entity: undefined }),
}
</script>

A value you set while the entity is loading is now kept when the entity arrives (#1036). A field rendered in another component's slot reads its own entity's data (#1020). v-model now works on every module alongside druxt-entity, so exposed Views filters apply (#1037). Changing a filter on page three of a view returns you to page one, as Drupal does (#1032).

When a resource fails

A failed druxt/getResource request now includes its status code, so you can send a 401 to the login page and treat a 404 as missing (#1013). A request that never reaches Drupal reports 500.

Send a 401 to the login page
async asyncData({ store, params, redirect }) {
  const resource = await store.dispatch('druxt/getResource', {
    type: 'node--page',
    id: params.id,
  })
  if (resource.error?.statusCode === 401) {
    return redirect('/user/login')
  }
  return { resource }
},

JSON:API links now reach the browser as paths, even when Drupal builds them with a different scheme or host, such as https:// behind a proxy. Client-side navigation stays on your frontend (#833). DruxtSiteMixin also imports in client-side code without pulling Node's fs into the bundle (#545). Thanks to Sebastix for reporting that one.

Upgrading

Upgrading druxt-site brings the other six packages with it. Druxt now requires axios 0.35.0 or later, so that the bundle holds one copy (#1029). Install both in one command:

Upgrade through druxt-site
npm i druxt-site@0.15.2 axios@0.35.0

If your package.json lists any other Druxt package directly, such as druxt-schema, add it to the command too. Otherwise the older copy stays at the top of node_modules, nuxt build loads it, and an old druxt-schema still fails on Canvas.

Empty strings behave differently too. The value of a module, field or exposed filter now stays '' instead of Vue reading it as true, and a custom field that emits '' passes it to its parent. If your code checks for undefined to detect a cleared field, check for '' as well.

Nuxt 2 is end of life. 0.x is for sites already running on it, and I want those sites solid before 1.0.0. New sites should start on Druxt 2. Next is 0.26.0, the multilingual release, due 8 December. It's the last 0.x before the 1.0.0 release candidate. 1.0.0 is due 2 February and Druxt 2 is due 20 April, both on the milestones page.

Which Canvas components does your site use, and which would you want rendered first?

Druxt is open source on GitHub. The demo's source is in Decipher/demo-druxt-canvas, ready to fork and point at your own Drupal site. Sponsorship keeps the 0.x line getting fixes like these while I build Druxt 2.

Read next

All posts

Discussion

via GitHub Discussions