rc-dock icon indicating copy to clipboard operation
rc-dock copied to clipboard

Fix DockLayout.updateTabCache

Open Shravankumarkarnati opened this issue 1 year ago • 8 comments

Fixes #198, #195

This seems to be a problem with useEffect running twice in React 18 StrictMode.

Fixed it by adding an equality check on current cache and given children to update. Only update the cache (and forceUpdate) if they are not same.

Shravankumarkarnati avatar Jul 22 '23 18:07 Shravankumarkarnati

@rinick @slavamuravey does this look right to you?

Shravankumarkarnati avatar Jul 22 '23 18:07 Shravankumarkarnati

Can someone please fix this bug?

zelongjiang123 avatar Aug 03 '23 14:08 zelongjiang123

This seems like a known issue. It's frustrating that the layout crashes occasionally. If this pull request fixes the problem, it would be great to merge it to the main branch.

yepw avatar Aug 11 '23 19:08 yepw

Applied temporary patch-package with the fix the problem is still occurring but less frequently.

Here's an example: https://codesandbox.io/s/cycle-update-bug-vdphjp?file=/src/App.tsx

Drag a bunch of Draggable elements into the layout as floating windows, it crashes after a bit.

This might be related to the onLayoutChange on controlled layouts, as removing that and layout definition (leaving defaultLayout and loadTab only) solves the problem altogether.

garyvh2 avatar Sep 12 '23 21:09 garyvh2

@garyvh2 looks like the tabs in your example are unstable. Their randomly generated id keeps changing on every update and so the cache is updating. If you don't have stable ids, you can leave it to rc-dock. I believe rc-dock creates and re-uses tab ids on updates.

Shravankumarkarnati avatar Sep 14 '23 15:09 Shravankumarkarnati

I've updated the solution in this case removing the uuid. I tried to let rc-dock handle the id on it's own, but it seems it's not possible, if not provided then the id is set as undefined.

I've updated the example with a simple count on the outside, which is set on drag n drop, and also used the prior id on loadTab, but the problem is still present.

garyvh2 avatar Sep 19 '23 21:09 garyvh2

Can someone approve this? We get similar error for React 18 floating tabs when window is resized and it crashes the app.

react-dom.development.js:27292 Uncaught Error: Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops. at checkForNestedUpdates (react-dom.development.js:27292:1) at scheduleUpdateOnFiber (react-dom.development.js:25475:1) at Object.enqueueForceUpdate (react-dom.development.js:14120:1) at Component.forceUpdate (react.development.js:373:1) at DockLayout.updateTabCache (DockLayout.js:74:1) at DockTabPane.updateCache (DockTabPane.js:24:1) at DockTabPane.componentDidUpdate (DockTabPane.js:63:1) at commitLayoutEffectOnFiber (react-dom.development.js:23333:1) at commitLayoutMountEffects_complete (react-dom.development.js:24688:1) at commitLayoutEffects_begin (react-dom.development.js:24674:1)

denspi avatar Nov 24 '23 11:11 denspi

Hello @Shravankumarkarnati could you please approve this fix?

maulep1 avatar Nov 28 '23 17:11 maulep1