streaming SSR async data model
Svelte ships streaming SSR that cuts time-to-first-paint by deferring async promises Svelte SocietyTL;DW
- Async Svelte allows components to await promises at the top level, with pending and failed snippets displaying loading/error states independently in boundaries.
- Streaming SSR with warp maps enables sending only necessary data to the client by marking specific values in a JavaScript Map, avoiding accidental serialization of large objects.
- Server renders pending boundaries immediately while running async work in the background, then streams resolved data to the client—saving time equal to the server's data-fetching latency.
- Devalue's uneval streaming API serializes JavaScript objects with promises, supporting Maps, Sets, Dates, and custom classes with transport hooks for type reconstruction on the client.
- Dependencies on synchronous state block updates until async data resolves, preventing confusion like showing old temperature data after changing city—handled via effect.pending.
- Unrelated synchronous state remains responsive during async boundary operations; changing a counter doesn't block while city temperature loads asynchronously.
- Out-of-order HTML streaming via native browser APIs possible but requires sending more data (HTML + data) versus current approach sending only data plus JavaScript rendering logic.
- Streaming requires JavaScript on the client; progressive enhancement without JavaScript would use out-of-order streaming proposal but trades bandwidth for no-JS compatibility.
- Warp API designed as plain JavaScript Map for easier unit testing and library portability—no compilation needed, works outside Svelte renderer context.
- Circular references and shared object identity preserved across async serialization boundaries, reducing payload size for connected data structures and graphs.
TL;DW
- Async Svelte allows components to await promises at the top level, with pending and failed snippets displaying loading/error states independently in boundaries.
- Streaming SSR with warp maps enables sending only necessary data to the client by marking specific values in a JavaScript Map, avoiding accidental serialization of large objects.
- Server renders pending boundaries immediately while running async work in the background, then streams resolved data to the client—saving time equal to the server's data-fetching latency.
- Devalue's uneval streaming API serializes JavaScript objects with promises, supporting Maps, Sets, Dates, and custom classes with transport hooks for type reconstruction on the client.
- Dependencies on synchronous state block updates until async data resolves, preventing confusion like showing old temperature data after changing city—handled via effect.pending.
- Unrelated synchronous state remains responsive during async boundary operations; changing a counter doesn't block while city temperature loads asynchronously.
- Out-of-order HTML streaming via native browser APIs possible but requires sending more data (HTML + data) versus current approach sending only data plus JavaScript rendering logic.
- Streaming requires JavaScript on the client; progressive enhancement without JavaScript would use out-of-order streaming proposal but trades bandwidth for no-JS compatibility.
- Warp API designed as plain JavaScript Map for easier unit testing and library portability—no compilation needed, works outside Svelte renderer context.
- Circular references and shared object identity preserved across async serialization boundaries, reducing payload size for connected data structures and graphs.
Svelte's new async SSR uses a keyed Warp cache to serialize only the data components need, streaming resolved promise values via devalue without blocking initial HTML. Live demos show ~1 second TTFP gains; pending boundaries handle loading states while server work continues in the background. APIs are still in draft.
