Skip to content

fix: serialize Temporal values referenced more than once in uneval#165

Open
greymoth-jp wants to merge 1 commit into
sveltejs:mainfrom
greymoth-jp:fix-uneval-temporal-reference
Open

fix: serialize Temporal values referenced more than once in uneval#165
greymoth-jp wants to merge 1 commit into
sveltejs:mainfrom
greymoth-jp:fix-uneval-temporal-reference

Conversation

@greymoth-jp

Copy link
Copy Markdown

uneval has two code paths: an inline value format, and a reference format used when a value appears more than once or inside a cycle (the value is hoisted into a function parameter so the references can share identity).

The inline format handles the eight Temporal.* types, but the reference format never got a matching case, so a repeated Temporal value falls through to the plain-object branch and is emitted as {}. It is silently lost:

const instant = Temporal.Instant.from('1999-09-29T05:30:00Z');

uneval([instant, instant]);
// before: (function(a){return [a,a]}({}))
// after:  (function(a){return [a,a]}(Temporal.Instant.from("1999-09-29T05:30:00Z")))

stringify round-trips the same input correctly ([[1,1],["Temporal.Instant","1999-09-29T05:30:00Z"]]), so the two serializers disagreed on a repeated Temporal value.

This mirrors the existing inline Temporal case into the reference switch and adds a repetition fixture. Reverting only the uneval.js change fails the new uneval: repetition case while the stringify/parse/unflatten checks stay green, which isolates the bug to uneval.

uneval's inline value format handles Temporal types, but the reference
format used for values that appear more than once (or in a cycle) had no
Temporal case, so it fell through to the plain-object branch and emitted
{}. A repeated Temporal value was therefore silently turned into an empty
object, while stringify round-tripped the same value correctly.

Mirror the Temporal cases into the reference format and add a repetition
fixture.
@changeset-bot

changeset-bot Bot commented Jun 29, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: efcb0be

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

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