fix: dev warning for duplicate item keys (#16), close #17#23
Merged
Conversation
Items with non-primitive values (e.g. objects) and no explicit key field produce String(value) = "[object Object]" as the React key for every row, causing silent duplicate-key bugs. A dev-only console.warn now fires whenever the items array contains duplicate computed keys, telling the developer exactly which keys collided and what to do: [ink-enhanced-select-input] Duplicate item keys detected: [object Object]. Set a unique "key" on each item — this is required when value is a non-primitive type (e.g. object). The check runs inside the existing items-change useEffect so it fires on mount and whenever items update. It is a no-op in production (process.env.NODE_ENV === 'production'). 2 new tests (55 total): warns in development when object-valued items have no key field no duplicate key warning when all items have explicit keys Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #16 — duplicate React keys for object-valued items
Items with non-primitive values (objects) and no explicit
keyfield produceString(value) = "[object Object]"as the React key for every row, causing silent duplicate-key bugs that are hard to trace.A dev-only
console.warnnow fires when duplicate computed keys are detected:The check lives in the existing
items-changeuseEffectso it runs on mount and on every items update. It is a no-op in production (process.env.NODE_ENV === 'production').Closes #17 — spurious onHighlight
Already resolved in PR #19 (v0.5.0). Closing via issue comment.
Test plan
yarn build— no TypeScript errorsyarn test— 55/55 pass (2 new tests)🤖 Generated with Claude Code