Add searchParams to leaf cache key (#47312)
### What? Makes searchParams part of the cache key for dynamic rendering responses. ### Why? Current the cache key only includes the pathname and not the searchParams. This causes issues in a few cases: - Navigation to `/dashboard` then clicking a link to `/dashboard?sort=asc` works, but then when navigating back the cache node for `/dashboard?sort=asc` is used instead of the content for `/dashboard`. - Navigation between different searchParams always had to be a hard navigation as reusing a cache node would result in the wrong result. ### How? Changed the leaf node's name from `''` to `'__PAGE__'` so that it can be distinguished. Then used that `__PAGE__` marker to include the searchParams into the cache key for that leaf node in all places it's used. Ideally the `__PAGE__` key becomes something that can't be addressed in the pathname, since it still has to be serializable I'm thinking a number would be best. Given that the server just provides the cache key and the client only reasons about rendering the tree the current approach of stringifying the searchParams and making that part of the cache key could be replaced with a hash of the stringified result instead. fix NEXT-685 ([link](https://linear.app/vercel/issue/NEXT-685)) Fixes #45026 Fixes NEXT-688 Fixes #46503
Showing
Please
register
or
sign in
to comment