structuredClone shortens sparse arrays with trailing holes

Open Beginner friendly
#58,208 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
javascript, react-native
Domain
mobile

Research direction

Start by locating the React Native structuredClone polyfill and reproduce the issue with a sparse array such as new Array(3) with only index 1 populated. Verify that the clone preserves the source length and trailing holes, matching Node's native structuredClone behavior.

Written by the indexing model from the issue text.

Description

Needs: Author Feedback Needs: Repro
Description

The React Native structuredClone polyfill initializes an array clone as [] and only assigns enumerable keys. If a sparse array's highest populated index precedes its declared length, the trailing holes are lost and the clone is silently shortened. For example, new Array(3) with only index 1 populated becomes length 2.

Expected behavior

The clone should preserve the source array's declared length and holes. Node's native structuredClone follows this behavior.

React Native Version

0.87.1 and current main

Affected Platforms

JavaScript runtime - All

Dominant language
C++
Stars
127k
Forks
25.3k
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from react/react-native

All issues in react/react-native

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.