hypernova icon indicating copy to clipboard operation
hypernova copied to clipboard

Response streaming

Open Inkdpixels opened this issue 7 years ago • 9 comments

As of React 16 a new method renderToStream() method was introduced. I first though of creating a feature request issue at airbnb/hypernova-react but after taking a look at the code it seems that more ground-work needs to be done at the server itself to support streams in the first place.

@goatslacker mentioned in #22 that there are plans to support streams and even async rendering, it would be interesting if this was already started by anyone or if we could support you guys on this feature.

In the latter case it would be nice if we could collect all ideas/hints here on how to implement this feature correctly.

Inkdpixels avatar Sep 05 '17 07:09 Inkdpixels

* will be introduced - React 16 isn't out yet.

Definitely we'd like hypernova to support response streaming, and when available, to take advantage of renderToStream!

ljharb avatar Sep 05 '17 22:09 ljharb

React 16 is out in beta right now I believe and the stream/async rendering has already landed so feel free to take it for a spin and report back what works/doesn't work/what you'd like to work/how @Inkdpixels

goatslacker avatar Sep 14 '17 20:09 goatslacker

What's the benefit of rendering to stream when all the markup has to be buffered to send the HTTP response to the hypernova client? Am I missing something here?

patrick-mcdougle avatar May 15 '18 22:05 patrick-mcdougle

@patrick-mcdougle it doesn't all have to be buffered; by simply beginning to buffer it, chunks can be immediately sent down to the client, before the rest is ready.

ljharb avatar May 15 '18 23:05 ljharb

@ljharb But the client is almost always some legacy application, which needs the JS view rendered. The hypernova client isn't ever a browser, is it?!

patrick-mcdougle avatar May 16 '18 02:05 patrick-mcdougle

There’s sort of a client (browser), a combo client/server (whatever talks to hypernova and the web), and a server (hypernova). The webserver absolutely might support streaming - rails 4+, for example - and the browser always does - so hypernova would have to stream also to be able to support streaming through the entire process.

ljharb avatar May 16 '18 05:05 ljharb

I guess, but the whole response from hypernova will have to be re-tooled, since the response is JSON. You can't json_decode a partial JSON object...I guess I'm not saying it's impossible, but is it worth the effort?

patrick-mcdougle avatar May 16 '18 05:05 patrick-mcdougle

indeed, we'd have to use json streaming, or something similar.

I'm not sure if it's worth the effort yet - but it seems likely.

ljharb avatar May 16 '18 06:05 ljharb

Well - looking from outside - you can indeed decode a JSON Object using JSONStream - I made quite a lot implementations using that in reading - in writing my Scramjet..toJSONArray will easily deliver a JSON array (or object via another method) items in realtime while still provinding a proper JSON output for legacy and API use.

Can you elaborate a little on the code - maybe find a nice place to make a proof of concept? I could try and help.

MichalCz avatar May 19 '18 16:05 MichalCz