Skip to content

Some way to wait before send SSR results #2084

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

Closed
outerlook opened this issue Aug 3, 2021 · 6 comments
Closed

Some way to wait before send SSR results #2084

outerlook opened this issue Aug 3, 2021 · 6 comments

Comments

@outerlook
Copy link

outerlook commented Aug 3, 2021

Describe the problem

I'm used to GraphQL Relay's concepts of data specification in a more declarative rather than imperative way. To achieve that, part of it is based on the principle of collocating data requirements next to where it is used. It makes an data intensive app more scalable as components become more modular, less coupled to pages, without over or underfetching.

Load function is define what you need before you use. The methods I'm used to, you first use some data then it automatically request what you asked. I use gqless to achieve that. Rather than arguing which is better or has better performance, right now my workflow is not supported by svelte-kit.

Describe the proposed solution

It would be highly appretiated to be able to wait for something inside my svelte components before sending the results, or be able to extract the cache of it. Something in which I could extract information of what was compiled (without needing to right an preprocessor), pass cache back after await resolve(request) at Handle function in hooks.ts.

Routify does have an utility called $ready() which would be a good inspiration of api...
https://routify.dev/docs/helpers#ready

Alternatives considered

Leave as is and declare not scope of svelte-kit.

Refactor my app or be happy with some skeleton loading inside my app. But that would be a huge problem for SEO...

Importance

use SvelteKit without it becomes harder

Additional Information

Well, I could use Sveltekit without it, but I'd need to refactor all my app for it. And for my workflow it wouldn't be an improvement in terms of scalability.

about collocation:
https://www.graphql.com/articles/best-practices-for-graphql-clients

@Conduitry
Copy link
Member

If you need to do asynchronous stuff that you want to have present in the SSR'd version of your site, that's what the load function in each page component is for. It can return a promise. Does that not work for you?

@pixelmund
Copy link
Contributor

pixelmund commented Aug 3, 2021

If you haven't already, take a look at Houdini it's my goto with sveltekit and graphql, coming from a react/relay background. You may like it. Houdini

@outerlook
Copy link
Author

@Conduitry correct me if I'm wrong, but load is able to fetch before running svelte components itself, right?

if there's a fetch deep inside a nested component, there's no way to wait for it to complete. The only way is to bring this requirements to the page component, right?

That is my request, to be able to call something from inside after compiled - "I am ready to be ssr'd"
If you need further examples to clarify, I would be happy to provide.

Here is a example repo of how I fetch things, but it is not ssr friendly for this issue...
https://github.com/outerlook/sveltekit-gqless-spacex

@outerlook
Copy link
Author

Thanks for your suggestion, @pixelmund! I like Houdini a lot, and I appreciate your suggestion. Right now I'm trying to build a graphql client on top of a gqless, with the same principles as houdini and relay, but on a different api based on JS proxy... and I of course will try to open source it as it gets more polished. Hope houdini keeps the good work too.

I think this is offtopic 😬

@Conduitry
Copy link
Member

This, then, is essentially a Svelte feature request, and it's one that there's been an issue for for some time: sveltejs/svelte#958 This is impossible in SvelteKit without support in Svelte itself.

In the meantime, having this async code live in load (and thus be the responsibility of SvelteKit and not the synchronous SSR code) is the only way to do this.

@outerlook
Copy link
Author

outerlook commented Aug 4, 2021

Oh, okay! Thanks for clarifying. One last thing, may I somehow pass an object from svelte components in sync back to the hook.ts after SSR'd? I think I could collect my requests this way too in meantime.

Anyway, thanks for your thoughts, Conduitry!

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

No branches or pull requests

3 participants