Router Cache entry doesn't work when query params contain %20 #72927
Labels
bug
Issue was opened via the bug report template.
Navigation
Related to Next.js linking (e.g., <Link>) and navigation.
Performance
Anything with regards to Next.js performance.
Runtime
Related to Node.js or Edge Runtime with Next.js.
Link to the code that reproduces this issue
https://github.com/blairmcalpine/next-router-cache-bug
To Reproduce
pnpm i
)pnpm build && pnpm start
)localhost:3000
, and then open the network tab in browser devtools.localhost:3000/
.Current vs. Expected behavior
Following the steps above, I expect that clicking "Broken Prefetch" followed by "Broken Push" only creates one network request. Instead, it makes two.
Note that the only different between the working and broken prefetch, is that the broken one encodes a space with %20 (specifically the URL is
/other?query=a%20b
). The working one uses/other?query=a_b
(could be a + as well or any other character), which works.I believe this issue stems from the fact that the RSC request from the "Broken Prefetch" and "Broken Push" contain a + in the network request instead of a %20. I'd assume this means when the "Broken Push" looks up the cache entry, it uses %20, but the cache entry added by the "Broken Prefetch" contains a +.
I'd assume this can likely be fixed by no longer replacing the %20 in the query parameters with a + when doing the RSC request (which presumably occurs at some point if the query params are parsed into an object and then back to a string using URLSearchParams.toString).
Provide environment information
Operating System: Platform: darwin Arch: arm64 Version: Darwin Kernel Version 23.6.0: Wed Jul 31 20:49:39 PDT 2024; root:xnu-10063.141.1.700.5~1/RELEASE_ARM64_T6000 Available memory (MB): 32768 Available CPU cores: 10 Binaries: Node: 20.12.0 npm: 10.5.0 Yarn: 4.4.0 pnpm: 9.7.0 Relevant Packages: next: 15.0.3 // Latest available version is detected (15.0.3). eslint-config-next: 15.0.3 react: 19.0.0-rc-66855b96-20241106 react-dom: 19.0.0-rc-66855b96-20241106 typescript: 5.6.3 Next.js Config: output: N/A
Which area(s) are affected? (Select all that apply)
Navigation, Performance, Runtime
Which stage(s) are affected? (Select all that apply)
next start (local), Vercel (Deployed), Other (Deployed)
Additional context
No response
The text was updated successfully, but these errors were encountered: