Skip to content

[bug]: Phosphor icons and Breadcrumb component causes error #10503

@leofleeo

Description

@leofleeo

Describe the bug

Phosphor icons use context, which is unavailable in server components. To fix this, import icons that are used in server components from @phosphor-icons/react/ssr instead of the main package.

Affected component/components

Breadcrumb, other server components that use icons

How to reproduce

  1. Make a new next.js shadcn project with phosphor icons. (pnpm dlx shadcn@latest init --preset bp96 --template next --pointer)
  2. Install the breadcrumb component
  3. Add a simple usage with a separator like:
<Breadcrumb>
          <BreadcrumbItem>Foo</BreadcrumbItem>
          <BreadcrumbSeparator />
          <BreadcrumbItem>Bar</BreadcrumbItem>
</Breadcrumb>

in a server component
4. Run dev server and see error

Image

Codesandbox/StackBlitz link

https://codesandbox.io/p/devbox/breadcrumb-bug-demo-nkfhcl

Logs

GET / 500 in 1799ms (compile: 1697ms, render: 102ms)
⨯ 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
    at module evaluation (components/ui/breadcrumb.tsx:5:1)
    at module evaluation (app/page.tsx:1:1)
    at module evaluation (.next/dev/server/chunks/ssr/[root-of-the-server]__24026417._.js:209:47)
  3 |
  4 | import { cn } from "@/lib/utils"
> 5 | import { CaretRightIcon, DotsThreeIcon } from "@phosphor-icons/react"
    | ^
  6 |
  7 | function Breadcrumb({ className, ...props }: React.ComponentProps<"nav">) {
  8 |   return ( {
  page: '/'
}

System Info

Does not matter, happens in all environments

Before submitting

  • I've made research efforts and searched the documentation
  • I've searched for existing issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions