Unverified Commit 93613d55 authored by Hannes Bornö's avatar Hannes Bornö Committed by GitHub

dynamic = 'error' should only throw if page didn't get exported (#43377)

`export const dynamic = "error"` should only throw if the page actually
didn't get exported during `next build`. Test already exist to make sure
it throws:
`test/integration/app-dynamic-error/app/dynamic-error/page.js`

Fixes #43059

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

- [ ] Implements an existing feature request or RFC. Make sure the
feature request has been accepted for implementation before opening a
PR.
- [ ] Related issues linked using `fixes #number`
- [ ]
[e2e](https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
parent eaaa1937
...@@ -328,18 +328,16 @@ export default async function exportPage({ ...@@ -328,18 +328,16 @@ export default async function exportPage({
const revalidate = (curRenderOpts as any).revalidate const revalidate = (curRenderOpts as any).revalidate
results.fromBuildExportRevalidate = revalidate results.fromBuildExportRevalidate = revalidate
if (isDynamicError) {
throw new Error(
`Page with dynamic = "error" encountered dynamic data method ${path}.`
)
}
if (revalidate !== 0) { if (revalidate !== 0) {
await promises.writeFile(htmlFilepath, html ?? '', 'utf8') await promises.writeFile(htmlFilepath, html ?? '', 'utf8')
await promises.writeFile( await promises.writeFile(
htmlFilepath.replace(/\.html$/, '.rsc'), htmlFilepath.replace(/\.html$/, '.rsc'),
flightData flightData
) )
} else if (isDynamicError) {
throw new Error(
`Page with dynamic = "error" encountered dynamic data method ${path}.`
)
} }
} catch (err: any) { } catch (err: any) {
if ( if (
......
...@@ -51,6 +51,9 @@ describe('app-dir static/dynamic handling', () => { ...@@ -51,6 +51,9 @@ describe('app-dir static/dynamic handling', () => {
'blog/tim.rsc', 'blog/tim.rsc',
'blog/tim/first-post.html', 'blog/tim/first-post.html',
'blog/tim/first-post.rsc', 'blog/tim/first-post.rsc',
'dynamic-error.html',
'dynamic-error.rsc',
'dynamic-error/page.js',
'dynamic-no-gen-params-ssr/[slug]/page.js', 'dynamic-no-gen-params-ssr/[slug]/page.js',
'dynamic-no-gen-params/[slug]/page.js', 'dynamic-no-gen-params/[slug]/page.js',
'force-static/[slug]/page.js', 'force-static/[slug]/page.js',
...@@ -107,6 +110,11 @@ describe('app-dir static/dynamic handling', () => { ...@@ -107,6 +110,11 @@ describe('app-dir static/dynamic handling', () => {
srcRoute: '/blog/[author]/[slug]', srcRoute: '/blog/[author]/[slug]',
dataRoute: '/blog/tim/first-post.rsc', dataRoute: '/blog/tim/first-post.rsc',
}, },
'/dynamic-error': {
dataRoute: '/dynamic-error.rsc',
initialRevalidateSeconds: false,
srcRoute: '/dynamic-error',
},
'/blog/seb/second-post': { '/blog/seb/second-post': {
initialRevalidateSeconds: false, initialRevalidateSeconds: false,
srcRoute: '/blog/[author]/[slug]', srcRoute: '/blog/[author]/[slug]',
......
export const dynamic = 'error'
export default function Page() {
return <p>Dynamic error</p>
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment