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

double renders with react-beautiful-dnd #496

Closed
jedierikb opened this issue Jul 26, 2020 · 9 comments
Closed

double renders with react-beautiful-dnd #496

jedierikb opened this issue Jul 26, 2020 · 9 comments

Comments

@jedierikb
Copy link

I am familiar with #307 rendering components with recoil twice on initialization.

But I am also getting double renders when I use https://github.com/atlassian/react-beautiful-dnd

Here is my test case [1]
https://github.com/jedierikb/recoil-beautiful-dnd

& here is the line you can toggle to switch between useRecoilState and useState:
https://github.com/jedierikb/recoil-beautiful-dnd/blob/master/src/App.js#L64

In the console you will note there are two renders after every drop operation when using useRecoilState.

I am not knowledgeable about what is happening under the hood in either library to possibly trigger the double rendering, but since it is a popular library I thought this issue might be of interest.

--

[1] adapted from one of their provided examples https://codesandbox.io/s/k260nyxq9v

@drarmstr
Copy link
Contributor

We are finalizing a diff now for Concurrent Mode support that reduces double renders in more situations. Hopefully that may help this example.

@a6625327
Copy link

We are finalizing a diff now for Concurrent Mode support that reduces double renders in more situations. Hopefully that may help this example.

How dose the Concurrent Mode will reduces double renders? Can u explain it in term of source code of the recoil for me ? Thank u very much!

@cornwe19
Copy link

Has there been any update on this issue? We're facing the same problem.

The only workaround I've found so far is to duplicate the recoil state with some dependent state within my component (using a hook like what is described here https://dev.to/bmingles/usedependentstate-react-usestate-hook-with-dependencies-29fj), but it's making a real mess of our code to have to capture 2 separate states like that.

@drarmstr
Copy link
Contributor

@cornwe19 - Are you still having issues when using the latest experimental React with Concurrent Mode enabled?

@caiwukun
Copy link

caiwukun commented Mar 14, 2021

hi~ same rerender problem with recoil@0.1.3
i run @salvoravida fork and it work
i wonder if this fix will be merged into master?

@cornwe19
Copy link

@drarmstr, as @caiwukun pointed out, switching to react experimental concurrent mode and Recoil 0.1.3 doesn't fix the issue. Is there a specific fork or experimental version of Recoil I should be using to take advantage of concurrent mode?

@timiscoding
Copy link

I'm seeing this issue too where recoil seems to be re-rendering before and after the atom state update which results in some list items briefly rendering their original order before the final order when dropping an item. I've even tried using react 18 with concurrent mode by using the new ReactDOM.createRoot API method.

Here's a sandbox: https://codesandbox.io/s/react-beautiful-dnd-recoil-flash-bug-58scv?file=/src/App.js

Ignoring the initial log, if you drop an item, it logs 'rendering recoil' before and after rendering the list whereas with the useState version, it only logs after.

timiscoding added a commit to Back2Dev/attendance that referenced this issue Aug 26, 2021
@timiscoding
Copy link

On further investigation, this bug is related to #1076 and already fixed in 0.4.0 but disabled by default behind the 'recoil_early_rendering_2021' flag. I made a fork of the package and re-enabled it as @timiscoding/recoil.

I have recreated the OP's test case https://codesandbox.io/s/double-render-recoil-bug-2tmmq?file=/src/index.js and if you use my forked package, the problem is gone.

timiscoding added a commit to Back2Dev/attendance that referenced this issue Nov 9, 2021
* tim-survey-builder: (26 commits)
  add readme
  Question types render own Inspector properties. Update parts atom to include type config.
  Enable importing absolute paths. Restructure folders.
  Recoil devtools. Mobile navbar views. Move items with animation.  Dnd lock axis.
  Improve mobile responsive for frame + single type. Refactor DND to avoid unneeded part rerenders.
  Short answer integration
  Start adding mobile responsiveness. Fix recoil not working in ios. Fix storybook startup issue due to new Framework imports.
  Fix ios bug where any component using react-tabulator eg. admin/forms/list won't show list items. see ngduc/react-tabulator#215
  Add ios build
  Add dragndrop for canvas
  Reinstalling storybook
  Load editor's json into builder. Builder can update editor source on clicking save. Update DND. Update placeholder type.
  Enable builder in editor without blowing up. Fix circular imports.
  Refactor recoil state. Load json and save source. Fix error in engine.js when using strict mode.
  Add toolbar to generate source. Refactor to make it easier to add new question types.
  Update single item styles
  Reduce storybook startup time. Update dnd for single items.
  Fix recoil + rbd bug github/facebookexperimental/Recoil#496 Fix styled-components bug github/styled-components/styled-components#3564
  Merge in Minh's short question code. Add dnd to single items.
  EditProperty can auto render with complex paths Modify single items in canvas and inspector
  ...
@drarmstr
Copy link
Contributor

Closing as this feature is now enabled by default.

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

7 participants