Skip to content

fix: resolve circular references through custom revivers#154

Open
gabrielstellini wants to merge 1 commit into
sveltejs:mainfrom
gabrielstellini:main
Open

fix: resolve circular references through custom revivers#154
gabrielstellini wants to merge 1 commit into
sveltejs:mainfrom
gabrielstellini:main

Conversation

@gabrielstellini
Copy link
Copy Markdown

Fixes a regression introduced in v5.6.2 where parse() throws Invalid circular reference for valid circular structures structures that route through custom revivers (including self-referential ones).

The hydrating Set guard (added to catch infinite recursion) runs before checking whether the payload has already been hydrated. When a cycle re-encounters a custom type, the payload index is still in the hydrating Set from the outer call, so the guard throws, even though hydrate(payloadIndex) would have returned immediately from cache.

The fix adds a cache check (i in hydrated) before the guard. If the payload is already hydrated, the reviver is called directly with the cached value, bypassing the guard entirely. Genuinely invalid circular references (e.g. [["Custom", 0]] where the type points to itself as its own payload) are still rejected.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 14, 2026

🦋 Changeset detected

Latest commit: cbcf0ae

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

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

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

@gabrielstellini
Copy link
Copy Markdown
Author

@Rich-Harris I couldn't find a contributing.md - do I need to do anything else on my part?

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