Skip to content

Commit

Permalink
fix(nitro): ensure ssr error statusCode is a number (#19001)
Browse files Browse the repository at this point in the history
  • Loading branch information
clarkdo committed Feb 13, 2023
1 parent 54739e4 commit 859fbd0
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/nuxt/src/app/nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ interface _NuxtApp {
rendered?: Function
error?: Error | {
url: string
statusCode: string
statusCode: number
statusMessage: string
message: string
description: string
Expand Down
7 changes: 6 additions & 1 deletion packages/nuxt/src/core/runtime/nitro/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,13 @@ export default defineRenderHandler(async (event) => {

// Whether we're rendering an error page
const ssrError = event.node.req.url?.startsWith('/__nuxt_error')
? getQuery(event) as Exclude<NuxtApp['payload']['error'], Error>
? getQuery(event) as unknown as Exclude<NuxtApp['payload']['error'], Error>
: null

if (ssrError && ssrError.statusCode) {
ssrError.statusCode = parseInt(ssrError.statusCode as any)
}

if (ssrError && event.node.req.socket.readyState !== 'readOnly' /* direct request */) {
throw createError('Cannot directly render error page!')
}
Expand Down
2 changes: 1 addition & 1 deletion test/bundle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe.skipIf(isWindows)('minimal nuxt application', () => {

it('default server bundle size', async () => {
stats.server = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir)
expect(stats.server.totalBytes).toBeLessThan(90000)
expect(stats.server.totalBytes).toBeLessThan(90200)

const modules = await analyzeSizes('node_modules/**/*', serverDir)
expect(modules.totalBytes).toBeLessThan(2700000)
Expand Down

0 comments on commit 859fbd0

Please sign in to comment.