Skip to content

fix: Default keyExtractor returning the same key for all objects - #643

Draft
MatiPl01 wants to merge 3 commits into
mainfrom
fix/default-key-extractor
Draft

MatiPl01 wants to merge 3 commits into
mainfrom
fix/default-key-extractor

Conversation

@MatiPl01

@MatiPl01 MatiPl01 commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Description

The default keyExtractor is documented as returning the stringified item for objects that have neither an id nor a key. It used String(item), which returns [object Object] for every plain object, so all such items got the same key.

Objects whose string value is [object Object] are now passed through JSON.stringify. Nothing changes for items with an id or a key, for primitive items and for objects with their own string value (arrays, dates, classes with toString). An item that cannot be serialized (circular, or holding a React element in development) keeps the old key instead of throwing.

The key of such an item now depends on its content, so changing the item remounts it. Passing a keyExtractor stays the recommended way, as the docs already say.

Testing

New jest tests (the plain object case fails on main).

Evidence
Test on main before-test-on-main.txt
Test with the fix after-test-with-fix.txt

String() returned '[object Object]' for every such item, so all items got the same key.
@vercel

vercel Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
react-native-sortables-docs Ignored Ignored Preview Nov 25, 2026 8:29pm UTC

@MatiPl01 MatiPl01 self-assigned this Nov 25, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant