8000 Inconsistent value for context.resolvedUrl in getServerSideProps · Issue #22558 · vercel/next.js · GitHub
[go: up one dir, main page]

Skip to content

Inconsistent value for context.resolvedUrl in getServerSideProps #22558

New issue

Have a question about this project? Sign up for a free GitHub account to open an issu 8000 e 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

Closed
javiercr opened this issue Feb 26, 2021 · 13 comments
Closed

Inconsistent value for context.resolvedUrl in getServerSideProps #22558

javiercr opened this issue Feb 26, 2021 · 13 comments
Labels
bug Issue was opened via the bug report template. stale The issue has not seen recent activity.

Comments

@javiercr
Copy link
javiercr commented Feb 26, 2021

What version of Next.js are you using?

v10.0.8 (probably happening in earlier versions)

What version of Node.js are you using?

v12.18.3 (should be replicable in any)

What browser are you using?

Any

What operating system are you using?

Any

How are you deploying your application?

next start

Describe the Bug

When using rewrites without file-system based routing (useFileSystemPublicRoutes: false), the value for context.resolvedUrl on getServerSideProps lacks the query parameters when navigating server side (full page load).

Expected Behavior

context.resolvedUrl should return the same value when navigating client side or server side.

To Reproduce

I've created a codesandbox to reproduce the issue:

https://codesandbox.io/s/musing-lederberg-zuexy

This codesandbox has a next.config.js that disables file-sytem routing, and defines the following rewriting rules:

module.exports = {
  useFileSystemPublicRoutes: false,
  async rewrites() {
    return [
      {
        source: "/",
        destination: "/"
      },
      {
        source: "/products/:slug",
        destination: "/items/itemview?slug=:slug"
      }
    ];
  }
};

To reproduce the bug:

  1. Open the codesandbox
  2. Click on "Go to product page".
  3. Notice how context.resesolvedUrl = /items/itemview?slug=fancy-thing-1, i.e. it includes the slug param
  4. Now refresh that page doing a full page reload. Notice how the slug param is now missing from context.resolvedUrl
@javiercr javiercr added the bug Issue was opened via the bug report template. label Feb 26, 2021
@javiercr
Copy link
Author
javiercr commented Feb 26, 2021

To give some more context about how we found this bug and why is important to us:

We have a custom withAuth() High Order Function that we use to wrap getServerSideProps in multiple pages. This HOF is responsible for checking the current user's authentication and redirecting to the login page if the auth is missing. When we redirect to the login page, we pass the intended route as param (eg: /login?redirect=/private/page), so that after login we're able to navigate the user to the original page.

But because of this bug we can't have the full resolvedUrl (including all route params) when doing server-side navigation.

A simple use case for this are email notifications, where we include direct links to private areas of our site, and the user should be able to click the link, login and then get redirected back to the content. Another use case would be just sharing URLs of private pages with other users.

@javiercr
Copy link
Author
javiercr commented Mar 8, 2021

Just confirmed this is still happening in the final v10.0.8 release. I've updated the codesandbox to use the latest version.

@javiercr
Copy link
Author
javiercr commented May 4, 2021

I can confirm the problem is still present in versions v10.2.0 and v10.2.1-canary.2.

@valclark1
Copy link

I can confirm the problem is still present in the current version v11.0.1

@rlukawski
Copy link

Problem is still present in version v11.1.2

@lucasvst
Copy link

Same here with version v11.1.2

@iamdudeman
Copy link

I was experiencing this same issue on v11.1.4 and just updated to v12.1.6 today and it appears to be resolved there.

@javiercr
Copy link
Author
javiercr commented May 5, 2022

I was experiencing this same issue on v11.1.4 and just updated to v12.1.6 today and it appears to be resolved there.

This is a fork of the original repo case using v12.1.6 and the problem unfortunately still exists:

https://codesandbox.io/s/cocky-poincare-0896ul

  1. Open the codesandbox
  2. Click on "Go to product page".
  3. Notice how context.resesolvedUrl = /items/itemview?slug=fancy-thing-1, i.e. it includes the slug param
  4. Now refresh that page doing a full page reload. Notice how the slug param is now missing from context.resolvedUrl

@oriolcp
Copy link
Contributor
oriolcp commented May 16, 2022

I had a similar issue with 12.1.5, resolvedUrl was including url and segments after navigating in SPA mode, upgrading to 12.1.6 solved my issue.
The main difference with @javiercr's test is that I am not using rewrites, urls are defined following file system approach.

@kylemorena
Copy link

I confirm the problem still present in the version v13.0.3 if I use rewrites, is there any updates?

@b3nk3
Copy link
b3nk3 commented Nov 28, 2023

this caught us out too today, landing us a redirect loop :S v13.5.6

@nextjs-bot
Copy link
Collaborator

This issue has been automatically marked as stale due to two years of inactivity. It will be closed in 7 days unless there’s further input. If you believe this issue is still relevant, please leave a comment or provide updated details. Thank you.

@nextjs-bot nextjs-bot added the stale The issue has not seen recent activity. label May 26, 2025
@nextjs-bot
Copy link
Collaborator

This issue has been automatically closed due to two years of inactivity. If you’re still experiencing a similar problem or have additional details to share, please open a new issue following our current issue template. Your updated report helps us investigate and address concerns more efficiently. Thank you for your understanding!

@nextjs-bot nextjs-bot closed this as not planned Won't fix, can't repro, duplicate, stale Jun 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template. stale The issue has not seen recent activity.
Projects
None yet
Development

No branches or pull requests

10 participants
0