Skip to content

Commit be430bc

Browse files
committed
fix(build): fail the build when SSR rendering errors occur
1 parent a5a75bd commit be430bc

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/client/app/ssr.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,30 @@ export async function render(path: string) {
77
const { app, router } = await createApp()
88
await router.go(path)
99
const ctx: SSGContext = { content: '', vpSocialIcons: new Set<string>() }
10+
11+
// Vue's SSR renderer reports component errors through the app's error
12+
// handler and continues rendering instead of rejecting renderToString,
13+
// which would silently ship broken pages. Collect the errors and fail
14+
// the build instead.
15+
const errors: [unknown, string][] = []
16+
const userErrorHandler = app.config.errorHandler
17+
app.config.errorHandler = (err, instance, info) => {
18+
errors.push([err, info])
19+
userErrorHandler?.(err, instance, info)
20+
}
21+
1022
ctx.content = await renderToString(app, ctx)
23+
24+
if (errors.length) {
25+
const details = errors
26+
.map(([err, info]) =>
27+
err instanceof Error
28+
? `[${info}] ${err.stack || err.message}`
29+
: `[${info}] ${String(err)}`
30+
)
31+
.join('\n')
32+
throw new Error(`Errors during SSR rendering of ${path}:\n${details}`)
33+
}
34+
1135
return ctx
1236
}

0 commit comments

Comments
 (0)