Skip to content

feat: unevalStream - #218

Open
elliott-with-the-longest-name-on-github wants to merge 6 commits into
elliott/uneval-emitfrom
elliott/warp-simple
Open

elliott-with-the-longest-name-on-github wants to merge 6 commits into
elliott/uneval-emitfrom
elliott/warp-simple

Conversation

@elliott-with-the-longest-name-on-github

@elliott-with-the-longest-name-on-github elliott-with-the-longest-name-on-github commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Adds unevalStream, a streaming version of uneval for values that contain promises. This is a much smaller alternative to #183, which had grown to ~3,450 lines plus ~9,500 lines of tests.

const { head, tail, id } = devalue.unevalStream(value, replacer, options); // synchronous
  • head is an expression that recreates the value with every promise pending, no matter what has already settled, so the output is deterministic and doesn't depend on timing. Callers that want already-settled promises inlined can fold them in themselves with the replacer (js`Promise.resolve(${value})` ).
  • tail is an async iterable of statement blocks that settle those promises as they settle on the server. A settled value can contain more promises, which later blocks settle.
  • Object identity is preserved across head and every block, and the replacer is called at most once per object for the whole stream.
  • Options: id (stable session key, for when heads need to be byte-identical), scope (where the client session table lives, globalThis.__d by default), signal and transformError. Rejections and values that fail to serialize reach the client as a generic Error by default; transformError (modelled on Svelte's) turns the error into whatever the client should see instead, and can return a promise. Like a replacer, returning undefined, null or false keeps the default, as does throwing or returning something unserializable.

It's built on the internal analyze/render emitter from #223, which this PR is stacked on. The stream records where each object lives on the client during the emitter's own walk, then refers to it by path in later blocks. Paths are capped at 128 characters (at most 384 UTF-8 bytes); an object that would go deeper gets its own slot and paths restart from there, so references can't grow with the input's depth. There's no prefix aliasing on top of that: measured on SvelteKit-style streams, compression shrinks the repeated prefixes to almost nothing, and aliases came out even or slightly worse once compressed.

Tests are a table-driven round-trip harness. It checks every case across settlement orders, evaluating blocks separately vs. concatenated, identity, once-per-object replacer calls and session cleanup. On top of that are random-graph, UTF-8 transport and security regressions ported from #183.

Stack created with GitHub Stacks CLI • Give Feedback 💬

@changeset-bot

changeset-bot Bot commented Oct 6, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 929fabc

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
devalue Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-svelte-dev

Copy link
Copy Markdown

Install the latest version of devalue from 929fabc:

pnpm add https://pkg.svelte.dev/devalue/c/929fabc5cd17e060bb625976e0a62a6578a76cc5

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/devalue/pr/218

1 similar comment
@pkg-svelte-dev

Copy link
Copy Markdown

Install the latest version of devalue from 929fabc:

pnpm add https://pkg.svelte.dev/devalue/c/929fabc5cd17e060bb625976e0a62a6578a76cc5

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/devalue/pr/218

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

Successfully merging this pull request may close these issues.

1 participant