-
-
Notifications
You must be signed in to change notification settings - Fork 10.6k
Router.run Handler not idempotent #1041
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
Comments
If I'm understanding you correctly, this is related to #674 . So perhaps this would work: var lastState = null;
Router.run(routes, Router.HistoryLocation, (Handler, routerState) => {
(async function run() {
lastState = routerState;
await runStaticMethods(routerState.routes, routerState, actions);
if(lastState === routerState)
renderApp(Handler);
}());
}); Also, when rendering async, beware of this issue: #1027
I agree. That's what we're aiming for (#1012). |
Hm, that's not going to do it; the render we have to guard against is the one triggered by the "change" event. I can just remove the listener before the static methods and add it back afterwards but it seems like a hack.
👍 |
Ah, I overlooked that event. In that case, you could also try to work around rerendering |
follow #1031 |
I'm using an approach similar to many of the examples—hanging a static method off of Handlers, accumulating them in the
Router.run
callback, and rendering the app. However, instead of these methods returning data, they mutate an application state store. Changes to the application state should also trigger a new render. It looks something like this:The problem is that Handler is actually the (stateful) router. That means that (if a change event is dispatched on the appState during the course of running the static methods), the rerender it triggers will be with the new screen. (Expected behavior is that it will continue to render the old screen until the static methods complete.) As a result, the new screen can be rendered before its appState dependencies are met.
This is the first earnest look at react-router I've done since the new API a few months back, so I'd appreciate advice on how this should be accomplished, but I also think it would be great for the Handler rendering to be idempotent so that rendering could happen outside of the
run
callback.Apologies if I'm misunderstanding something. Thanks!
The text was updated successfully, but these errors were encountered: