Skip to content

Commit

Permalink
fix not found
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Aug 14, 2024
1 parent 4c763cd commit adb7026
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions packages/next/src/server/app-render/app-render.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,6 @@ async function renderToStream(
tree: LoaderTree,
formState: any
): Promise<ReadableStream<Uint8Array>> {
const is404 = res.statusCode === 404
const renderOpts = ctx.renderOpts
const ComponentMod = renderOpts.ComponentMod
// TODO: fix this typescript
Expand Down Expand Up @@ -1280,7 +1279,7 @@ async function renderToStream(

try {
// This is a dynamic render. We don't do dynamic tracking because we're not prerendering
const RSCPayload = await getRSCPayload(tree, ctx, is404)
const RSCPayload = await getRSCPayload(tree, ctx, res.statusCode === 404)
const reactServerStream = ComponentMod.renderToReadableStream(
RSCPayload,
clientReferenceManifest.clientModules,
Expand Down Expand Up @@ -1484,6 +1483,7 @@ async function renderToStream(
setHeader('Location', redirectUrl)
}

const is404 = res.statusCode === 404
if (!is404 && !hasRedirectError && !shouldBailoutToCSR) {
res.statusCode = 500
}
Expand Down Expand Up @@ -1602,7 +1602,6 @@ async function prerenderToStream(
staticGenerationStore: StaticGenerationStore,
tree: LoaderTree
): Promise<PrenderToStringResult> {
const is404 = res.statusCode === 404
// When prerendering formState is always null. We still include it
// because some shared APIs expect a formState value and this is slightly
// more explicit than making it an optional function argument
Expand Down Expand Up @@ -1705,7 +1704,7 @@ async function prerenderToStream(
const reactServerPrerenderStore = {
dynamicTracking,
}
const RSCPayload = await getRSCPayload(tree, ctx, is404)
const RSCPayload = await getRSCPayload(tree, ctx, res.statusCode === 404)
const reactServerStream: ReadableStream<Uint8Array> =
prerenderAsyncStorage.run(
reactServerPrerenderStore,
Expand Down Expand Up @@ -1869,7 +1868,7 @@ async function prerenderToStream(
} else {
// This is a regular static generation. We don't do dynamic tracking because we rely on
// the old-school dynamic error handling to bail out of static generation
const RSCPayload = await getRSCPayload(tree, ctx, is404)
const RSCPayload = await getRSCPayload(tree, ctx, res.statusCode === 404)
const reactServerStream = ComponentMod.renderToReadableStream(
RSCPayload,
clientReferenceManifest.clientModules,
Expand Down Expand Up @@ -1993,6 +1992,7 @@ async function prerenderToStream(
setHeader('Location', redirectUrl)
}

const is404 = res.statusCode === 404
if (!is404 && !hasRedirectError && !shouldBailoutToCSR) {
res.statusCode = 500
}
Expand Down

0 comments on commit adb7026

Please sign in to comment.