-
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
router asPath hydration mismatch when rewrite is applied #34197
Comments
Potential duplicate of #34144 |
Hi, so this is currently expected as the page being rewritten to is an automatically statically optimized page so it can't know the Also note using |
@ijjk Yeah I just had this realization regarding static generation 😅 . Definitely agreed there could be potential for docs improvement here, or even a development warning if I was just using the Thanks for taking a look! |
## Description According to `Next.js` useRouter documentation: - `asPath`: The path (including the query) shown in the browser without the configured basePath or locale. - `pathname`: Current route. That is the path of the page in /pages, the configured basePath or locale is not included. `asPath` should not be used as the props of components. There are many cases that `asPath` not working as expected. For example: - `asPath` is different on server-side and client-side. - `asPath` can contains `id` and `query`. ## Suggestion - Warning the use of `asPath` can lead to the conflict of client and server-side. - Update `useRouter` document. ## Bug - [x] Related issues linked using `fixes #number` Fixes: #34144 Fixes: #34016 Fixes: #34197
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. |
## Description According to `Next.js` useRouter documentation: - `asPath`: The path (including the query) shown in the browser without the configured basePath or locale. - `pathname`: Current route. That is the path of the page in /pages, the configured basePath or locale is not included. `asPath` should not be used as the props of components. There are many cases that `asPath` not working as expected. For example: - `asPath` is different on server-side and client-side. - `asPath` can contains `id` and `query`. ## Suggestion - Warning the use of `asPath` can lead to the conflict of client and server-side. - Update `useRouter` document. ## Bug - [x] Related issues linked using `fixes #number` Fixes: vercel/next.js#34144 Fixes: vercel/next.js#34016 Fixes: vercel/next.js#34197
Run
next info
(available from version 12.0.8 and up)What version of Next.js are you using?
12.0.10
What version of Node.js are you using?
14.17.6
What browser are you using?
Chrome
What operating system are you using?
macOS
How are you deploying your application?
Vercel
Describe the Bug
When navigating to a route which has been rewritten and using
asPath
during SSR, a hydration mismatch occurs, specifically when usingasPath
to create anhref
to be passed tonext/link
.Rewrite config: https://github.com/BRKalow/next-rewrite-hydration-mismatch/blob/main/next.config.js
Rewritten page: https://github.com/BRKalow/next-rewrite-hydration-mismatch/blob/main/pages/proxied/index.jsx
On initial load, the anchor tag rendered by
next/link
has an href of/proxied
, whereas I would expect it to have an href of/
Expected Behavior
No hydration mismatch, the router state during SSR should ideally match the URL as reflected in the request. On initial load, the anchor tag rendered by
next/link
should have an href of/
.To Reproduce
https://github.com/BRKalow/next-rewrite-hydration-mismatch
The text was updated successfully, but these errors were encountered: