timc1 / kbar

fast, portable, and extensible cmd+k interface for your site
https://kbar.vercel.app
MIT License
4.87k stars 184 forks source link

Next.js 14 App router layout.tsx: Fails to spawn the command palette #358

Closed Aymericr closed 2 days ago

Aymericr commented 7 months ago

Fails to spawn the command palette. I tried wrapping it into a 'use client' component but the issue keeps happening.

Dependencies:

Error: Invariant failed: Input ref is undefined, make sure you attach `query.inputRefSetter` to your search input.

Call Stack
invariant
node_modules/tiny-invariant/dist/tiny-invariant.cjs.js (14:1)
Object.getInput
node_modules/kbar/lib/useStore.js (107:1)
handler
node_modules/kbar/lib/InternalEvents.js (277:1)

CleanShot 2024-05-01 at 11 53 48@2x

0x33dm commented 4 months ago

did you manage to solve this?

0x33dm commented 4 months ago

For me adding use client at the top of the provider ( which is them added to my root layout ) is yielding another error.

// KBarProvider.ts

'use client'

import {
  KBarAnimator,
  KBarPortal,
  KBarPositioner,
  KBarProvider as OriginalKBarProvider,
  KBarSearch
} from 'kbar'
import type { ReactNode } from 'react'

interface Props {
  children: ReactNode
}

const KBarProvider = ({ children }: Props) => {
  return (
    <OriginalKBarProvider>
      <KBarPortal>
        <KBarPositioner>
          <KBarAnimator>
            <KBarSearch />
            {/* <KBarResults /> */}
          </KBarAnimator>
        </KBarPositioner>
      </KBarPortal>
      {children}
    </OriginalKBarProvider>
  )
}

export default KBarProvider

The error i get is:

[!caution] TypeError: createContext only works in Client Components. Add the "use client" directive at the top of the file to use it. Read more: https://nextjs.org/docs/messages/context-in-server-component

stale[bot] commented 1 week ago

Hey! This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.