-
Notifications
You must be signed in to change notification settings - Fork 26
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
Server side doesn't receive correct location after match() #26
Comments
@psalz Thank you very much for the investigation and for the workaround! |
Thanks for the quick response! |
…ry history object I believe, this is a proper fix for denvned/isomorphic-relay-router#26.
I've also submitted a proper fix for this issue to react-router repo: remix-run/react-router#3394 |
I'm not sure where you're seeing |
@taion Note, with isomorphic-relay-router we are using |
You should not use |
@taion, Are you sure this is the right direction? Having the history on the server allows unification of server side and client side rendering. Using |
There's definitely code that's shared between client and server, and we want to have a simple API for extending things – but I don't think stateful operations like One downside with |
@taion, I don't mind to use |
The new
applyRouterMiddleware
approach to things causes an issue where the server side code doesn't receive the correct routing information after a call tomatch
. This is actually happening in the todo-example, where requesting anything other than/
(e.g./completed
) will cause React to complain about invalid checksums. When disabling client-side Javascript, you will see that only the/
route is rendered, no matter the actually requested route.I'm anything but involved in the react-router codebase, but I think I have found the root cause and also have a potential solution, although I'm not sure if this should be resolved in userland (here) or in react-router itself.
Previously, when rendering a
RouterContext
, thelocation
prop was directly provided by therenderProps
returned frommatch
. With the new approach, this is no longer the case: TheRouter
component uses its state for the location. This state variable is changed in a history listener, here. Note that this listener immediately fires once upon registering, so this is not an async issue. The problem lies a couple of lines below: As this newly created history doesn't yet have alocation
, a call togetCurrentLocation
is made. Assuming aMemoryHistory
, which is the default, the call ends here, whereentries[current]
simply equals/
at this point (see line 36). This never gets changed, so theRouter
state is never updated, and all child components receive/
as the location.I'm wondering if the
TransitionManager
should update the history state upon a successfulmatch
.Anyway, in the meantime, simply adding
renderProps.router.replace(renderProps.location)
to
prepareData
solves the issue for me.Note that applying this fix may still cause invalid checksums at times, but this is due to another issue (facebook/react#6451).
The text was updated successfully, but these errors were encountered: