You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Our authentication flow involves redirecting the user to a page and then back to where they were (or where they wanted to go). This is initiated from actions or loaders. When determining what url to redirect the client to we need to be able to know if the request to loader/action was because of navigation or a background fetch.
Here is what I mean by navigation and background fetch: navigation: Requests due to useLoaderData (except for the requests due to revalidation of the loader data), These happen when the url changes background fetch: Requests due useFetcher and revalidation of useLoaderData, requests posting forms. These happen without a url change
If we could distinguish between these two in our loaders and actions we can do the following:
request is due to navigation -> redirect to request url (where the client wanted to go)
request is due to background fetch -> redirect to Referer if it matches our url
We solved this issue for ourselves by patching @remix-run/router as follows:
1- add X-Request-Type: fetch header to all requests created by createClientSideRequest
2- in revalidate function, pass isRevalidation: true to startNavigation function as part of opts (3rd) argument.
3- in startNavigation check if opts?.isRevalidation is true, if not, set X-Request-Type: navigation header on the request
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Our authentication flow involves redirecting the user to a page and then back to where they were (or where they wanted to go). This is initiated from actions or loaders. When determining what url to redirect the client to we need to be able to know if the request to loader/action was because of
navigation
or abackground fetch
.Here is what I mean by
navigation
andbackground fetch
:navigation
: Requests due touseLoaderData
(except for the requests due to revalidation of the loader data), These happen when the url changesbackground fetch
: Requests dueuseFetcher
and revalidation ofuseLoaderData
, requests posting forms. These happen without a url changeIf we could distinguish between these two in our loaders and actions we can do the following:
request is due to navigation -> redirect to request url (where the client wanted to go)
request is due to background fetch -> redirect to
Referer
if it matches our urlWe solved this issue for ourselves by patching
@remix-run/router
as follows:1- add
X-Request-Type: fetch
header to all requests created bycreateClientSideRequest
2- in
revalidate
function, passisRevalidation: true
tostartNavigation
function as part ofopts
(3rd) argument.3- in
startNavigation
check ifopts?.isRevalidation
is true, if not, setX-Request-Type: navigation
header on the requestBeta Was this translation helpful? Give feedback.
All reactions