-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: provide cache to reroute #15107
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
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: c5cb2e0 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Allow reroute hook to control route caching behavior by adding a cache parameter. This enables selective caching where some routes can skip the cache and re-run the hook on every request, which is useful when rerouting depends on client state (cookies, headers, etc.) to determine layouts or route handling.
504f1ea to
98a08b9
Compare
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
|
The docs for
I'm not necessarily saying this is a bad feature or something we definitely should not do, but it is definitely against the currently-stated purpose of |
Hey Elliot! That's why I made this Reddit post pondering whether it should actually be considered a pure, idempotent function when in its initial implementation (before async in 2.18 and specially the cache introduction in 2.19) it allowed for much more functionality. I 100% agree with the reasons why those were implemented as a standard behavior and the point of this PR is not to change that, but to also give the developer the choice in case they want/need those functionalities and accept the performance penalties. I hope this helps clarify and I make myself available for any further clarifications and discussions. Thanks for your reply and for considering this change! |
This PR fixes #13653 by allowing the
reroutehook to control route caching behavior through acacheparameter. By passing the cache Map reference (Map<string, Promise<URL>>) to the hook, developers can selectively clear cache entries (e.g., by looping through specific routes or clearing all entries) to force the hook to re-run on subsequent requests. This is useful when rerouting depends on client state (cookies, headers, etc.) to determine layouts or route handling.In two projects, I was already using the
reroutehook for this type of behavior, but after updating from 2.18, thereroute_cachebroke my apps. I tested this patch manually by applying it directly tonode_modulesin both projects, and it successfully allows fine-grained control over which routes bypass the cache.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm testand lint the project withpnpm lintandpnpm checkChangesets
pnpm changesetand following the prompts. Changesets that add features should beminorand those that fix bugs should bepatch. Please prefix changeset messages withfeat:,fix:, orchore:.Edits