Module Authors + Upgrade Lab: Renderer Plugins, Rsbuild, and a Safe 4.7
Use renderer plugins and the render:document hook, adopt defineHandler, move from Rspack to Rsbuild, and finish with the security and upgrade checklist for Nuxt 4.7.
The last step is for the people who extend Nuxt, and for anyone about to upgrade a real app.
Renderer plugins#
Some modules need to add to the initial HTML. @nuxtjs/color-mode injects a small script; an analytics module injects a loader. On @nuxt/vite-server there is no Nitro to register a plugin with, so 4.7 adds a new place to live:
addRendererPlugin(resolve('./runtime/server/renderer'))
import type { RendererPlugin } from 'nuxt/server'
export default (({ hooks }) => {
hooks.hook('render:html', (html) => {
html.head.push(`<script>${script}</script>`)
})
}) satisfies RendererPlugin
A renderer plugin attaches to the renderer, not a particular server, so it works with Nitro v2, Nitro v3, and @nuxt/vite-server. On an older Nuxt, addRendererPlugin registers the same file as a Nitro plugin.
There is also a new render:document hook, called with the finished HTML document of a non-streamed response, after every render:html listener has run.
defineHandler from nuxt/server#
Nuxt 4.7 adds defineHandler to the portable server surface, with defineEventHandler as an alias. It matches Nitro v3:
import { defineHandler } from 'nuxt/server'
export default defineHandler(() => ({ hello: 'world' }))
On Nuxt 5 the same names are auto-imported from nuxt/server, so explicit imports written on 4.6 keep working unchanged.
Rsbuild instead of Rspack#
@nuxt/rspack-builder is deprecated. The replacement is @nuxt/rsbuild-builder:
pnpm remove @nuxt/rspack-builder
pnpm add -D @nuxt/rsbuild-builder
export default defineNuxtConfig({
builder: 'rsbuild',
})
It replaces the Rspack builder, which still works with a warning. Modules can use extendRsbuildConfig() and addRsbuildPlugin(), and addRspackPlugin() keeps working.
More for module authors#
build:environment:start,build:environment:done, andbuild:prerender:*hooks report every production bundle and prerendered route, whatever the builder.updateRuntimeConfig()accepts schemas for your module's options.defineHandlerfromnuxt/server, withdefineEventHandleras an alias.- A
nuxt.requesttracing channel around each request, so APM tools get the same span hierarchy with any server builder.
The security checklist#
The release fixes security issues. The three listed advisories:
- Route rules on
_payload.json(GHSA-jxc9-w3j6-pwp2, medium). A wildcardcache,swr, orisrrule combined with a more specific page rule could cache one user's payload and serve it to another. - Encoded slashes on catch-all routes (GHSA-vrh2-cfcx-c3fg, medium). An incomplete fix for an earlier advisory. A repeated or leading encoded slash could bypass route rules for a catch-all page.
- Dev server runtime config (GHSA-h5xj-x893-p5f7, low, development only). If
nuxt devis reachable from an untrusted network, private runtime config could be read from earlier Nitro build output.
If you use cache, swr, or isr route rules on pages with user-specific data, purge any CDN or edge cache that may already hold a _payload.json after you upgrade. The code fix does not evict old entries.
The upgrade checklist#
- Read the heads-up list. DevTools is separate;
vue ^3.5.46is required; template diagnostics are on;@nuxt/rspack-builderis deprecated;<NuxtClientFallback>is deprecated. - Run
npx nuxt upgrade --dedupe. It refreshes the lockfile and pulls in Nuxt CLI 4.1,my-badv1, andvite-plugin-checkerv1. - Add
@nuxt/devtoolsif you use it. Nuxt no longer installs it for you. - Fix
NUXT_B4025warnings. Addexternalto links that point at server routes,public/files, or other sites. - Check
globalThis.$fetch. If you read it from the console, an inline script, orpublic/, setexperimental.globalFetch: true. - Try
staticRoutes. If you do not add routes at runtime, it is free throughput. - Pilot Nitro v3 on a branch. Add
nitro, fix route rules and imports, turnnitroLegacyoff, run the build. - Purge caches if the payload advisory applies to you.
- Keep template diagnostics on. The noise is the point.
Do it yourself#
- Add a renderer plugin to a small module. Inject a meta tag.
- Move one handler to
defineHandlerfromnuxt/server. - Switch a test project to
builder: 'rsbuild'. - Run the upgrade checklist on the branch.
- Enable
staticRoutesandtypeCheck: 'dev'. - Run
nuxt buildandnuxt test(or your CI equivalent). - Deploy a preview, not production, and click through the pages that use route rules.
Gotchas#
- A renderer plugin is not a Nitro plugin. It runs with any server builder. If your code only works on Nitro, keep it a Nitro plugin.
render:documentonly fires for non-streamed responses. A streamed page does not have a finished document to hand you.- Rsbuild does not read the
webpackoptions. Some Rspack hooks change. Read the migration section before you switch. - The dev-server advisory is development only, but it is still real. Do not expose
nuxt devto a network you do not trust. - Nitro v3 is still a release candidate. Pilot it, do not bet the quarter on it.
- A green build is not a migration. Click the pages that use route rules, caching, and payload extraction.
Recap#
Renderer plugins give modules a server-agnostic place for HTML injection, defineHandler aligns Nuxt with Nitro v3, Rsbuild replaces Rspack, and the upgrade checklist is short enough to run today. Do the branch, do the preview, then ship.
That is Nuxt 4.7. The runway is real, and for the first time we are moving down it.
← Back to the series: Learning Nuxt 4.7.