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

useSearchParams context is missing search params from rewritten url #58256

Open
1 task done
noreiller opened this issue Nov 9, 2023 · 3 comments
Open
1 task done

useSearchParams context is missing search params from rewritten url #58256

noreiller opened this issue Nov 9, 2023 · 3 comments
Labels
bug Issue was opened via the bug report template. Navigation Related to Next.js linking (e.g., <Link>) and navigation.

Comments

@noreiller
Copy link
Contributor

Link to the code that reproduces this issue

https://github.com/noreiller/next-missing-search-params-with-rewrites

To Reproduce

  1. Start the application (npm run dev)
  2. Navigate to http://localhost:3000/app-url-to-rewrite
  3. The search param foo is not detected

Current vs. Expected behavior

When we use a rewrite containing search params, for example to the destination /my-page?foo=bar, we expect that the search param foo is available from the useSearchParams() hook and has the value bar.

Currently, the useSearchParams() hook does not return any search param.

With next/router (Page Router), the query object contains the expected search params.

This occurs in both App Router and Page Router.

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #35~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Oct  6 10:23:26 UTC 2
Binaries:
  Node: 18.12.1
  npm: 8.19.2
  Yarn: 1.22.19
  pnpm: 8.2.0
Relevant Packages:
  next: 14.0.1
  eslint-config-next: 14.0.1
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

App Router, Routing (next/router, next/navigation, next/link)

Additional context

No response

@noreiller noreiller added the bug Issue was opened via the bug report template. label Nov 9, 2023
@github-actions github-actions bot added the Navigation Related to Next.js linking (e.g., <Link>) and navigation. label Nov 9, 2023
@noreiller
Copy link
Contributor Author

I found in the e2e tests that the search params from the rewrite are available in the searchParams prop available in the page.
It sound strange to me that the searchParams from the url and the rewrite are not merged and available in the SearchParamsContext.

@tiana25
Copy link

tiana25 commented Jan 30, 2024

@noreiller Hey! Could you please tell the status of this issue. Do you have an idea when it's gonna be fixed?

@noreiller
Copy link
Contributor Author

Hi, I had no update on this so I changed my code. I think that query params should be avoided as much as possible in rewirtes. You can also use redirects.

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. Navigation Related to Next.js linking (e.g., <Link>) and navigation.
Projects
None yet
Development

No branches or pull requests

2 participants