Skip to content

fix: dev warning for duplicate item keys (#16), close #17#23

Merged
gfargo merged 1 commit into
mainfrom
fix/duplicate-key-warning
May 5, 2026
Merged

fix: dev warning for duplicate item keys (#16), close #17#23
gfargo merged 1 commit into
mainfrom
fix/duplicate-key-warning

Conversation

@gfargo
Copy link
Copy Markdown
Owner

@gfargo gfargo commented May 5, 2026

Summary

Closes #16 — duplicate React keys for object-valued items

Items with non-primitive values (objects) and no explicit key field produce String(value) = "[object Object]" as the React key for every row, causing silent duplicate-key bugs that are hard to trace.

A dev-only console.warn now fires when duplicate computed keys are detected:

[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 lives in the existing items-change useEffect so 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 errors
  • yarn test — 55/55 pass (2 new tests)
New test What it covers
warns in development when object-valued items have no key field Warning fires with correct message
no duplicate key warning when all items have explicit keys No false positives

🤖 Generated with Claude Code

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>
@gfargo gfargo merged commit 29dcacd into main May 5, 2026
@gfargo gfargo deleted the fix/duplicate-key-warning branch May 5, 2026 14:36
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.

bug: onHighlight fires spuriously when items array reference changes bug: items with object values and no key field produce duplicate React keys

1 participant