Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug in getValidItems function #268

Open
csaba-veezla opened this issue May 27, 2024 · 0 comments
Open

bug in getValidItems function #268

csaba-veezla opened this issue May 27, 2024 · 0 comments

Comments

@csaba-veezla
Copy link

csaba-veezla commented May 27, 2024

Im not entirely sure how we run into this issue, but I know there is an issue with this code:

cmdk/cmdk/src/index.tsx

Lines 399 to 407 in 541fad2

const group = item.closest(GROUP_ITEMS_SELECTOR)
if (group) {
group.appendChild(item.parentElement === group ? item : item.closest(`${GROUP_ITEMS_SELECTOR} > *`))
} else {
listInsertionElement.appendChild(
item.parentElement === listInsertionElement ? item : item.closest(`${GROUP_ITEMS_SELECTOR} > *`),
)
}

As you can see if we get a null as a result for group in line 399, we will take the second branch in line 404.
As you know if item.closest(GROUP_ITEMS_SELECTOR) is null, then item.closest(``${GROUP_ITEMS_SELECTOR} > *``) will definitely be null as well.

So in line 405 you will try to feed null as the parameter, which will result in an error:
Uncaught TypeError: Failed to execute 'appendChild' on 'Node': parameter 1 is not of type 'Node'.

Edit:
It seems, this happens, when there is no group In the list, and it is "portalled" to the body.

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

No branches or pull requests

1 participant