huntabyte / cmdk-sv

cmdk, but for Svelte ✨
https://cmdk-sv.com
MIT License
423 stars 18 forks source link

Bug: Does not render any elements if children are changed. #19

Closed brunostjohn closed 8 months ago

brunostjohn commented 8 months ago

Problem:

When loading elements using async blocks or just conditional rendering using if blocks, the Command element won't get updated and searching always yields no results. Occurs in shadcn svelte and without.

Minimal repro:

<script lang="ts">
  import * as Command from "@ui/Command";

  let searchVal: string = "";
</script>

<Command.Root class="rounded-lg border shadow-md max-w-screen-sm">
  <Command.Input placeholder="Type a command or search..." bind:value={searchVal} />
  <Command.List>
    {#if searchVal.trim() !== ""}
      <Command.Empty>No results found.</Command.Empty>
      <Command.Group heading="Suggestions">
        <Command.Item>
          <Calendar class="mr-2 h-4 w-4" />
          <span>Calendar</span>
        </Command.Item>
        <Command.Item>
          <Smile class="mr-2 h-4 w-4" />
          <span>Search Emoji</span>
        </Command.Item>
        <Command.Item>
          <Calculator class="mr-2 h-4 w-4" />
          <span>Calculator</span>
        </Command.Item>
      </Command.Group>
      <Command.Separator />
      <Command.Group heading="Settings">
        <Command.Item>
          <User class="mr-2 h-4 w-4" />
          <span>Profile</span>
          <Command.Shortcut>⌘P</Command.Shortcut>
        </Command.Item>
        <Command.Item>
          <CreditCard class="mr-2 h-4 w-4" />
          <span>Billing</span>
          <Command.Shortcut>⌘B</Command.Shortcut>
        </Command.Item>
        <Command.Item>
          <Settings class="mr-2 h-4 w-4" />
          <span>Settings</span>
          <Command.Shortcut>⌘S</Command.Shortcut>
        </Command.Item>
      </Command.Group>
    {/if}
  </Command.List>
</Command.Root>
huntabyte commented 8 months ago

Thanks for creating this issue, will investigate further!