Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React 18 (RC 0) StrictMode rendering breaks ability to find node by it's draggable id #2350

Open
Malien opened this issue Dec 22, 2021 · 37 comments

Comments

@Malien
Copy link

Malien commented Dec 22, 2021

Expected behavior

React Beautiful DnD should work as advertised on the latest React version with StrictMode enabled (which is a common default nowadays)

Actual behavior

Library fails to find draggable nodes with messaged logged (in development mode):
Unable to find draggable with id: card-2

When using the, now deprecated, ReactDOM.render API (instead of new ReactDOM.createRoot), React is forced to work in React 17 compatible manner, which eliminates the problem.

As I've found out, removing <React.StrictMode /> wrapper resolved the issue, which means React Beautiful DnD is not compatible with Strict Effects

With the release of React 18, StrictMode gets an additional behavior that we call “strict effects” mode. When strict effects are enabled, React intentionally double-invokes effects (mount -> unmount -> mount) for newly mounted components. Like other strict mode behaviors, React will only do this for development builds.

Steps to reproduce

  1. yarn add react@rc react-dom@rc react-beautiful-dnd,
ReactDOM.createRoot(document.getElementById("root")).render(
  <React.StrictMode>
    <App />
  </React.StrictMode>
)
  1. Follow the guide precisely
  2. *profit*

Suggested solution?

I am not familiar with innerworkings of the library, but I suspect the way registrations registry.draggable are handled makes StrictMode incompatible (I've only looked into it in debugger for like 10 seconds). I suspect other registrations also fail

What version of React are you using?

18.0.0-rc0

What version of react-beautiful-dnd are you running?

13.1.2

What browser are you using?

Safari 15.2 beta, Chrome 96

Demo

https://codesandbox.io/s/vertical-list-forked-hd8ve?file=/index.js

@faradaytrs
Copy link

Same here, any plans to resolve this?

@100terres
Copy link
Contributor

You can follow the progress of this issue here: hello-pangea/dnd#317

@Shahzad6077
Copy link

any updates on this issue?

@mjoycemilburn
Copy link

Hit this issue today too. 'Fixed' by removing the <React.StrictMode> components round the rendering ofin my index.js.

@enisdenjo
Copy link

Beware guys that StrictMode also helps you with preparing your development builds for production. Make sure to check whether the issue is present in production too.

kasterra added a commit to kasterra/todo-proj that referenced this issue Jun 1, 2022
atlassian/react-beautiful-dnd#2350 dnd doesn't support StrictMode now
kasterra added a commit to kasterra/todo-proj that referenced this issue Jun 1, 2022
kasterra added a commit to kasterra/todo-proj that referenced this issue Jun 1, 2022
@jbournonville
Copy link

Will it be fixed ?
I'm not a fan of removing StrictMode... it's a dirty fix and React 18 is not in rc anymore.

@Danzo7
Copy link

Danzo7 commented Jun 20, 2022

any fix yet?

@Malin88
Copy link

Malin88 commented Jun 29, 2022

same problem here :/

@aujisti-ador
Copy link

same issue. Is there any fix for avoiding a way around like removing strict mode?

@ShekibAziz
Copy link

same problem

@peterb0yd
Copy link

yup, same thing

@bhagi108
Copy link

going through same issue.

@Meligy
Copy link

Meligy commented Jul 19, 2022

The workaround here works OK for me: #2399 (comment)

@Xhale1
Copy link

Xhale1 commented Aug 13, 2022

If anyone is looking for a less hacky solution, I have a fork of this library @hello-pangea/dnd which natively supports react 18 and react strict mode.

Just replace react-beautiful-dnd with @hello-pangea/dnd and you should be good to go 👍

@Kahitar
Copy link

Kahitar commented Sep 11, 2022

If anyone is looking for a less hacky solution, I have a fork of this library @hello-pangea/dnd which natively supports react 18 and react strict mode.

Just replace react-beautiful-dnd with @hello-pangea/dnd and you should be good to go 👍

Is this going to be merged into react-beautiful-dnd eventually?

@RGBWang
Copy link

RGBWang commented Sep 24, 2022

same problem

@Hollumidhe
Copy link

@Xhale1 I seems not to get it, replacing it means installing @hello-pangea/dnd](https://github.com/hello-pangea/dnd). won't it affect the functions?

@100terres
Copy link
Contributor

@Kahitar

Is this going to be merged into react-beautiful-dnd eventually?

I do not think it will. Atlassian do not plan to put more effort on this library. At least in the foreseeable future.

@arfanliaqat
Copy link

Ran into same problem

@WGTW
Copy link

WGTW commented Nov 16, 2022

It's been nearly a year, please fix this.

@shunk76
Copy link

shunk76 commented Nov 17, 2022

This article is helpful to me.
https://medium.com/@wbern/getting-react-18s-strict-mode-to-work-with-react-beautiful-dnd-47bc909348e4

@Grawl
Copy link

Grawl commented Dec 7, 2022

I can confirm that solution from @shunk76 comment is working

@ThaJay
Copy link

ThaJay commented Feb 27, 2023

I can confirm that the solution #2350 (comment) by 100terres is working.

This library continues to be relied upon heavily by Atlassian products, but we are focused on other priorities right now and have no current plans for further feature development or improvements.

It will continue to be here on GitHub and we will still make critical updates (e.g. security fixes, if any) as required, but will not be actively monitoring or replying to issues and pull requests.

This opening statement from the readme does not sound true as strict mode seems pretty critical to me for any serious production environment.

@immortalt
Copy link

@ranlix
Copy link

ranlix commented Mar 28, 2023

Samox added a commit to twentyhq/twenty that referenced this issue Jun 8, 2023
Atlassion has not fixed this issue in a year so we use the fork @hello-pangea/dnd
atlassian/react-beautiful-dnd#2350
Samox added a commit to twentyhq/twenty that referenced this issue Jun 8, 2023
* refactor: extract data from Board component

* feature: display board on opportunities page

* test: add strict mode in storybook

* chore: replace dnd to make it work with React 18 and strict mode

Atlassion has not fixed this issue in a year so we use the fork @hello-pangea/dnd
atlassian/react-beautiful-dnd#2350

* refactor: move mocked-data in a file

* chore: use real column names in mock data

* feature: design columns

* feature: add New button at bottum of columns

* bugfix: move header out of dragable so the cards does not flicker on drop

* lint: remove useless imports

* refactor: rename board item key
@minhtrung0110
Copy link

minhtrung0110 commented Jul 10, 2023

After some searching, I came across a very helpful snippet by GiovanniACamacho, which was converted to TypeScript by Meligy in that same issue, which resolved my problems and made me able to drag and drop again, with Strict Mode enabled.

import { useEffect, useState } from "react"; import { Droppable, DroppableProps } from "react-beautiful-dnd"; export const StrictModeDroppable = ({ children, ...props }: DroppableProps) => { const [enabled, setEnabled] = useState(false); useEffect(() => { const animation = requestAnimationFrame(() => setEnabled(true)); return () => { cancelAnimationFrame(animation); setEnabled(false); }; }, []); if (!enabled) { return null; } return <Droppable {...props}>{children}</Droppable>; };

@checklist
Copy link

I switched to https://github.com/hello-pangea/dnd and all issues were solved.

@Chaobanh27
Copy link

If anyone is looking for a less hacky solution, I have a fork of this library @hello-pangea/dnd which natively supports react 18 and react strict mode.

Just replace react-beautiful-dnd with @hello-pangea/dnd and you should be good to go 👍

Tks man you helped me

@leikoilja
Copy link

leikoilja commented Oct 6, 2023

Here is a typescript version for the Droppable components compatible with strict mode.
I can confirm that it works on NextJS 13

KonohaBrain125 pushed a commit to KonohaBrain125/Modern-Open-Source-CRM-20 that referenced this issue Oct 28, 2023
* refactor: extract data from Board component

* feature: display board on opportunities page

* test: add strict mode in storybook

* chore: replace dnd to make it work with React 18 and strict mode

Atlassion has not fixed this issue in a year so we use the fork @hello-pangea/dnd
atlassian/react-beautiful-dnd#2350

* refactor: move mocked-data in a file

* chore: use real column names in mock data

* feature: design columns

* feature: add New button at bottum of columns

* bugfix: move header out of dragable so the cards does not flicker on drop

* lint: remove useless imports

* refactor: rename board item key
@CarloshDevBR
Copy link

CarloshDevBR commented Dec 8, 2023

https://github.com/hello-pangea/dnd is a fork that solves this stickmode problem

The funniest thing is that the lib was working correctly and suddenly it stopped working, I'm using React 18.2.0, Next 14.0.2

@SumanKisku
Copy link

SumanKisku commented Dec 28, 2023

https://github.com/hello-pangea/dnd is a fork that solves this stickmode problem

The funniest thing is that the lib was working correctly and suddenly it stopped working, I'm using React 18.2.0, Next 14.0.2
@CarloshDevBR
Is it still causing problem?

@CarloshDevBR
Copy link

I didn't have any more problems

@dimple06varshney
Copy link

I also faced the same issue, as I tried to find out the difference between the code I wrote and the example code from the documentation, I found <React.StrictMode> is only when I commented out, that it works.

@evgar
Copy link

evgar commented Mar 5, 2024

Run into same problem

@mskVitalii
Copy link

Run into same problem with Next.js

Set StrictMode to false and it's working + made rnd work only on client (works only after useEffect)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests