Skip to content

Preserve sparse array length in structuredClone - #58209

Open
OskarEichler wants to merge 1 commit into
react:mainfrom
OskarEichler:codex/fix-structured-clone-sparse-arrays
Open

Preserve sparse array length in structuredClone#58209
OskarEichler wants to merge 1 commit into
react:mainfrom
OskarEichler:codex/fix-structured-clone-sparse-arrays

Conversation

@OskarEichler

Copy link
Copy Markdown
Contributor

Summary:

The structured-clone polyfill initializes array results at length zero, so sparse arrays with trailing holes are shortened. Initialize the clone at the source length before recursively copying enumerable keys, preserving both holes and declared length.

Fixes #58208.

Changelog:

[GENERAL] [FIXED] - Preserve sparse array length and trailing holes in structuredClone.

Test Plan:

  • Exact baseline cloned a length-3 sparse array as length 2 while retaining key 1.
  • Fixed focused Fantom suite: 33/33 passed; behavior matches Node's native structuredClone.
  • Fresh yarn flow-check: 0 errors.
  • Targeted ESLint, Prettier, and git diff --check passed.

No UI change; screenshots are not applicable.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 30, 2026
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Aug 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

structuredClone shortens sparse arrays with trailing holes

1 participant