Replies: 6 comments 8 replies
|
This has been discussed quite a bit over the years, and while I would absolutely welcome this addition, I understand that it's a very hard problem to solve in the general case. What I think would help, and wouldn't be super difficult to implement, would be a way to supply a custom fetch function to React Router. This would allow you to inject request headers being sent to your server, as well as inspect response headers and perform necessary global actions in response, such as displaying a notification to the user that they're running an out-of-date client and giving them the option to reload. Maybe something like: <HydratedRouter
// defaults to `window.fetch` if not supplied
fetch={async (input, init) => {
const response = await window.fetch(input, init);
const serverVersion = response.headers.get('X-App-Version');
if (serverVersion !== APP_VERSION) {
window.dispatchEvent(new ClientOutOfDateEvent({detail: serverVersion}));
}
return response;
}}
/>Honestly, I'd like to see this available in all the modes where it makes sense (ie: Framework, Data, RSC). |
|
Adding some details from a discussion the steering committee had a bit ago that didn't make it into here.
|
|
Our use case for in this scenario is provide zero downtime deploys for our users who might be in the middle of filling out a large form. Another use case is when users are in the middle of scrolling a very long report, they click a link that opens a child route, and the whole thing reloads and we lose scroll position. (That might be on us as well) We originally had lazy route discovery enabled, but it would auto refresh the page while they were in the middle of the form. We disabled it so that we can manually tell our users that there is a newer version of the application available. It's been somewhat unreliable, but that's on our side. An ideal scenario would be some way to be notified that there is a newer version of the manifest. This would need 2 things:
How we get that data is not important to us. We are really interested in deploying more often, but feel we can't just yet until we are confident we aren't interrupting workflows (I do know there's other ways around this like drafts, etc., but wanted to share our use case) |
|
Any movement on this? I'm still stuck with what I posted back in Feb. #14790 |
|
Emit a small event immediately before the existing manifest-version reload? I'd keep reload behavior unchanged and first confirm the event name, payload, and whether it should be cancellable. |
Uh oh!
There was an error while loading. Please reload this page.
A mismatch between the frontend and the backend is a sure way to get unexpected crashes, and should be avoided as much as possible.
An easy way to do this is to use browser navigation instead of react-router navigation when a new version is deployed
Maybe a way to achieve this would be to enable:
I've managed to implement something similar by using a lot of react router internals and monkey-patching fetch, but it seems like a few additions in the middleware would make this a lot easier
All reactions