-
Notifications
You must be signed in to change notification settings - Fork 27.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Respect non 200 status to page static generation response (#63731)
### What In static generation phase of app page, if there's any case that we're receiving 3xx/4xx status code from the response, we 're setting it into the static generation meta now to make sure they're still returning the same status after build. ### Why During static generation if there's any 3xx/4xx status code that is set in the response, we should respect to it, such as the ones caused by using `notFound()` to mark as 404 response or `redirect` to mark as `307` response. Closes NEXT-2895 Fixes #51021 Fixes #62228
- Loading branch information
Showing
12 changed files
with
115 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function Layout({ children }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
7 changes: 7 additions & 0 deletions
7
test/e2e/app-dir/static-generation-status/app/not-found-page/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { notFound } from 'next/navigation' | ||
|
||
export default function Page() { | ||
notFound() | ||
} | ||
|
||
export const dynamic = 'force-static' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Page() { | ||
return 'home' | ||
} |
7 changes: 7 additions & 0 deletions
7
test/e2e/app-dir/static-generation-status/app/redirect-page/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { redirect } from 'next/navigation' | ||
|
||
export default function Page() { | ||
redirect('/') | ||
} | ||
|
||
export const dynamic = 'force-static' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { createNextDescribe } from 'e2e-utils' | ||
|
||
createNextDescribe( | ||
'app-dir static-generation-status', | ||
{ | ||
files: __dirname, | ||
}, | ||
({ next }) => { | ||
it('should render the page using notFound with status 404', async () => { | ||
const { status } = await next.fetch('/not-found-page') | ||
expect(status).toBe(404) | ||
}) | ||
|
||
it('should render the page using redirect with status 307', async () => { | ||
const { status } = await next.fetch('/redirect-page', { | ||
redirect: 'manual', | ||
}) | ||
expect(status).toBe(307) | ||
}) | ||
|
||
it('should render the non existed route redirect with status 404', async () => { | ||
expect((await next.fetch('/does-not-exist')).status).toBe(404) | ||
}) | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default function RootLayout({ children }) { | ||
return ( | ||
<html> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
test/production/app-dir/parallel-routes-static/app/nested/@bar/bar/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Page() { | ||
return '@bar' | ||
} |
3 changes: 3 additions & 0 deletions
3
test/production/app-dir/parallel-routes-static/app/nested/@foo/foo/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Default() { | ||
return '@foo default' | ||
} |
9 changes: 9 additions & 0 deletions
9
test/production/app-dir/parallel-routes-static/app/nested/layout.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export default function Layout({ children, bar, foo }) { | ||
return ( | ||
<div> | ||
<h1>Layout</h1> | ||
<div id="foo-slot">{foo}</div> | ||
<div id="bar-slot">{bar}</div> | ||
</div> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
test/production/app-dir/parallel-routes-static/app/nested/page.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function Page() { | ||
return <div>Hello from Nested</div> | ||
} |
26 changes: 26 additions & 0 deletions
26
test/production/app-dir/parallel-routes-static/index.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { createNextDescribe } from 'e2e-utils' | ||
|
||
createNextDescribe( | ||
'app-dir parallel-routes-static', | ||
{ | ||
files: __dirname, | ||
}, | ||
({ next }) => { | ||
it('should static generate parallel routes', async () => { | ||
const rscExtension = process.env.__NEXT_EXPERIMENTAL_PPR | ||
? '.prefetch.rsc' | ||
: '.rsc' | ||
expect(await next.hasFile('.next/server/app/nested/foo.html')).toBe(true) | ||
expect(await next.hasFile('.next/server/app/nested/foo.meta')).toBe(true) | ||
expect( | ||
await next.hasFile(`.next/server/app/nested/foo${rscExtension}`) | ||
).toBe(true) | ||
|
||
expect(await next.hasFile('.next/server/app/nested/bar.html')).toBe(true) | ||
expect(await next.hasFile('.next/server/app/nested/bar.meta')).toBe(true) | ||
expect( | ||
await next.hasFile(`.next/server/app/nested/bar${rscExtension}`) | ||
).toBe(true) | ||
}) | ||
} | ||
) |