Skip to content

Commit

Permalink
Use _error for development in streaming (#31466)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
huozhi and kodiakhq[bot] committed Nov 16, 2021
1 parent 593d943 commit 55ab4f0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 16 deletions.
2 changes: 1 addition & 1 deletion packages/next/build/entries.ts
Expand Up @@ -162,7 +162,7 @@ export function createEntrypoints(
page,
absoluteAppPath: pages['/_app'],
absoluteDocumentPath: pages['/_document'],
absoluteErrorPath: pages['/_error'],
absoluteErrorPath: pages['/500'] || pages['/_error'],
absolutePagePath,
isServerComponent: isFlight,
buildId,
Expand Down
Expand Up @@ -16,7 +16,6 @@ export default async function middlewareRSCLoader(this: any) {
const stringifiedAbsolutePagePath = stringifyRequest(this, absolutePagePath)
const stringifiedAbsoluteAppPath = stringifyRequest(this, absoluteAppPath)
const stringifiedAbsoluteErrorPath = stringifyRequest(this, absoluteErrorPath)
const stringified500PagePath = stringifyRequest(this, './pages/500')
const stringifiedAbsoluteDocumentPath = stringifyRequest(
this,
absoluteDocumentPath
Expand All @@ -29,13 +28,7 @@ export default async function middlewareRSCLoader(this: any) {
import App from ${stringifiedAbsoluteAppPath}
import Document from ${stringifiedAbsoluteDocumentPath}
let ErrorPage
try {
ErrorPage = require(${stringified500PagePath}).default
} catch (_) {
ErrorPage = require(${stringifiedAbsoluteErrorPath}).default
}
const errorMod = require(${stringifiedAbsoluteErrorPath})
const {
default: Page,
Expand Down Expand Up @@ -125,9 +118,15 @@ export default async function middlewareRSCLoader(this: any) {
result = await renderToHTML(
req,
errorRes,
pathname,
'/_error',
query,
{ ...renderOpts, Component: ErrorPage }
{
...renderOpts,
Component: errorMod.default,
getStaticProps: errorMod.getStaticProps,
getServerSideProps: errorMod.getServerSideProps,
getStaticPaths: errorMod.getStaticPaths,
}
)
} catch (err) {
return new Response(
Expand Down
Expand Up @@ -157,7 +157,7 @@ describe('concurrentFeatures - prod', () => {
expect(html).toContain('foo.client')
})

runBasicTests(context)
runBasicTests(context, 'prod')
})

describe('concurrentFeatures - dev', () => {
Expand All @@ -182,7 +182,7 @@ describe('concurrentFeatures - dev', () => {
expect(content).toMatchInlineSnapshot('"foo.client"')
})

runBasicTests(context)
runBasicTests(context, 'dev')
})

const cssSuite = {
Expand Down Expand Up @@ -213,7 +213,8 @@ const documentSuite = {
runSuite('document', 'dev', documentSuite)
runSuite('document', 'prod', documentSuite)

async function runBasicTests(context) {
async function runBasicTests(context, env) {
const isDev = env === 'dev'
it('should render the correct html', async () => {
const homeHTML = await renderViaHTTP(context.appPort, '/')

Expand Down Expand Up @@ -242,7 +243,10 @@ async function runBasicTests(context) {
expect(dynamicRouteHTML2).toContain('[pid]')

expect(path404HTML).toContain('custom-404-page')
expect(path500HTML).toContain('custom-500-page')
// in dev mode: custom error page is still using default _error
expect(path500HTML).toContain(
isDev ? 'Internal Server Error' : 'custom-500-page'
)
expect(pathNotFoundHTML).toContain('custom-404-page')
})

Expand Down Expand Up @@ -330,6 +334,6 @@ function runSuite(suiteName, env, { runTests, before, after }) {
await killApp(context.server)
})

runTests(context)
runTests(context, env)
})
}

0 comments on commit 55ab4f0

Please sign in to comment.