Skip to content
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

[9.5.4-canary.18] Different router.asPath between server and client. #17113

Closed
nghiepdev opened this issue Sep 15, 2020 · 6 comments · Fixed by #17121
Closed

[9.5.4-canary.18] Different router.asPath between server and client. #17113

nghiepdev opened this issue Sep 15, 2020 · 6 comments · Fixed by #17121
Assignees
Milestone

Comments

@nghiepdev
Copy link
Contributor

Bug report

From 9.5.4-canary.18 router.asPath in the sever-side return incorrect value.

Describe the bug

// next.config.js
module.exports = {
  rewrites() {
    return [
      {
        source: "/my-post",
        destination: "/post"
      }
    ];
  }
};

To Reproduce

https://codesandbox.io/s/sharp-cannon-kcsio?file=/pages/post.js
Directly access /my-post url

Screen Shot 2020-09-15 at 21 30 53

Expected behavior

The router.asPath always return /my-post.

Additional context

#17082

@Timer Timer added this to the iteration 9 milestone Sep 15, 2020
@ijjk ijjk added the point: 1 label Sep 15, 2020
@kodiakhq kodiakhq bot closed this as completed in #17121 Sep 15, 2020
kodiakhq bot pushed a commit that referenced this issue Sep 15, 2020
This makes sure we have the correct `asPath` value to prevent breaking hydration for `getServerSideProps` pages and doesn't re-use the `resolvedUrl` value for the `asPath` and instead creates a separate `resolvedAsPath` value that only removes the `_next/data` prefix from the path. Additional tests have been added in the `getServerSideProps` suite to ensure correct `asPath` with rewrites. 

Fixes: #17113
@ijjk
Copy link
Member

ijjk commented Sep 15, 2020

Hi, this should be fixed in v9.5.4-canary.20 of Next.js, please upgrade and give it a try!

@nghiepdev
Copy link
Contributor Author

@ijjk v9.5.4-canary.20 The problem still has not resolved 😿
https://codesandbox.io/s/sharp-cannon-kcsio?file=/pages/post.js

@ijjk
Copy link
Member

ijjk commented Sep 16, 2020

@nghiepit which part isn't resolved on that codesandbox link? It looks like the asPath is the expected value when visiting /my-post. We have also added these cases to our test suite which are passing.

@nghiepdev
Copy link
Contributor Author

In my local project and export codesanbox.example.zip both are the same problem.

@ijjk
Copy link
Member

ijjk commented Sep 16, 2020

@nghiepit I took another look at your reproduction and your issue doesn't appear to be related to the GS(S)P asPath resolving like I thought so I opened a new issue to track the actual problem you are encountering here. Thanks for reporting back that the issue wasn't resolved!

HitoriSensei pushed a commit to HitoriSensei/next.js that referenced this issue Sep 26, 2020
This makes sure we have the correct `asPath` value to prevent breaking hydration for `getServerSideProps` pages and doesn't re-use the `resolvedUrl` value for the `asPath` and instead creates a separate `resolvedAsPath` value that only removes the `_next/data` prefix from the path. Additional tests have been added in the `getServerSideProps` suite to ensure correct `asPath` with rewrites. 

Fixes: vercel#17113
@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants