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

[SSR] Async renderToString to allow data-prefetching #11

Closed
Akryum opened this issue Oct 26, 2018 · 2 comments
Closed

[SSR] Async renderToString to allow data-prefetching #11

Akryum opened this issue Oct 26, 2018 · 2 comments

Comments

@Akryum
Copy link
Member

Akryum commented Oct 26, 2018

This would allow for automatic data prefetching (for example with apollo) on the server.

Ideas:

  • waitCounter = 0
  • mount the App and render the whole component tree
  • user/lib code can hook into renderToString with this.waitForPrefetch() (waitCounter++)
  • if waitCounter is 0, resolve renderToString
  • else, we wait for user/lib code that should call this.prefetchDone() after fetching data
    • we re-render the component
    • eventually code in children can call this.waitForPrefetch() again
    • then waitCounter--
    • then if waitCounter is 0 we resolve renderToString
  • a re-render could trigger new this.waitForPrefetch() (maybe make this parametrable, like maxReRenders)
  • <NoSSR> component prevents both server-side render and async prefetching
  • some way of skipping a component (and its children) only for async prefetching, like a skipPrefetch () { return this.myProp } option?
@yyx990803
Copy link
Member

The current renderToString implementation actually already handles async component (i.e. waiting on a component before it resolves) so it should be simple to use similar logic to wait on data fetching. We just need to have a convention or internal mechanism for a component to signal that it needs to wait for a preFetch function to finish before continuing the rendering.

@Akryum
Copy link
Member Author

Akryum commented Nov 8, 2018

PR is up: vuejs/vue#9017

@Akryum Akryum closed this as completed Nov 8, 2018
@github-actions github-actions bot locked and limited conversation to collaborators Nov 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants