fix(testing): resolve async function configs in unstable_getResponseFromNextConfig#92514
Closed
sleitor wants to merge 1 commit into
Closed
fix(testing): resolve async function configs in unstable_getResponseFromNextConfig#92514sleitor wants to merge 1 commit into
sleitor wants to merge 1 commit into
Conversation
…romNextConfig Plugin wrappers like @sentry/nextjs wrap the user config in an async function: `(phase, ctx) => config`. When such a config is passed to `unstable_getResponseFromNextConfig`, `loadCustomRoutes` receives the function instead of the resolved object and sees all route properties as `undefined`, causing every matcher to return null. Fix: call `normalizeConfig(PHASE_PRODUCTION_BUILD, nextConfig)` before passing the result to `loadCustomRoutes`. This is the same helper used by the main Next.js config loader to unwrap function and Promise exports. Closes vercel#92500
Contributor
|
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
1 similar comment
Contributor
|
Allow CI Workflow Run
Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer |
Member
|
Duplicate of #92501 |
Contributor
Author
|
@mischnic Thanks for pointing that out! You're right — #92501 (by @TooTallNate) addresses the same issue and was submitted first. Both use |
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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
What?
Plugin wrappers like
@sentry/nextjs,@vercel/workflowwrap the user config in an async function:When such a config is passed to
unstable_getResponseFromNextConfig, the config is passed directly toloadCustomRoutes, which immediately accessesconfig.rewrites,config.redirects, etc. Since the value is still a function, all those properties areundefinedand every route matcher returnsnull.Why?
loadCustomRoutesexpects a plain config object. The main Next.js config loader already callsnormalizeConfig(phase, rawExport)which properly resolves both function and Promise exports before use.How?
Call
normalizeConfig(PHASE_PRODUCTION_BUILD, nextConfig)before passing toloadCustomRoutes. This is the same helper used by the Next.js config loading pipeline to unwrap function/async function configs.Also broadened the TypeScript parameter type to accept function-wrapped configs without needing an
as anycast in user code.Test
Added two test cases in
config-testing-utils.test.ts:(phase, ctx) => config(phase, ctx) => Promise<config>Closes #92500