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

Experiment Async Route support #653

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Experiment Async Route support #653

wants to merge 4 commits into from

Conversation

yoshuawuyts
Copy link
Member

Porting https://github.com/goto-bus-stop/choo-lazy-route to be a first-class citizen in Choo. Should allow loading routes async directly.

Right now the API is prefixed with experimental, as it probably requires some discussion on how to stabilize. But feel it's worthwhile adding a non-hacky way to allow this in the meantime. If anything so we can iterate on the functionality while keeping clear that this isn't ready for prime time yet.

Thanks!

@yoshuawuyts yoshuawuyts changed the title WIP Experiment Async Route support Experiment Async Route support Apr 4, 2018

Choo.prototype._initAsyncProxy = function () {
var tagName = this._tree ? this._tree.nodeName : 'body'
this._asyncProxy = document.createElement(tagName)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid this won't work on the server

renderRoute = state.route
loadingState = LOADING

var p = loader(onload)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we don't need to pass in the onload callback here if p must return a promise anyway

@tornqvist
Copy link
Member

tornqvist commented Dec 4, 2018

I love this idea! Before I knew about choo-lazy-route I started work on pretty much the exact same thing called choo-lazy-view but it has support for a third argument being a loader view. Not only was the loader view a nice way of giving immediate feedback but also offers an opportunity for prefetching content needed by the view being loaded. Ofc, this could just as well be done by listening for the choo:async-route-start. It also defaults to returning the mounted node as loading view to prevent flash of an empty view.

@yoshuawuyts
Copy link
Member Author

@tornqvist it'd be awesome if someone could take this PR over the finish line. I ran out of time to work on it in over summer, but would love if this could eventually land!

@tornqvist
Copy link
Member

I've been working a bit on this lately but have hit a wall regarding what to do with SSR. On the client side we either preserve the current view as the async route is being loaded or the user could supply a loader function that would be rendered in its place.

On the server side it's a bit more tricky. Both choo-lazy-route and choo-lazy-view use state.prefetch (or state._experimental_prefetch) to inform the user when the view has loaded, encouraging a second render pass.

As I see it we either standardize state.prefetch as a core choo pattern for these kinds of things or we allow toString ro return a promise, in which case the name doesn't really make sense and would need change to e.g. render.

Any opinions on this matter? I personally would prefer the latter and let state.prefetch just be an implementation detail, which could easily be used in conjunction with an async render method.

@tornqvist tornqvist mentioned this pull request Jun 8, 2019
6 tasks
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

Successfully merging this pull request may close these issues.

None yet

4 participants