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] Fake instances tree for smart prefetching #7

Closed
Akryum opened this issue Oct 11, 2018 · 7 comments
Closed

[SSR] Fake instances tree for smart prefetching #7

Akryum opened this issue Oct 11, 2018 · 7 comments

Comments

@Akryum
Copy link
Member

Akryum commented Oct 11, 2018

I think it would be nice to have an official way of "pre-rendering" the components tree to gather prefetching data when doing SSR. Ideally much lighter than a real render, with ways to mock global/local properties and methods to speed it up, maybe with an API libraries can use to mock themselves.

This would hugely improve the SSR story because currently we are limited to the routes components. I recently made some experimentation with this in the vue-apollo SSR API that allows the user to prefetch all the GraphQL queries in his app without manually adding them if they are in rotue sub-components (or even outside of router views). However, I think it would be better as an official API so it's less exposed to breaking due to Vue internal changes.

The vue-apollo implementation also recognizes a special attribute like no-prefetch which skips a components sub-tree to optimize the tree walking if it is known that no queries will be found there.

@yyx990803
Copy link
Member

I'm not sure if fake rendering is really a good idea. Mocking sounds super fragile and I doubt it can be really that lightweight if we want to make sure things don't just break.

Maybe we can tackle this from a different perspective - is it possible to statically analyze and extract queries at build time (kinda like Relay Modern)?

@Akryum
Copy link
Member Author

Akryum commented Oct 14, 2018

Well, that's the approach taken by the official react-apollo (source). BTW it seems so much easier to do in React 😭

@yyx990803
Copy link
Member

yyx990803 commented Oct 14, 2018

It looks quite fragile/hacky to me, and is essentially rendering the whole app twice... which means it decreases performance significantly... not sure if it's worth it at all.

That said it's totally possible in v3.

@yyx990803
Copy link
Member

Also, it seems it cannot have nested components with queries. The walker stops when any component has async data. Still quite a limitation IMO.

@Akryum
Copy link
Member Author

Akryum commented Oct 26, 2018

Maybe we could make renderToString asynchronous with ways to hook into it and do data prefetching and eventual secondary re-rerenders of components that prefetched some data?

@Akryum
Copy link
Member Author

Akryum commented Oct 26, 2018

BTW react-apollo switched to rendering the app multiple times: apollographql/react-apollo#2533

@Akryum
Copy link
Member Author

Akryum commented Nov 8, 2018

Closing in favor of #11

@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