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
rewrites, trailingSlash: true and getStaticProps cause TypeError [ERR_INVALID_URL]: Invalid URL #43623
Comments
Thanks, seems to be a regression introduced in #41767, we will have a look! |
Fixes #43623 ## 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) Co-authored-by: Wyatt Johnson <accounts+github@wyattjoh.ca>
Thanks very much for fixing it @balazsorban44 and @wyattjoh! |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
Data fetching (gS(S)P, getInitialProps), Routing (next/router, next/navigation, next/link)
Link to reproduction - Issues with a link to complete (but minimal) reproduction code will be addressed faster
https://github.com/jdddog/next-invalid-url-reproduction
To Reproduce
Run
yarn dev
Navigate to:
http://localhost:3000/country/
(you want to trigger a server render not client side navigation).Then you should receive this error in the browser:
And this error in the terminal for the server:
Describe the Bug
This bug occurs when using
rewrites
, where a page, e.g./country/
is rewritten to/
,trailingSlash
is true andgetStaticProps
is present on the index page (the page we are rewriting to).When the user requests the source page using server navigation, e.g.
/country/
the error TypeError [ERR_INVALID_URL]: Invalid URL is thrown.The error occurs in PathnameContextProviderAdapter at
new URL(router.asPath, 'http://f')
because router.asPath is set to//
: https://github.com/vercel/next.js/blob/canary/packages/next/shared/lib/router/adapters.tsx#L120It might be related to this bug: #40549. I've used the workaround in that thread by setting
source: "/country/{/}?"
to fix the client side navigation (see that thread), however, if the source is set tosource: "/country/"
the error from this example still occurs.Expected Behavior
When the user requests the source page using server navigation, e.g.
/country/
no error should be thrown and the page rendered.Which browser are you using? (if relevant)
Version 107.0.5304.87 (Official Build) (64-bit)
How are you deploying your application? (if relevant)
next dev
The text was updated successfully, but these errors were encountered: