Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use _error for development in streaming #31466

Merged
merged 4 commits into from Nov 16, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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})
huozhi marked this conversation as resolved.
Show resolved Hide resolved

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)
})
}