From 2fd4214781da955afeab879ed3f3c5b9d05a6371 Mon Sep 17 00:00:00 2001 From: alectimison-maker Date: Wed, 5 Aug 2026 15:17:26 +0800 Subject: [PATCH] fix: respect ignore during prerender --- playground/pages/ignored.vue | 5 +++++ src/module.ts | 5 ++++- test/module-prerender.test.ts | 9 ++++++++- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 playground/pages/ignored.vue diff --git a/playground/pages/ignored.vue b/playground/pages/ignored.vue new file mode 100644 index 00000000..bf9e5211 --- /dev/null +++ b/playground/pages/ignored.vue @@ -0,0 +1,5 @@ + diff --git a/src/module.ts b/src/module.ts index 0e567f9e..433ddb0a 100644 --- a/src/module.ts +++ b/src/module.ts @@ -65,7 +65,7 @@ export default defineNuxtModule({ if (!nuxt.options.dev) { const validatorPath = await resolvePath(fileURLToPath(new URL('./runtime/validator', import.meta.url))) - const { useChecker, getValidator } = await import(isWindows ? pathToFileURL(validatorPath).href : validatorPath) + const { useChecker, getValidator, isIgnored } = await import(isWindows ? pathToFileURL(validatorPath).href : validatorPath) const validator = getValidator(options) const { checkHTML, invalidPages } = useChecker(validator, usePrettier, logLevel) @@ -88,6 +88,9 @@ export default defineNuxtModule({ if (route.contents.match(NuxtRedirectHtmlRegex)) { return } + if (isIgnored(route.route, moduleOptions.ignore)) { + return + } checkHTML(route.route, route.contents) }) }) diff --git a/test/module-prerender.test.ts b/test/module-prerender.test.ts index fe10736d..5350c9ce 100644 --- a/test/module-prerender.test.ts +++ b/test/module-prerender.test.ts @@ -20,7 +20,8 @@ await setup({ hooks: { 'modules:before'() { const nuxt = useNuxt() - nuxt.options.nitro.prerender = { routes: ['/', '/redirect'] } + nuxt.options.htmlValidator = { ignore: ['/ignored'] } + nuxt.options.nitro.prerender = { routes: ['/', '/ignored', '/redirect'] } }, }, }, @@ -57,4 +58,10 @@ describe('Nuxt prerender', () => { expect.stringContaining(' element must have as content'), ) }) + + it('ignores configured pages', () => { + expect(console.error).not.toHaveBeenCalledWith( + expect.stringContaining('/ignored'), + ) + }) })