-
Notifications
You must be signed in to change notification settings - Fork 27k
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
fix: redirect logic missing basePath in App Render #60184
Conversation
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.
Hey Colton, these changes look good to me 💯
The only thing missing is a test to ensure it doesn't regress in the future. You can find how to add and run tests here: https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md
We have a large number of Server Actions tests in these directories:
- https://github.com/vercel/next.js/tree/canary/test/e2e/app-dir/actions
- https://github.com/vercel/next.js/tree/canary/test/e2e/app-dir/actions-navigation
- https://github.com/vercel/next.js/tree/canary/test/e2e/app-dir/actions-allowed-origins
And the App Router tests are here:
You'll probably want to add this particular change in https://github.com/vercel/next.js/tree/canary/test/e2e/app-dir/app-basepath which is already testing other basePath related features 👍
If that doesn't work out I can help 🙌
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 |
Include the basePath to the fetchUrl to ensure the relative URL matches the app when deployed under a basePath. - Fixes #58570
Hey @timneutkens, thank you for the feedback and guidance! I am attempting to run tests now locally and seem to be having some struggles. I have already rebased my branch to latest upsteam/canary, re-installed using pnpm i, built using pnpm build and tried running both pnpm test-start and pnpm testonly-start. I get this error Full Log w/ Error
|
UPDATE: fixed by using |
@timneutkens Do you have any good examples of tests that include a custom server? This bug appears to only be reproducible with a custom server since the logic inside the redirect does not care about what path is chosen, only if the response is a RSC I need to be able to interact with the page after render, but can't seem to find a custom server test that does this anywhere, only does a render and checks the raw response.
|
@timneutkens Sorry for all the pings... I have added an e2e test that I believe should fit the criteria here, let me know what you think :D |
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.
The test looks great! Awesome work 💯
I made some slight tweaks to ensure it doesn't rely on internal implementation details and made sure that we check the entire URL when navigated in case the basePath would ever be wrong.
Stats from current PRDefault BuildGeneral
Client Bundles (main, webpack)
Legacy Client Bundles (polyfills)
Client Pages
Client Build Manifests
Rendered Page Sizes
Edge SSR bundle Size
Middleware size
Next Runtimes
Diff detailsDiff for page.jsDiff too large to display Diff for edge-ssr.jsDiff too large to display Diff for app-page-exp..ntime.dev.jsDiff too large to display Diff for app-page-exp..time.prod.jsDiff too large to display Diff for app-page-tur..time.prod.jsDiff too large to display Diff for app-page-tur..time.prod.jsDiff too large to display Diff for app-page.runtime.dev.jsDiff too large to display Diff for app-page.runtime.prod.jsDiff too large to display |
What?
Fixes #58570
How?
Include the basePath to the fetchUrl to ensure the relative URL matches the app when deployed under a basePath.
Tested?
I have added an e2e test with a basic custom server & server action redirect.
This test was confirmed to catch the bug when running it without the fix in place. When running it you will get the failed result.
Notes
Not sure if there are any edge cases where the
fetchUrl
is now broken in other use cases where there is no basePath, I assume the string would be empty""
and result in the same URL as before, but not sure?Disclosure
I am not that familiar with the Next.js code base and this is my first PR. I was struggling to find out how to grab the basePath fromnext.config.js
, but then noticed the assetPrefix inside the function matched, so decided to use that for minimal change. I don't know if there are any caveats with this approach, but could consider switching to pull directly from the config file, if that's possible?Update: Figured out where the basePath came from and switched it.