dnd-kit icon indicating copy to clipboard operation
dnd-kit copied to clipboard

Add "use client" to DragDropProvider for React 19 compatibility in @dnd-kit/react

Open pedro757 opened this issue 9 months ago • 5 comments

You have to add "use client"; at the top of the file, to allow us to use this Component in a server component

pedro757 avatar Apr 16 '25 12:04 pedro757

There's a use client here: https://github.com/clauderic/dnd-kit/blob/experimental/packages/react/src/core/index.ts#L1

Is that not sufficient?

clauderic avatar Apr 18 '25 00:04 clauderic

It doesn't work, I had to wrap it in a "use client"; file like this:

// provider.tsx
"use client";

import { DragDropProvider } from "@dnd-kit/react";

export function Layout(props: { children: React.ReactNode }) {
  return <DragDropProvider>{props.children}</DragDropProvider>;
}

And Import it in the layout like this:

import { Layout } from "./provider";

export default Layout;

Otherwise if I don't put "use client"; I get this error:

TypeError: (0 , {imported module [project]/nodemodules/next/dist/server/route-modules/app-page/vendored/rsc/react.js [app-rsc] (ecmascript)}.createContext) is not a function

pedro757 avatar Apr 21 '25 12:04 pedro757

I added it here https://github.com/clauderic/dnd-kit/commit/42bec2c507adf5659d70a1d5fba33847b0efe016, can you try out this version of @dnd-kit/react and let me know if it works: 0.1.2-beta-20250421131817

clauderic avatar Apr 21 '25 13:04 clauderic

No, this version doesn't work either: "@dnd-kit/react": "0.1.2-beta-20250421131817",

pedro757 avatar Apr 21 '25 19:04 pedro757

There's a "use client" at the top of the file now, so not sure why it's not working?

clauderic avatar Apr 21 '25 19:04 clauderic