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

Support React 19 & Nextjs 15

Open downright-development opened this issue 1 year ago • 12 comments

Hey friends!

Love the project but prevents me from going to Nextjs 15 & react 19.

Any timeline on when dependencies will be updated to support react 19?

downright-development avatar Oct 25 '24 18:10 downright-development

Ping :) Been a week without any feedback. Any way we can help?

downright-development avatar Nov 01 '24 15:11 downright-development

Type error: 'SortableContext' cannot be used as a JSX component.
  Its type '({ children, id, items: userDefinedItems, strategy, disabled: disabledProp, }: Props) => Element' is not a valid JSX element type.
    Type '({ children, id, items: userDefinedItems, strategy, disabled: disabledProp, }: Props) => Element' is not assignable to type '(props: any) => ReactNode'.
      Type 'Element' is not assignable to type 'ReactNode'.

muhaimincs avatar Nov 03 '24 13:11 muhaimincs

try npm i --force or npm i --legacy-peer-deps, it might do the trick

brasillero avatar Nov 19 '24 03:11 brasillero

Is there a timeline kindly? I hate using hacks like peer-deps d:

samuelkingtwentytwo avatar Nov 25 '24 03:11 samuelkingtwentytwo

Can we have a estimated timeline on this? Big thanks.

TrustyTechSG avatar Nov 26 '24 02:11 TrustyTechSG

Is there a timeline kindly? I hate using hacks like peer-deps d:

I understand your concern, but using --legacy-peer-deps or --force isn't a hack—it's a temporary solution to help you move forward while the issue is being addressed. If your deadline allows you to stop just because you don't like a workaround, it might be worth waiting for the final version. In the end, using this 'hack' is just to install packages, and once it's stable, you can simply delete your lock-file and continue with the good old npm install.

brasillero avatar Nov 26 '24 15:11 brasillero

EDIT: I've moved this to #1559.

There's a bunch of these errors too:

node_modules/@dnd-kit/core/dist/components/Accessibility/Accessibility.d.ts:9:129 - error TS2503: Cannot find namespace 'JSX'.

9 export declare function Accessibility({ announcements, container, hiddenTextDescribedById, screenReaderInstructions, }: Props): JSX.Element | null;

Possibly related to https://react.dev/blog/2024/04/25/react-19-upgrade-guide#the-jsx-namespace-in-typescript.

As we can see in the tests of https://github.com/DefinitelyTyped/DefinitelyTyped/pull/69022, we need s/JSX.Element/React.JSX.Element. It's just that most occurrences in dnd-kit aren't actually spelled out in its code, e.g. the Accessibility component has no explicit return type. Somehow the type is inferred when generating the d.ts files.

Actually if I update to newer @react/types in this repo, it fails with a related error:

(typescript) Error: /home/philipp/repos/dnd-kit/packages/core/src/components/DndContext/DndContext.tsx(740,8): semantic error TS2786: 'Accessibility' cannot be used as a JSX component.
Its return type 'Element | ReactPortal | null' is not a valid JSX element.
Type 'ReactPortal' is not assignable to type 'ReactElement<any, any>'.
Types of property 'key' are incompatible.
Type 'Key | null' is not assignable to type 'string | null'.
Type 'number' is not assignable to type 'string'.

Philipp91 avatar Dec 06 '24 17:12 Philipp91

hey bro make sure you use "use client" on the top of parent component & "suppressHydrationWarning" attribute in each dragable element. I'm use react19 & nextjs15 it work so fine

DyKhang avatar Jan 04 '25 08:01 DyKhang

Also facing the same issue (Next.js 15 & React 19). We just need the dependencies to be updated. The build can succeed withskipLibraryCheck, but I don't think that's a viable solution.

Verino-profico avatar Jan 07 '25 10:01 Verino-profico

Any updates on this?

sirpeas avatar Jan 23 '25 12:01 sirpeas

Just create a type file, e.g. dnd-kit.d.ts with the following content

export * from '@dnd-kit/sortable';

declare module '@dnd-kit/sortable' {
  import React from 'react';
  import { ClientRect, UniqueIdentifier } from '@dnd-kit/core';
  import type { Disabled, SortingStrategy } from '../types';
  export interface Props {
    children: React.ReactNode;
    items: (UniqueIdentifier | {
      id: UniqueIdentifier;
    })[];
    strategy?: SortingStrategy;
    id?: string;
    disabled?: boolean | Disabled;
  }
  interface ContextDescriptor {
    activeIndex: number;
    containerId: string;
    disabled: Disabled;
    disableTransforms: boolean;
    items: UniqueIdentifier[];
    overIndex: number;
    useDragOverlay: boolean;
    sortedRects: ClientRect[];
    strategy: SortingStrategy;
  }
  export declare const Context: React.Context<ContextDescriptor>;
  export declare function SortableContext({ children, id, items: userDefinedItems, strategy, disabled: disabledProp, }: Props): React.ReactElement;
}

xepozz avatar Jul 10 '25 17:07 xepozz

Hi @clauderic 👋

I’m currently running into a TypeScript error when using SortableContext with the latest versions of React, Next.js, and TypeScript. My setup includes React 19.2.0, Next.js 15.5.4, and TypeScript 5.9.3, along with the following dnd-kit packages:

{
  "@dnd-kit/core": "^6.3.1",
  "@dnd-kit/modifiers": "^9.0.0",
  "@dnd-kit/sortable": "^10.0.0",
  "@dnd-kit/utilities": "^3.2.2"
}

I’m getting this error when trying to use SortableContext in a client component. I’ve already added "use client" at the top, checked the TypeScript config, reinstalled dependencies, and made sure I’m not using any custom .d.ts overrides, but the issue is still there. Everything compiles fine until SortableContext is rendered, at which point the JSX type check fails with the following error:

'SortableContext' cannot be used as a JSX component.
  Its type '({ children, id, items: userDefinedItems, strategy, disabled: disabledProp, }: Props) => Element' is not a valid JSX element type.
    Type '({ children, id, items: userDefinedItems, strategy, disabled: disabledProp, }: Props) => Element' is not assignable to type '(props: any) => ReactNode | Promise<ReactNode>'.
      Type 'Element' is not assignable to type 'ReactNode | Promise<ReactNode>'.
        Property 'children' is missing in type 'ReactElement<any, any>' but required in type 'ReactPortal'.

Screenshot of the error: Image

Could this be related to React 19 or the latest Next.js version? If not, any guidance or an update on supporting the latest versions would be really appreciated.

faridvatani avatar Oct 12 '25 09:10 faridvatani