Skip to content

breaking: reducers only see objects; revivers are called once - #247

Closed
elliott-with-the-longest-name-on-github wants to merge 3 commits into
elliott/new-wire-formatfrom
elliott/reducer-reviver-api
Closed

elliott-with-the-longest-name-on-github wants to merge 3 commits into
elliott/new-wire-formatfrom
elliott/reducer-reviver-api

Conversation

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

@elliott-with-the-longest-name-on-github elliott-with-the-longest-name-on-github commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Second of three stacked PRs, on top of #246. It changes the reducer and reviver APIs.

What changes

  • Reducers only see objects and functions (reducers-objects-only). Strings, numbers, booleans, BigInts, null and undefined are always written as themselves, so they stay on the fast path even when reducers are passed. Functions are tracked by identity, so a reducer that returns its own input is an ordinary cycle. This removes the REDUCER_LOOP error and its bookkeeping.

  • Revivers are called once, with the whole payload (two-stage-revivers). A custom value whose payload refers back to the value itself now throws Invalid circular reference. For types that can contain themselves, a reviver can be { create, fill }:

    • create makes the value before its payload is read;
    • fill(value, payload) completes it.

    The two-stage form also works for revivers named after built-ins. Adds the Reviver and TwoStageReviver types.

  • Refactor: in parse.js, shadow(name, fallback) returns the built-in's own reader when there is no user reviver, which removes a conditional at each call site. There's no measurable speed or size change.

@pkg-svelte-dev

pkg-svelte-dev Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

Install the latest version of devalue from 2d9f25b:

pnpm add https://pkg.svelte.dev/devalue/c/2d9f25b963e86e6ebc28f68c16f43545879cae94

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

@changeset-bot

changeset-bot Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2d9f25b

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

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

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

@elliott-with-the-longest-name-on-github elliott-with-the-longest-name-on-github changed the title breaking: reducers only see objects; revivers are called once, with two-stage revivers for cycles breaking: reducers only see objects; revivers are called once Dec 2, 2026
…them in a Set

A reference to a custom value whose function reviver hasn't returned, or to
a box or view whose contents are still being read, now always throws
`Invalid circular reference`.
@elliott-with-the-longest-name-on-github

Copy link
Copy Markdown
Contributor Author

Folded into #246, so the reducer and reviver changes are reviewed together with the format they fix up. #248 now sits directly on #246.

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