-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Get Route Handler Components Asynchronously #755
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
Looks good and does it require any change of code on server side rendering? Here is a sample that I'm using in yahoo's fluxible architecture https://github.com/geekyme/isomorphic-react/blob/master/server.js#L58-L98 |
All depends on your implementation, we just provide a function and a callback. |
This is good. Yes. What happens before the callback is ready? As you saw in another issue, we ran into a little trouble: if you want transition hooks to work, you can't have a loading UI, because to show the UI, you have to allow the transition. IMO we need to both allow loading UI and let transition hooks work correctly. |
I didn't know how about that. Please advise. How come actions need the router instance?
|
You might want to |
Agree. I've done a lot of thinking about this over the weekend. The nice thing about the model we currently have is that we already have a few well-defined points where you get to control 1) how the transition proceeds (the To put it another way, we already know how to:
Which one you do is up to you, according to your needs. |
Can route handlers define a static property telling what to show while transition to it is pending? var ShowNothingUntilImReady = React.createClass({
statics: {
willTransitionTo(blabla, callback) {
setTimeout(callback, 3000);
},
}
});
var Spinner = React.createClass({
render() { return <img src='loading.gif' /> }
});
var ShowSpinnerUntilImReady = React.createClass({
statics: {
pendingHandler: Spinner,
willTransitionTo(blabla, callback) {
setTimeout(callback, 3000);
},
}
}); Or should this be declared in route config instead? <Route name='not-nice' handler={ShowNothingUntilImReady} />
<Route name='nice' handler={ShowSpinnerUntilImReady} pendingHandler={Spinner} /> How does this work with nesting? |
<Route handler={App}>
<Route name='nice' handler={ShowSpinnerUntilImReady} />
<PendingRoute handler={Spinner} />
</Route> Until This approach probably has problems with more nesting but it's something. |
Should it be the responsibility of the component to chose a spinner or of the router/root component? So: component: I'm not done yet, please render this spinner till I'm done. vs component: I'm not done yet. Router: Ok, while waiting, I will render this spinner? Both seem to have advantages. |
I think the parent component (or parent's route config node) should decide that. Only parent knows what is appropriate to nest inside it at the current level of nesting. |
This is really exciting, and definitely solves a really tricky data/lazy loading use-case that I keep butting into. Awesome. |
I really like this. This would also allow for managing any initial data load that may also occur after the initial lazy-load of the handler to happen behind the same spinner. |
@gaearon I know its related, but can we move the discussion around "loading states" to a new thread? We can talk about in the context of waiting on a transition already, I'd like to try to keep this thread dedicated to a solid API for async component loading, and then we can reference this in the other thread. |
@ryanflorence your proposal looks good to me. I bumped into this problem just yesterday and I was looking for exactly this implementation. |
I think this could be an opportunity to add a lot of flexibility to how matched routes are handled. I'm not even specifically interested for this for the sake of loading handlers asynchronously, but I think this same feature could be really useful anywhere you want to be able to dynamically build a handler given the context of a matched route. Doing that with the current API is awkward, but if in the suggested |
This is good. I'm currently building an app that would benefit enormously from this API. We should start a new thread to discuss how this API would be connected to transition hooks and the loading component idea. IMO that is a very important part of this. |
@ryanflorence An alternate idea is to let each handler declare its own routes, then when a parent dynamically loads a child, it can add it to its own routes. I have a rough prototype of this which only requires one small change: #798 . The way it works is by having a handler add or alter its own routes, then call replaceRoutes in the Router with the root and it will then reload all of the new routes. Not the most efficient implementation, but if you like this path, it can be made more efficient. |
@ryanflorence @mjackson this looks good. It would probably be necessary to be able to abort a call to |
I have another use case for async loading which I'm hoping this issue will be able to address in the future. My app's flow is as such:
So the main issue here is that when |
I think new API should solve this with async route configuration. |
1.0 does all of this and MORE SEND US MONEY! |
@ryanflorence Cool! Do you have any docs yet for the new async stuff in 1.0? |
+1 |
smell nice |
Right now a route config requires all of the routes to declare their route handle components up front, this is problematic for a couple reasons:
While lazy loading is possible by creating thin handlers like in the
partial-app-loading
example, for cases like Relay's GraphQL queries, we'd still need to be requiring in the child components to get their queries so we're back to having the same problem.My initial thought is to introduce
getHandlerForRoute
on the router instance. The default implementation would not require anybody to change their existing code but would give us the ability to let the developer provide a component lazily.I like this a lot, but its simply a strawman to get the conversation going.
The text was updated successfully, but these errors were encountered: