-
Notifications
You must be signed in to change notification settings - Fork 29.5k
fix: route handlers should validate invalid exports #83500
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
Merged
ztanner
merged 3 commits into
canary
from
09-05-fix_route_handlers_should_validate_invalid_exports
Sep 6, 2025
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
1 change: 0 additions & 1 deletion
1
...he-components-dynamic-imports/bundled/app/not-instrumented/edge-route-handler/messages.ts
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
...cache-components-dynamic-imports/bundled/app/not-instrumented/edge-route-handler/route.ts
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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
11 changes: 11 additions & 0 deletions
11
test/e2e/app-dir/cache-components-route-handler-errors/app/layout.tsx
This file contains hidden or 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,11 @@ | ||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
return ( | ||
<html lang="en"> | ||
<body>{children}</body> | ||
</html> | ||
) | ||
} |
5 changes: 5 additions & 0 deletions
5
test/e2e/app-dir/cache-components-route-handler-errors/app/route-with-dynamic/route.ts
This file contains hidden or 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,5 @@ | ||
export const dynamic = 'force-static' | ||
|
||
export async function GET(request: Request) { | ||
return new Response('route GET') | ||
} |
5 changes: 5 additions & 0 deletions
5
test/e2e/app-dir/cache-components-route-handler-errors/app/route-with-fetchcache/route.ts
This file contains hidden or 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,5 @@ | ||
export const fetchCache = 'force-cache' | ||
|
||
export async function GET(request: Request) { | ||
return new Response('route GET with fetchCache') | ||
} |
5 changes: 5 additions & 0 deletions
5
test/e2e/app-dir/cache-components-route-handler-errors/app/route-with-revalidate/route.ts
This file contains hidden or 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,5 @@ | ||
export const revalidate = 60 | ||
|
||
export async function GET(request: Request) { | ||
return new Response('route GET with revalidate') | ||
} |
65 changes: 65 additions & 0 deletions
65
...p-dir/cache-components-route-handler-errors/cache-components-route-handler-errors.test.ts
This file contains hidden or 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,65 @@ | ||
import { nextTestSetup } from 'e2e-utils' | ||
import { | ||
assertHasRedbox, | ||
getRedboxDescription, | ||
getRedboxSource, | ||
} from 'next-test-utils' | ||
|
||
describe('cache-components-route-handler-errors', () => { | ||
const { next, skipped, isNextDev, isTurbopack } = nextTestSetup({ | ||
files: __dirname, | ||
skipStart: true, | ||
skipDeployment: true, | ||
}) | ||
|
||
if (skipped) { | ||
return | ||
} | ||
|
||
it("should error when route handlers use segment configs that aren't supported by cacheComponents", async () => { | ||
try { | ||
await next.start() | ||
} catch { | ||
// we expect the build to fail | ||
} | ||
|
||
if (isNextDev) { | ||
// Test the first route handler with "dynamic" config | ||
const browser = await next.browser('/route-with-dynamic') | ||
await assertHasRedbox(browser) | ||
const redbox = { | ||
description: await getRedboxDescription(browser), | ||
source: await getRedboxSource(browser), | ||
} | ||
|
||
if (isTurbopack) { | ||
expect(redbox.description).toMatchInlineSnapshot( | ||
`"Ecmascript file had an error"` | ||
) | ||
} else { | ||
expect(redbox.description).toMatchInlineSnapshot( | ||
`" x Route segment config "dynamic" is not compatible with \`nextConfig.experimental.cacheComponents\`. Please remove it."` | ||
) | ||
} | ||
expect(redbox.source).toContain( | ||
'"dynamic" is not compatible with `nextConfig.experimental.cacheComponents`. Please remove it.' | ||
) | ||
} else { | ||
// 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( | ||
'"dynamic" is not compatible with `nextConfig.experimental.cacheComponents`. Please remove it.' | ||
) | ||
|
||
expect(next.cliOutput).toContain('./app/route-with-revalidate/route.ts') | ||
expect(next.cliOutput).toContain( | ||
'"revalidate" is not compatible with `nextConfig.experimental.cacheComponents`. Please remove it.' | ||
) | ||
|
||
expect(next.cliOutput).toContain('./app/route-with-fetchcache/route.ts') | ||
expect(next.cliOutput).toContain( | ||
'"fetchCache" is not compatible with `nextConfig.experimental.cacheComponents`. Please remove it.' | ||
) | ||
} | ||
}) | ||
}) |
10 changes: 10 additions & 0 deletions
10
test/e2e/app-dir/cache-components-route-handler-errors/next.config.js
This file contains hidden or 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,10 @@ | ||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
const nextConfig = { | ||
experimental: { | ||
cacheComponents: true, | ||
}, | ||
} | ||
|
||
module.exports = nextConfig |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test should never have been possible to begin with, as specifying edge runtime with cache components should have errored.