kadirahq / flow-router

Carefully Designed Client Side Router for Meteor
MIT License
1.09k stars 195 forks source link

[React] FlowRouter.go causes subscriptions to stop #660

Closed s-devaney closed 8 years ago

s-devaney commented 8 years ago

Example: my application has a layout containing a sidebar and a main content region. I use react-mounter to mount the page in the main content region according to the FlowRouter route. Inside my sidebar I have some information about the user which is managed by a normal Meteor subscription.

Inside my React page components I have some hrefs which handle navigation between pages - all normal stuff.

Here's where it gets weird. If I have a React onClick handler and a function which calls FlowRouter.go - instead of a HTML href - the routing will occur however my subscriptions in the sidebar component will momentarily stop and then re-subscribe. This causes content flashing in the sidebar - not good.

And here's where it get's even weirder - if I call the exact same FlowRouter.go command from the console this behavior does not occur.

I've simplified my app - when routing to an empty component with a single action - react-mount this behavior still occurs, I'm fairly sure it is FlowRouter - or it's Pages.js dependency - which is causing this. But I have no idea why.

s-devaney commented 8 years ago

After scratching my head about this for 2 days, 10 minutes after opening an issue I found a solution.

Wrapping the FlowRouter.go call in a zero millisecond setTimeout seemed to fix it - and after reading a lot of the issues on here it seems to "solve" a lot of things. Maybe FlowRouter isn't the well architected, solid piece of software it claims to be?