Commit 7780200e authored by Cursor Agent's avatar Cursor Agent

Add documentation link to route segment config incompatibility error message

Updated the error message for incompatible route segment configs
(e.g. 'dynamic', 'revalidate', 'runtime') with cacheComponents/useCache
to include a 'Learn more' link to the relevant docs page:
https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic

Updated all related test snapshots and expected output files.
Co-authored-by: 's avatarJimmy Lai <hello@jimmyl.ai>
parent 50d61f93
...@@ -117,6 +117,19 @@ impl Display for NextConfigProperty { ...@@ -117,6 +117,19 @@ impl Display for NextConfigProperty {
} }
} }
impl NextConfigProperty {
fn docs_url(&self) -> &'static str {
match self {
NextConfigProperty::CacheComponents => {
"https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic"
}
NextConfigProperty::UseCache => {
"https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic"
}
}
}
}
enum InvalidExportKind { enum InvalidExportKind {
General, General,
Metadata, Metadata,
...@@ -358,7 +371,7 @@ fn report_error(app_dir: &Option<PathBuf>, filepath: &str, error_kind: RSCErrorK ...@@ -358,7 +371,7 @@ fn report_error(app_dir: &Option<PathBuf>, filepath: &str, error_kind: RSCErrorK
vec![span], vec![span],
), ),
RSCErrorKind::NextRscErrIncompatibleRouteSegmentConfig(span, segment, property) => ( RSCErrorKind::NextRscErrIncompatibleRouteSegmentConfig(span, segment, property) => (
format!("Route segment config \"{segment}\" is not compatible with `nextConfig.{property}`. Please remove it."), format!("Route segment config \"{segment}\" is not compatible with `nextConfig.{property}`. Please remove it. Learn more: {}", property.docs_url()),
vec![span], vec![span],
), ),
RSCErrorKind::NextRscErrTaintWithoutConfig((api_name, span)) => ( RSCErrorKind::NextRscErrTaintWithoutConfig((api_name, span)) => (
......
x Route segment config "runtime" is not compatible with `nextConfig.cacheComponents`. Please remove it. x Route segment config "runtime" is not compatible with `nextConfig.cacheComponents`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic
,-[input.js:1:1] ,-[input.js:1:1]
1 | export const runtime = 'edge' 1 | export const runtime = 'edge'
: ^^^^^^^ : ^^^^^^^
2 | export const dynamic = 'force-dynamic' 2 | export const dynamic = 'force-dynamic'
`---- `----
x Route segment config "dynamic" is not compatible with `nextConfig.cacheComponents`. Please remove it. x Route segment config "dynamic" is not compatible with `nextConfig.cacheComponents`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic
,-[input.js:2:1] ,-[input.js:2:1]
1 | export const runtime = 'edge' 1 | export const runtime = 'edge'
2 | export const dynamic = 'force-dynamic' 2 | export const dynamic = 'force-dynamic'
: ^^^^^^^ : ^^^^^^^
3 | export const dynamicParams = false 3 | export const dynamicParams = false
`---- `----
x Route segment config "dynamicParams" is not compatible with `nextConfig.cacheComponents`. Please remove it. x Route segment config "dynamicParams" is not compatible with `nextConfig.cacheComponents`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic
,-[input.js:3:1] ,-[input.js:3:1]
2 | export const dynamic = 'force-dynamic' 2 | export const dynamic = 'force-dynamic'
3 | export const dynamicParams = false 3 | export const dynamicParams = false
: ^^^^^^^^^^^^^ : ^^^^^^^^^^^^^
4 | export const fetchCache = 'force-no-store' 4 | export const fetchCache = 'force-no-store'
`---- `----
x Route segment config "fetchCache" is not compatible with `nextConfig.cacheComponents`. Please remove it. x Route segment config "fetchCache" is not compatible with `nextConfig.cacheComponents`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic
,-[input.js:4:1] ,-[input.js:4:1]
3 | export const dynamicParams = false 3 | export const dynamicParams = false
4 | export const fetchCache = 'force-no-store' 4 | export const fetchCache = 'force-no-store'
: ^^^^^^^^^^ : ^^^^^^^^^^
5 | export const revalidate = 1 5 | export const revalidate = 1
`---- `----
x Route segment config "revalidate" is not compatible with `nextConfig.cacheComponents`. Please remove it. x Route segment config "revalidate" is not compatible with `nextConfig.cacheComponents`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic
,-[input.js:5:1] ,-[input.js:5:1]
4 | export const fetchCache = 'force-no-store' 4 | export const fetchCache = 'force-no-store'
5 | export const revalidate = 1 5 | export const revalidate = 1
......
x Route segment config "runtime" is not compatible with `nextConfig.experimental.useCache`. Please remove it. x Route segment config "runtime" is not compatible with `nextConfig.experimental.useCache`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic
,-[input.js:1:1] ,-[input.js:1:1]
1 | export const runtime = 'edge' 1 | export const runtime = 'edge'
: ^^^^^^^ : ^^^^^^^
......
...@@ -151,11 +151,11 @@ describe('Cache Components Dev Errors', () => { ...@@ -151,11 +151,11 @@ describe('Cache Components Dev Errors', () => {
} else if (isRspack) { } else if (isRspack) {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": " ╰─▶ × Error: x Route segment config "revalidate" is not compatible with \`nextConfig.cacheComponents\`. Please remove it.", "description": " ╰─▶ × Error: x Route segment config "revalidate" is not compatible with \`nextConfig.cacheComponents\`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/page.tsx "source": "./app/page.tsx
╰─▶ × Error: x Route segment config "revalidate" is not compatible with \`nextConfig.cacheComponents\`. Please remove it. ╰─▶ × Error: x Route segment config "revalidate" is not compatible with \`nextConfig.cacheComponents\`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic
│ ,-[1:1] │ ,-[1:1]
│ 1 | export const revalidate = 10 │ 1 | export const revalidate = 10
│ : ^^^^^^^^^^ │ : ^^^^^^^^^^
...@@ -170,11 +170,11 @@ describe('Cache Components Dev Errors', () => { ...@@ -170,11 +170,11 @@ describe('Cache Components Dev Errors', () => {
} else { } else {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": " x Route segment config "revalidate" is not compatible with \`nextConfig.cacheComponents\`. Please remove it.", "description": " x Route segment config "revalidate" is not compatible with \`nextConfig.cacheComponents\`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/page.tsx "source": "./app/page.tsx
Error: x Route segment config "revalidate" is not compatible with \`nextConfig.cacheComponents\`. Please remove it. Error: x Route segment config "revalidate" is not compatible with \`nextConfig.cacheComponents\`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic
,-[1:1] ,-[1:1]
1 | export const revalidate = 10 1 | export const revalidate = 10
: ^^^^^^^^^^ : ^^^^^^^^^^
......
...@@ -38,27 +38,27 @@ describe('cache-components-route-handler-errors', () => { ...@@ -38,27 +38,27 @@ describe('cache-components-route-handler-errors', () => {
) )
} else { } else {
expect(redbox.description).toMatchInlineSnapshot( expect(redbox.description).toMatchInlineSnapshot(
`" x Route segment config "dynamic" is not compatible with \`nextConfig.cacheComponents\`. Please remove it."` `" x Route segment config "dynamic" is not compatible with \`nextConfig.cacheComponents\`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic"`
) )
} }
expect(redbox.source).toContain( expect(redbox.source).toContain(
'"dynamic" is not compatible with `nextConfig.cacheComponents`. Please remove it.' '"dynamic" is not compatible with `nextConfig.cacheComponents`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic'
) )
} else { } else {
// In build mode, check for all three errors in the output // In build mode, check for all three errors in the output
expect(next.cliOutput).toContain('./app/route-with-dynamic/route.ts') expect(next.cliOutput).toContain('./app/route-with-dynamic/route.ts')
expect(next.cliOutput).toContain( expect(next.cliOutput).toContain(
'"dynamic" is not compatible with `nextConfig.cacheComponents`. Please remove it.' '"dynamic" is not compatible with `nextConfig.cacheComponents`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic'
) )
expect(next.cliOutput).toContain('./app/route-with-revalidate/route.ts') expect(next.cliOutput).toContain('./app/route-with-revalidate/route.ts')
expect(next.cliOutput).toContain( expect(next.cliOutput).toContain(
'"revalidate" is not compatible with `nextConfig.cacheComponents`. Please remove it.' '"revalidate" is not compatible with `nextConfig.cacheComponents`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic'
) )
expect(next.cliOutput).toContain('./app/route-with-fetchcache/route.ts') expect(next.cliOutput).toContain('./app/route-with-fetchcache/route.ts')
expect(next.cliOutput).toContain( expect(next.cliOutput).toContain(
'"fetchCache" is not compatible with `nextConfig.cacheComponents`. Please remove it.' '"fetchCache" is not compatible with `nextConfig.cacheComponents`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic'
) )
} }
}) })
......
...@@ -54,7 +54,7 @@ function filterBrowserLogs(output: string): string { ...@@ -54,7 +54,7 @@ function filterBrowserLogs(output: string): string {
3 | export default function Page() { 3 | export default function Page() {
4 | return <div>Test page under app/</div> 4 | return <div>Test page under app/</div>
Route segment config "runtime" is not compatible with \`nextConfig.cacheComponents\`. Please remove it." Route segment config "runtime" is not compatible with \`nextConfig.cacheComponents\`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic"
`) `)
// Count occurrences of the layout error at the specific location // Count occurrences of the layout error at the specific location
// Filter out browser logs to avoid counting forwarded browser errors // Filter out browser logs to avoid counting forwarded browser errors
...@@ -69,10 +69,10 @@ function filterBrowserLogs(output: string): string { ...@@ -69,10 +69,10 @@ function filterBrowserLogs(output: string): string {
expect(next.cliOutput).toContain('./app/edge-with-layout/layout.tsx') expect(next.cliOutput).toContain('./app/edge-with-layout/layout.tsx')
expect(next.cliOutput).toContain('./app/edge-with-layout/edge/page.tsx') expect(next.cliOutput).toContain('./app/edge-with-layout/edge/page.tsx')
expect(next.cliOutput).toContain( expect(next.cliOutput).toContain(
'"dynamic" is not compatible with `nextConfig.cacheComponents`. Please remove it.' '"dynamic" is not compatible with `nextConfig.cacheComponents`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic'
) )
expect(next.cliOutput).toContain( expect(next.cliOutput).toContain(
'"runtime" is not compatible with `nextConfig.cacheComponents`. Please remove it.' '"runtime" is not compatible with `nextConfig.cacheComponents`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic'
) )
// Count occurrences of the layout error at the specific location // Count occurrences of the layout error at the specific location
const layoutErrorMatches = next.cliOutput.match( const layoutErrorMatches = next.cliOutput.match(
......
...@@ -38,31 +38,31 @@ describe('cache-components-segment-configs', () => { ...@@ -38,31 +38,31 @@ describe('cache-components-segment-configs', () => {
) )
} else { } else {
expect(redbox.description).toMatchInlineSnapshot( expect(redbox.description).toMatchInlineSnapshot(
`" x Route segment config "revalidate" is not compatible with \`nextConfig.cacheComponents\`. Please remove it."` `" x Route segment config "revalidate" is not compatible with \`nextConfig.cacheComponents\`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic"`
) )
} }
expect(redbox.source).toContain( expect(redbox.source).toContain(
'"revalidate" is not compatible with `nextConfig.cacheComponents`. Please remove it.' '"revalidate" is not compatible with `nextConfig.cacheComponents`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic'
) )
} else { } else {
expect(next.cliOutput).toContain('./app/dynamic-params/[slug]/page.tsx') expect(next.cliOutput).toContain('./app/dynamic-params/[slug]/page.tsx')
expect(next.cliOutput).toContain( expect(next.cliOutput).toContain(
'"dynamicParams" is not compatible with `nextConfig.cacheComponents`. Please remove it.' '"dynamicParams" is not compatible with `nextConfig.cacheComponents`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic'
) )
expect(next.cliOutput).toContain('./app/dynamic/nested/page.tsx') expect(next.cliOutput).toContain('./app/dynamic/nested/page.tsx')
expect(next.cliOutput).toContain('./app/dynamic/page.tsx') expect(next.cliOutput).toContain('./app/dynamic/page.tsx')
expect(next.cliOutput).toContain( expect(next.cliOutput).toContain(
'"dynamic" is not compatible with `nextConfig.cacheComponents`. Please remove it.' '"dynamic" is not compatible with `nextConfig.cacheComponents`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic'
) )
expect(next.cliOutput).toContain('./app/fetch-cache/page.tsx') expect(next.cliOutput).toContain('./app/fetch-cache/page.tsx')
expect(next.cliOutput).toContain( expect(next.cliOutput).toContain(
'"fetchCache" is not compatible with `nextConfig.cacheComponents`. Please remove it.' '"fetchCache" is not compatible with `nextConfig.cacheComponents`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic'
) )
expect(next.cliOutput).toContain('./app/revalidate/page.tsx') expect(next.cliOutput).toContain('./app/revalidate/page.tsx')
expect(next.cliOutput).toContain( expect(next.cliOutput).toContain(
'"revalidate" is not compatible with `nextConfig.cacheComponents`. Please remove it.' '"revalidate" is not compatible with `nextConfig.cacheComponents`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic'
) )
} }
}) })
...@@ -99,16 +99,16 @@ describe('cache-components-segment-configs', () => { ...@@ -99,16 +99,16 @@ describe('cache-components-segment-configs', () => {
) )
} else { } else {
expect(redbox.description).toMatchInlineSnapshot( expect(redbox.description).toMatchInlineSnapshot(
`" x Route segment config "runtime" is not compatible with \`nextConfig.cacheComponents\`. Please remove it."` `" x Route segment config "runtime" is not compatible with \`nextConfig.cacheComponents\`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic"`
) )
} }
expect(redbox.source).toContain( expect(redbox.source).toContain(
'"runtime" is not compatible with `nextConfig.cacheComponents`. Please remove it.' '"runtime" is not compatible with `nextConfig.cacheComponents`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic'
) )
} else { } else {
await retry(async () => { await retry(async () => {
expect(next.cliOutput).toContain( expect(next.cliOutput).toContain(
'"runtime" is not compatible with `nextConfig.cacheComponents`. Please remove it.' '"runtime" is not compatible with `nextConfig.cacheComponents`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic'
) )
// the stack trace is different between turbopack/webpack // the stack trace is different between turbopack/webpack
......
...@@ -35,11 +35,11 @@ describe('use-cache-segment-configs', () => { ...@@ -35,11 +35,11 @@ describe('use-cache-segment-configs', () => {
} else if (isRspack) { } else if (isRspack) {
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": " ╰─▶ × Error: x Route segment config "runtime" is not compatible with \`nextConfig.experimental.useCache\`. Please remove it.", "description": " ╰─▶ × Error: x Route segment config "runtime" is not compatible with \`nextConfig.experimental.useCache\`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "<FIXME-nextjs-internal-source> "source": "<FIXME-nextjs-internal-source>
╰─▶ × Error: x Route segment config "runtime" is not compatible with \`nextConfig.experimental.useCache\`. Please remove it. ╰─▶ × Error: x Route segment config "runtime" is not compatible with \`nextConfig.experimental.useCache\`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic
│ ,-[1:1] │ ,-[1:1]
│ 1 | export const runtime = 'edge' │ 1 | export const runtime = 'edge'
│ : ^^^^^^^ │ : ^^^^^^^
...@@ -55,11 +55,11 @@ describe('use-cache-segment-configs', () => { ...@@ -55,11 +55,11 @@ describe('use-cache-segment-configs', () => {
// FIXME: Fix broken import trace for Webpack loader resource. // FIXME: Fix broken import trace for Webpack loader resource.
await expect(browser).toDisplayRedbox(` await expect(browser).toDisplayRedbox(`
{ {
"description": " x Route segment config "runtime" is not compatible with \`nextConfig.experimental.useCache\`. Please remove it.", "description": " x Route segment config "runtime" is not compatible with \`nextConfig.experimental.useCache\`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "<FIXME-nextjs-internal-source> "source": "<FIXME-nextjs-internal-source>
Error: x Route segment config "runtime" is not compatible with \`nextConfig.experimental.useCache\`. Please remove it. Error: x Route segment config "runtime" is not compatible with \`nextConfig.experimental.useCache\`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic
,-[1:1] ,-[1:1]
1 | export const runtime = 'edge' 1 | export const runtime = 'edge'
: ^^^^^^^ : ^^^^^^^
...@@ -87,7 +87,7 @@ describe('use-cache-segment-configs', () => { ...@@ -87,7 +87,7 @@ describe('use-cache-segment-configs', () => {
3 | export default function Page() { 3 | export default function Page() {
4 | return <div>This page uses \`export const runtime\`.</div> 4 | return <div>This page uses \`export const runtime\`.</div>
Route segment config "runtime" is not compatible with \`nextConfig.experimental.useCache\`. Please remove it. Route segment config "runtime" is not compatible with \`nextConfig.experimental.useCache\`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic
at <unknown> (./app/runtime/page.tsx:1:14) at <unknown> (./app/runtime/page.tsx:1:14)
...@@ -97,7 +97,7 @@ describe('use-cache-segment-configs', () => { ...@@ -97,7 +97,7 @@ describe('use-cache-segment-configs', () => {
expect(buildOutput).toMatchInlineSnapshot(` expect(buildOutput).toMatchInlineSnapshot(`
" "
// TODO(veil): Fix broken import trace for Webpack loader resource. // TODO(veil): Fix broken import trace for Webpack loader resource.
╰─▶ × Error: x Route segment config "runtime" is not compatible with \`nextConfig.experimental.useCache\`. Please remove it. ╰─▶ × Error: x Route segment config "runtime" is not compatible with \`nextConfig.experimental.useCache\`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic
│ ,-[1:1] │ ,-[1:1]
│ 1 | export const runtime = 'edge' │ 1 | export const runtime = 'edge'
│ : ^^^^^^^ │ : ^^^^^^^
...@@ -118,7 +118,7 @@ describe('use-cache-segment-configs', () => { ...@@ -118,7 +118,7 @@ describe('use-cache-segment-configs', () => {
expect(buildOutput).toMatchInlineSnapshot(` expect(buildOutput).toMatchInlineSnapshot(`
" "
// TODO(veil): Fix broken import trace for Webpack loader resource. // TODO(veil): Fix broken import trace for Webpack loader resource.
Error: x Route segment config "runtime" is not compatible with \`nextConfig.experimental.useCache\`. Please remove it. Error: x Route segment config "runtime" is not compatible with \`nextConfig.experimental.useCache\`. Please remove it. Learn more: https://nextjs.org/docs/app/getting-started/cache-components#dynamic--force-dynamic
,-[1:1] ,-[1:1]
1 | export const runtime = 'edge' 1 | export const runtime = 'edge'
: ^^^^^^^ : ^^^^^^^
......
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