Skip to content

fix: guard against null Command.Item value (TypeError on 'in' operator)#407

Open
guuszz wants to merge 2 commits into
dip:mainfrom
guuszz:fix/null-value-in-operator
Open

fix: guard against null Command.Item value (TypeError on 'in' operator)#407
guuszz wants to merge 2 commits into
dip:mainfrom
guuszz:fix/null-value-in-operator

Conversation

@guuszz
Copy link
Copy Markdown

@guuszz guuszz commented May 31, 2026

Bug

<Command.Item value={null}> throws TypeError: Cannot use 'in' operator to search for 'current' in null instead of rendering. Reported in #404.

Root cause

In useValue (cmdk/src/index.tsx), each part of the value dependencies is inspected with:

if (typeof part === 'object' && 'current' in part) {

When value={null}, part is null. Because typeof null === 'object' (the long-standing JavaScript quirk), the first condition passes and execution reaches 'current' in null, which throws — the in operator requires an object on its right-hand side.

Fix

Add a truthiness guard so null/undefined short-circuit before reaching the in operator:

if (part && typeof part === 'object' && 'current' in part) {

Real refs are truthy objects, so existing behavior is unchanged — only the null/undefined case is now handled gracefully.

Fixes #404

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.

TypeError: Cannot use 'in' operator to search for 'current' in null when CommandItem value is null

1 participant