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]: Combobox - Unhandled Runtime Error TypeError: Array.from requires an array-like object - not null or undefined #3051

Closed
2 tasks done
ScottyMaher opened this issue Mar 19, 2024 · 20 comments
Labels
bug Something isn't working

Comments

@ScottyMaher
Copy link

ScottyMaher commented Mar 19, 2024

Describe the bug

In an any Next.js project this is an issue I get simply trying to use the first example combobox as is - copying straight from the docs and without changing anything.

The issue is that the first and last examples do not use a <CommandList> to wrap the <CommandEmpty> and <CommandGroup>. To fix the issue, there must be a CommandList, as the cmdk docs specify.

Here is an excerpt from the first example:

<Command>
  <CommandInput placeholder="Search framework..." className="h-9" />
  <CommandEmpty>No framework found.</CommandEmpty>
  <CommandGroup>
    {frameworks.map((framework) => (
      // some code for CommandItems
    ))}
  </CommandGroup>
</Command>

To fix the issue, add CommandList to the imports and change it to this:

<Command>
  <CommandInput placeholder="Search framework..." className="h-9" />
  <CommandList>
    <CommandEmpty>No framework found.</CommandEmpty>
    <CommandGroup>
      {frameworks.map((framework) => (
        // some code for CommandItems
      ))}
    </CommandGroup>
  </CommandList>
</Command>

The update to cmdk also included "The aria-disabled and aria-selected props will now be set to false, instead of being undefined", which means that the tailwind on the CommandItem also needs to be changed otherwise the mouse events will be disabled on the list:

- "data-[disabled]:pointer-events-none data-[disabled]:opacity-50"
+ "data-[disabled='true']:pointer-events-none data-[disabled='true']:opacity-50"

Affected component/components

Combobox

How to reproduce

  1. Install a fresh Next.js project
  2. Init shadcn and install combobox dependencies
  3. Copy combobox demo code
  4. Try to use the combobox

Codesandbox/StackBlitz link

No response

Logs

Unhandled Runtime Error
TypeError: Array.from requires an array-like object - not null or undefined
Call Stack
from

[native code]
forEach

[native code]

System Info

Tested on MacOS Sonoma and Windows 10, with Next.js 14.

Before submitting

  • I've made research efforts and searched the documentation
  • I've searched for existing issues
@paresiqbal
Copy link

But it can't be click now, but still able to use search and press enter.

@ScottyMaher
Copy link
Author

ScottyMaher commented Mar 19, 2024

But it can't be click now, but still able to use search and press enter.

Yeah that's an issue as well. As mentioned in a different thread, the breaking update to cmdk also included "The aria-disabled and aria-selected props will now be set to false, instead of being undefined", which means that the tailwind on the CommandItem needs to be changed to:

- "data-[disabled]:pointer-events-none data-[disabled]:opacity-50"
+ "data-[disabled='true']:pointer-events-none data-[disabled='true']:opacity-50"

I'll include this in the original post

@joonheeu
Copy link

I resolved the issue temporarily by downgrading the version.

# package.json

- "cmdk": "^1.0.0",
+ "cmdk": "0.2.0",
npm install

@treipatru
Copy link

I resolved the issue temporarily by downgrading the version.

- "cmdk": "^1.0.0",
+ "cmdk": "0.2.0",

Thanks for the suggestion. I just tried with v 0.2.1 and that works too.

@dsyx
Copy link

dsyx commented Mar 20, 2024

cmdk v1.0.0 has a breaking update:

Command.List is now required (CommandList in shadcn)

Rendering the Command.List part (CommandList if using shadcn) is now mandatory. Otherwise, you should expect to see an error like this:

TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))

Currently, the dependency of the Combobox example is: "cmdk": "^0.2.0".

It is not recommended to use CommandList to contain CommandItem, which will disable pointer events of CommandItem.

@jercomio
Copy link

Hello, I had the same problem with Next.js 14 and I found the following solution:

  1. CommandList is required (@dsyx )
  2. In command.tsx and for CommandItem, replace in className:
    data-[disabled]:pointer-events-none by data-[disabled]:pointer-events-auto

And now, the Combobox component works.

@isneverdead
Copy link

i have solution here, i'm using "cmdk": "^0.2.0"but because it will disable the pointer events of commandItem, i'm adding state to popover and change the state when user click on the initial button or the commandGroup. i know maybe it not the best but at least it can work again until this bug get fixed.
ezgif-7-a4fa254d26

const Page = () => {
........

  const [popover1, setPopover1] = useState(false);

........
<Popover open={popover1}>  // <------------ here
    <PopoverTrigger asChild>
      <FormControl>
        <Button
          onClick={() => setPopover1(!popover1)} // <------------ here
          variant='outline'
          role='combobox'
          className={cn(
            'w-[200px] justify-between',
            !field.value && 'text-muted-foreground'
          )}
        >
          {field.value
            ? vendorList.find(
                (vndr) => vndr.value === field.value
              )?.label
            : 'Select Vendor'}
          <CaretSortIcon className='ml-2 h-4 w-4 shrink-0 opacity-50' />
        </Button>
      </FormControl>
    </PopoverTrigger>
    <PopoverContent className='w-[200px] p-0'>
      <Command>
        <CommandInput
          placeholder='Search Vendor...'
          className='h-9'
        />
        <CommandEmpty>No framework found.</CommandEmpty>
        <CommandGroup onClick={() => setPopover1(!popover1)}>  // <------------ here
          {vendorList.map((vendorItem) => (
            <CommandItem
              value={vendorItem.label}
              key={vendorItem.value}
              onSelect={() => {
                form.setValue('vendorId', vendorItem.value);
              }}
            >
              {vendorItem.label}
              <CheckIcon
                className={cn(
                  'ml-auto h-4 w-4',
                  vendorItem.value === field.value
                    ? 'opacity-100'
                    : 'opacity-0'
                )}
              />
            </CommandItem>
          ))}
        </CommandGroup>
      </Command>
    </PopoverContent>
  </Popover>

@maik-emanoel
Copy link

I resolved the issue temporarily by downgrading the version.

# package.json

- "cmdk": "^1.0.0",
+ "cmdk": "0.2.0",
npm install

This worked perfectly to me, thanks.

@d1d4r
Copy link

d1d4r commented Apr 2, 2024

I resolved the issue temporarily by downgrading the version.

# package.json

- "cmdk": "^1.0.0",
+ "cmdk": "0.2.0",
npm install

it work perfectly

@aminulidev
Copy link

data-[disabled='true']:pointer-events-none data-[disabled='true']:opacity-50

Its working for me. thanks

@treipatru
Copy link

While downgrading the version of cmdk works well, there is a drawback: the keywords prop does not exist in 0.2.1 and below.
So if you need to filter by multiple values, the original workaround (1st post) works just fine with the latest cmdk version. Thanks everyone for the shared info 🙏

@mk48
Copy link

mk48 commented Apr 23, 2024

Hello, I had the same problem with Next.js 14 and I found the following solution:

1. `CommandList` is required (@dsyx )

2. In `command.tsx` and for `CommandItem`, replace in `className`:
   `data-[disabled]:pointer-events-none` by `data-[disabled]:pointer-events-auto`

And now, the Combobox component works.

Thanks, It's fixed the issue

@harryzcy
Copy link
Contributor

Why is this closed as completed? Is #3268 the right PR that's working on this?

@ScottyMaher
Copy link
Author

ScottyMaher commented Apr 27, 2024

Why is this closed as completed? Is #3268 the right PR that's working on this?

Oh, I just closed it because it has an answer on how to fix it now. Was able to update the OP with the answers as people commented them. Similar to how I might close my issue on StackOverflow once it's been successfully answered. Based on your comment I'm guessing it's supposed to stay open until the fix exists in the actual source code? This is the first github issue I've ever posted.

@michidk
Copy link

michidk commented Apr 27, 2024

Yeah, I think this bug report should stay open until the bug is fixed (which is it not) and the code works as intended.

@code-PA-32
Copy link

None of the fixes—not data-[disabled='true'] or a CMDK downgrade—work.
😃

@lohrm-stabl
Copy link

@ScottyMaher can you please reopen this?

@ScottyMaher ScottyMaher reopened this May 15, 2024
@rppala3
Copy link

rppala3 commented May 15, 2024

This worked for me as well.

Hello, I had the same problem with Next.js 14 and I found the following solution:

1. `CommandList` is required (@dsyx )

This is not needed.

2. In `command.tsx` and for `CommandItem`, replace in `className`:
   `data-[disabled]:pointer-events-none` by `data-[disabled]:pointer-events-auto`

At this point this is not a bug anymore, but it's a misalignment with the documentation.
See combobox page. All the examples contain legacy code.
That is not true in the command page. The examples are good.

@TobX12
Copy link

TobX12 commented Jun 3, 2024

Only the downgrade fix worked for me, not the one with

  1. In command.tsx and for CommandItem, replace in className:
    data-[disabled]:pointer-events-none by data-[disabled]:pointer-events-auto

As I am not using the combox, only the "CommandInput"

      <CommandInput
        placeholder="Search for a name"
        value={searchText}
        onValueChange={(value) => setSearchText(value)} />
      </Command>

Event this leads to the Error

TypeError: Array.from requires an array-like object - not null or undefined

Any ideas how to fix this besides downgrading?

ukeSJTU added a commit to ukeSJTU/minerva that referenced this issue Jul 1, 2024
This downgrade is aimed to solve the error: TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator)) arousing from the using popover component of shadcn/ui. For details, see github issues here: shadcn-ui/ui#3051.
@ScottyMaher
Copy link
Author

Fixed in #2945

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests