Skip to content

Streaming SSR renderer #653

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
Rich-Harris opened this issue Jun 20, 2017 · 1 comment
Closed

Streaming SSR renderer #653

Rich-Harris opened this issue Jun 20, 2017 · 1 comment

Comments

@Rich-Harris
Copy link
Member

At present, you can only render a component if all the data is present. This wastes an opportunity to stream markup we can already generate — it's very likely that we can print out the doctype and (most of) the <head> immediately, for example, even if the server is waiting on a database or network request for everything else.

Perhaps this could just mean that top-level data properties could be promises, and they would get Promise.resolve(...)'d.

Would need a new API:

// sync (current API)
const html = App.render({
  foo: 1,
  bar: 2
});

// async
const html = await App.renderAsync({
  foo: 1,
  bar: Promise.resolve(2)
});

// streaming
const stream = App.renderToStream({
  foo: 1,
  bar: Promise.resolve(2)
});
stream.pipe(res);

If we had some way for components to fetch their own data asynchronously, this would enable that to work with SSR as well:

const html = AppWithAsyncData.render(); // throws error
const html = await AppWithAsyncData.renderAsync(); // works

Open to bike-shedding!

@Rich-Harris
Copy link
Member Author

Closing this in favour of #958

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

1 participant