Skip to content

roduyemi/missing-streaming-scripts

Repository files navigation

Missing scripts during streaming

Deferred loader data and the stream end marker ($_TSR.e()) are lost when serialisation finishes before the HTML is processed.

Reproduce

pnpm install
npx playwright install chromium
pnpm test:bug    # ✗ FAILS — scripts dropped
pnpm test:fix    # ✓ PASSES — scripts present

We set up 10 deferred server calls that resolve in the route loader.

Bug:

  1. Fast-exit path (this repro): stream closes synchronously before the queued microtask injects scripts.
  2. Main streaming path: cleanup runs before the queued microtask injects scripts.

Result: HTML looks correct but seroval $R promises never resolve.

Fix

Four changes in @tanstack/router-core (see patches/):

  1. ssr-server.js: Make ScriptBuffer.enqueue() and liftBarrier() synchronous (remove queueMicrotask)
  2. ssr-server.js: Expose flushScripts() on serverSsr
  3. transformStreamWithRouter.js: Call takeBufferedHtml() after setRenderFinished() in the fast-exit path
  4. transformStreamWithRouter.js: Call flushScripts() in tryFinish() and move liftScriptBarrier() after flushPendingRouterHtml()

About

Missing scripts during streaming

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors