Skip to content

Support progressive HTML rendering via chunked transfer encoding #1522

Open
Danish-Belal wants to merge 1 commit intohotwired:mainfrom
Danish-Belal:support-progressive-html-streaming-1517
Open

Support progressive HTML rendering via chunked transfer encoding #1522
Danish-Belal wants to merge 1 commit intohotwired:mainfrom
Danish-Belal:support-progressive-html-streaming-1517

Conversation

@Danish-Belal
Copy link
Copy Markdown

Root cause
Turbo uses response.text() in FetchResponse, which buffers the full response before processing. That blocks progressive rendering with chunked transfer encoding.

Solution
Progressive HTML streaming is supported when the server sends X-Turbo-Stream-Body: true and uses as a delimiter between chunks.

Changes

  1. src/http/fetch_response.js
  • isStreamBody – checks X-Turbo-Stream-Body: true
  • streamTarget – optional target selector (default main or body)
  • streamBodyChunks() – async generator yielding HTML chunks split by

2.src/core/drive/streaming_body_renderer.js

  • Renders chunks into a target container
  • First chunk: merges , replaces target content
  • Later chunks: appended to target
  • Scripts in chunks are activated
  1. src/core/drive/visit.js
  • Detects streaming responses before awaiting responseHTML
  • Adds loadStreamingResponse() for the streaming path
  • Updates history and completes the visit when streaming finishes
  1. src/tests/server.mjs
  • Adds /__turbo/stream-body endpoint for tests

5.Tests

  • New drive test for progressive streaming
  • New link in drive.html fixture

Server usage
// PHP/Symfony example from the RFC

return new StreamedResponse(function () {
    echo $this->renderShell();
    echo '<!-- turbo-chunk -->';
    flush();
echo $this->renderTrackList();
echo '<!-- turbo-chunk -->';
flush();

echo $this->renderFooter();
flush();

});

Set the response header: X-Turbo-Stream-Body: true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant