From 39f8df2cd156ff6111546c67ff2a4d2a19304785 Mon Sep 17 00:00:00 2001 From: Julien Huang Date: Sat, 1 Aug 2026 14:52:21 +0200 Subject: [PATCH 1/2] fix(html-validate): wrap validation in a try/catch --- src/runtime/html-validate/nitro.plugin.ts | 40 +++++++++++++---------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/src/runtime/html-validate/nitro.plugin.ts b/src/runtime/html-validate/nitro.plugin.ts index bb391be..78468c8 100644 --- a/src/runtime/html-validate/nitro.plugin.ts +++ b/src/runtime/html-validate/nitro.plugin.ts @@ -31,7 +31,7 @@ const DEFAULT_RULES: RuleConfig = { 'no-inline-style': 'off', } -export default function (nitro) { +export default function (nitro) { const opts: ConfigData = defu({ extends: DEFAULT_EXTENDS, rules: DEFAULT_RULES, @@ -43,24 +43,30 @@ export default function (nitro) { nitro.hooks.hook('render:response', async (response, { event }) => { if (typeof response.body === 'string' && (response.headers?.['Content-Type'] || response.headers?.['content-type'])?.includes('html')) { - const formattedBody = await format(response.body, { plugins: [html], parser: 'html' }) - const results = await validator.validateString(formattedBody) + try { + const formattedBody = await format(response.body, { plugins: [html], parser: 'html' }) + const results = await validator.validateString(formattedBody) - if (response.body && results.errorCount > 0) { - const id = randomUUID() - const data: HtmlValidateReport = { - id, - path: event.path, - html: formattedBody, - results: results.results, + if (response.body && results.errorCount > 0) { + const id = randomUUID() + const data: HtmlValidateReport = { + id, + path: event.path, + html: formattedBody, + results: results.results, + } + response.body = addBeforeBodyEndTag( + response.body, + ``, + ) + nitro.hooks.callHook(HTML_VALIDATE_REPORT_HOOK, data).catch((error) => { + nitro.captureError(error instanceof Error ? error : new Error(String(error)), { event }) + }) } - response.body = addBeforeBodyEndTag( - response.body, - ``, - ) - nitro.hooks.callHook(HTML_VALIDATE_REPORT_HOOK, data).catch((error) => { - nitro.captureError(error instanceof Error ? error : new Error(String(error)), { event }) - }) + } catch (error) { + // https://github.com/nuxt/hints/issues/360 + // html validate can throw errors for some html + console.warn('HTML Validate error:', error instanceof Error ? error.message : String(error)) } } }) From 382463da106eec63ef8d59f4d548b0af8160ebb0 Mon Sep 17 00:00:00 2001 From: Julien Huang Date: Sat, 1 Aug 2026 15:05:33 +0200 Subject: [PATCH 2/2] chore: lint --- src/runtime/html-validate/nitro.plugin.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/runtime/html-validate/nitro.plugin.ts b/src/runtime/html-validate/nitro.plugin.ts index 78468c8..55b6bae 100644 --- a/src/runtime/html-validate/nitro.plugin.ts +++ b/src/runtime/html-validate/nitro.plugin.ts @@ -31,7 +31,7 @@ const DEFAULT_RULES: RuleConfig = { 'no-inline-style': 'off', } -export default function (nitro) { +export default function (nitro) { const opts: ConfigData = defu({ extends: DEFAULT_EXTENDS, rules: DEFAULT_RULES, @@ -63,7 +63,8 @@ export default function (nitro) { nitro.captureError(error instanceof Error ? error : new Error(String(error)), { event }) }) } - } catch (error) { + } + catch (error) { // https://github.com/nuxt/hints/issues/360 // html validate can throw errors for some html console.warn('HTML Validate error:', error instanceof Error ? error.message : String(error))