fix(nuxt): allow url-specific chars in vfs (#30584)

This commit is contained in:
Daniel Roe 2025-01-14 13:10:25 +00:00 committed by GitHub
parent 2fee14df8b
commit 06d5840d26
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 9 additions and 9 deletions

View File

@ -38,25 +38,25 @@ export const VirtualFSPlugin = (nuxt: Nuxt, options: VirtualFSPluginOptions) =>
const resolvedId = resolveWithExt(id) const resolvedId = resolveWithExt(id)
if (resolvedId) { if (resolvedId) {
return PREFIX + resolvedId return PREFIX + encodeURIComponent(resolvedId)
} }
if (importer && RELATIVE_ID_RE.test(id)) { if (importer && RELATIVE_ID_RE.test(id)) {
const path = resolve(dirname(withoutPrefix(importer)), id) const path = resolve(dirname(withoutPrefix(importer)), id)
const resolved = resolveWithExt(path) const resolved = resolveWithExt(path)
if (resolved) { if (resolved) {
return PREFIX + resolved return PREFIX + encodeURIComponent(resolved)
} }
} }
}, },
loadInclude (id) { loadInclude (id) {
return id.startsWith(PREFIX) && withoutPrefix(id) in nuxt.vfs return id.startsWith(PREFIX) && withoutPrefix(decodeURIComponent(id)) in nuxt.vfs
}, },
load (id) { load (id) {
return { return {
code: nuxt.vfs[withoutPrefix(id)] || '', code: nuxt.vfs[withoutPrefix(decodeURIComponent(id))] || '',
map: null, map: null,
} }
}, },

View File

@ -287,9 +287,9 @@ export const PageMetaPlugin = (options: PageMetaPluginOptions = {}) => createUnp
handleHotUpdate: { handleHotUpdate: {
order: 'post', order: 'post',
handler: ({ file, modules, server }) => { handler: ({ file, modules, server }) => {
if (options.isPage?.(file)) { if (options.routesPath && options.isPage?.(file)) {
const macroModule = server.moduleGraph.getModuleById(file + '?macro=true') const macroModule = server.moduleGraph.getModuleById(file + '?macro=true')
const routesModule = server.moduleGraph.getModuleById('virtual:nuxt:' + options.routesPath) const routesModule = server.moduleGraph.getModuleById('virtual:nuxt:' + encodeURIComponent(options.routesPath))
return [ return [
...modules, ...modules,
...macroModule ? [macroModule] : [], ...macroModule ? [macroModule] : [],

View File

@ -44,7 +44,7 @@ export function viteNodePlugin (ctx: ViteBuildContext): VitePlugin {
// invalidate changed virtual modules when templates are regenerated // invalidate changed virtual modules when templates are regenerated
ctx.nuxt.hook('app:templatesGenerated', (_app, changedTemplates) => { ctx.nuxt.hook('app:templatesGenerated', (_app, changedTemplates) => {
for (const template of changedTemplates) { for (const template of changedTemplates) {
const mods = server.moduleGraph.getModulesByFile(`virtual:nuxt:${template.dst}`) const mods = server.moduleGraph.getModulesByFile(`virtual:nuxt:${encodeURIComponent(template.dst)}`)
for (const mod of mods || []) { for (const mod of mods || []) {
markInvalidate(mod) markInvalidate(mod)

View File

@ -212,7 +212,7 @@ export const bundle: NuxtBuilder['bundle'] = async (nuxt) => {
// Invalidate virtual modules when templates are re-generated // Invalidate virtual modules when templates are re-generated
ctx.nuxt.hook('app:templatesGenerated', (_app, changedTemplates) => { ctx.nuxt.hook('app:templatesGenerated', (_app, changedTemplates) => {
for (const template of changedTemplates) { for (const template of changedTemplates) {
for (const mod of server.moduleGraph.getModulesByFile(`virtual:nuxt:${template.dst}`) || []) { for (const mod of server.moduleGraph.getModulesByFile(`virtual:nuxt:${encodeURIComponent(template.dst)}`) || []) {
server.moduleGraph.invalidateModule(mod) server.moduleGraph.invalidateModule(mod)
server.reloadModule(mod) server.reloadModule(mod)
} }

View File

@ -134,7 +134,7 @@ if (process.env.TEST_ENV !== 'built' && !isWindows) {
'type': 'debug', 'type': 'debug',
}, },
{ {
'text': `[vite] hot updated: /@id/virtual:nuxt:${fixturePath}/.nuxt/routes.mjs`, 'text': `[vite] hot updated: /@id/virtual:nuxt:${encodeURIComponent(join(fixturePath, '.nuxt/routes.mjs'))}`,
'type': 'debug', 'type': 'debug',
}, },
]) ])