Request "type" visibility in route handlers/middleware #14505
brophdawg11
started this conversation in
Proposals
Replies: 1 comment
-
|
I think the headers are better. It's common to use custom headers for tools like proxies to pass values to the app code, and they don't modify the URL. I think we should have a header I don't think the original URL with |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, we normalize
request.urlwhen callingloaders/actionson the server between document/data requests by stripping the.dataextension and removing anyroutesquery params.react-router/packages/react-router/lib/server-runtime/server.ts
Line 115 in e7879a8
react-router/packages/react-router/lib/server-runtime/data.ts
Line 26 in e7879a8
We actually don't currently do this on
middleware, but that's just a bug we'll fix up.I believe the original reasoning for this was to avoid potential footguns by allowing branching in your
loader/actionthat behaved differently based on document vs. data which could result in your application behaving differently on SSR loads versus client-side navigations - something Remix v1 worked hard to ensure always behaved the same.However, we have had a number of requests for this over time - and more recently with the Instrumentation APIs, it's tricky to monitor document requests differently from data requests. You can do it today with a custom server and using
getLoadContextto set a value oncontextbecause that has access to the raw unmodifiedexpressreqinstance (or whatever else applies for your runtime).Along the same lines, we have had many requests over the past few years to know when a
loaderis being called as part of a revalidation versus the initial load. We should go back and find out some of the use cases for this to see if it's something we should also consider here or not.Options
I think we have a few potential options here:
.datarequestsrequest(i.e.,X-React-Router-Original-UrlandX-React-Router-Revalidation-Request)originalUrlandisRevalidationI like (1) for it's simplicity and the ability to delete code, but we would still need something like (2) or (3) to handle identifying revalidation requests if we went that route. I like (2) because it's non-breaking and handles both cases in the same manner.
Looking for Feedback
I'm curious to get some feedback from folks on a few things:
.data?routes=...for data requests? Are there scenarios where you would need to write more code to get the "normalized" URL?Beta Was this translation helpful? Give feedback.
All reactions