-
-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
match workaround for client-side rendering doesn't work with async onEnter hooks #2714
Comments
Per https://github.com/rackt/example-react-router-server-rendering-lazy-routes/blob/master/modules/client.js#L12 you need to run |
@taion, the example I posted does that, (see https://github.com/ngoossens/example-react-router-server-rendering-lazy-routes/blob/master/modules/client.js#L12) but the issue still persists. |
I see - the current API setup doesn't let us do much about this. Can you memoize the result of your |
I could work around this by making sure the request is completed before the initial render is done. Maybe something to consider for future API developments? |
Right, #2036 is a "good-enough-for-most-use-cases" workaround. We'll have something more... eventually. |
Thanks. |
Running Is there any specific development planned to resolve this issue? Do you guys know the root cause? I would be happy to try and lend a hand to fix it if need be... |
@levibotelho, the first time render runs This is hooked up through a history listener here: https://github.com/rackt/react-router/blob/master/modules/Router.js#L66 and here: https://github.com/rackt/react-router/blob/master/modules/useRoutes.js#L234 Pre-running To work around the problem we would need a way to wait for or inject the correct state into |
@ngoossens Alright well that explains why |
failing test case would be awesome here |
@ryanflorence I'll give the failing test case a shot if there has been no advancement so far on the issue. Would be good to give this the "bug" tag. |
Still broken in Example: |
Your code is wrong. Follow what's in the tests until we have a chance to update docs. Try Stack Overflow or Reactiflux for support if you're still having problems. |
Seems we should write the client.js like this ? import React from 'react'
import { match, Router, RouterContext, browserHistory as history } from 'react-router'
import { render } from 'react-dom'
import routes from './routes/RootRoute'
const { pathname, search, hash } = window.location
const location = `${pathname}${search}${hash}`
match({ routes, location }, (error, redirectLocation, renderProps) => {
render(
<Router
{...renderProps}
history={history}
/>,
document.getElementById('app')
);
}); |
@morlay thanks for your example! It worked for me |
Hi
Following the advice of issue #2036 works to correctly render the content on the first pass until you add an async onEnter hook. When this is done the issue returns because again the location ends up being null and a null component is rendered.
This can be reproduced using the following route:
I have made a small modification to the
example-react-router-server-rendering-lazy-routes
illustrating the problem here: https://github.com/ngoossens/example-react-router-server-rendering-lazy-routesThanks in advance for any assistance!
The text was updated successfully, but these errors were encountered: