Skip to content
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

React Router hook performance [listen+match] vs [Router.onUpdate] #34

Open
djeeg opened this issue Aug 3, 2016 · 1 comment
Open

React Router hook performance [listen+match] vs [Router.onUpdate] #34

djeeg opened this issue Aug 3, 2016 · 1 comment

Comments

@djeeg
Copy link

djeeg commented Aug 3, 2016

I am working on a project that makes use of async chunked routes using react-router's getChildRoutes and webpack2's System.import

I am seeing an issue when using this code:

browserHistory.listen(location => {
    var time4 = new Date()
    //OR match({location, routes}
    match({history, routes}, (err, redirectLocation, renderProps: any) => {
        console.log("match:second: " + timeSince(time4))
        setTimeout(function () {
            trigger('loadclientonly', components, getLocals(renderProps))
                .then(function () {

                });
        }, 10);
    });
});

The match() causes an additional call to react-router's getChildRoutes, which adds a few hundred milliseconds to route transition time

I am prototyping an alternative way of doing this, and wanted some feedback
Hints taken from this thread #3

<Router onUpdate={RouterOnUpdate} />

With

function RouterOnUpdate() {
    let components = this.state ? this.state.components : this.props.components;
    let renderProps = this.state ? this.state : this.props;
    setTimeout(function () {
        trigger('loadclientonly', components, getLocals(renderProps))
            .then(function () {

            });
    }, 10);
}

This approach seems to remove the lag during route transition

@lukaswelinder
Copy link

lukaswelinder commented Dec 23, 2016

This works and should be the 'client' example provided in the README. I don't understand why the example uses the match method, something recommended by React Router to not be used for much other than server-side rendering.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants