Skip to content

Conversation

@STRML
Copy link
Collaborator

@STRML STRML commented Dec 14, 2025

When items were removed from the layout and re-added (toolbox pattern), they would flicker infinitely between their correct size and default 1x1.

Root cause: The layout sync from props used useEffect which runs AFTER render. When props changed, GridLayout received stale layout state on the first render, creating items with default dimensions, triggering callbacks that updated props, causing an infinite loop.

Fix: Use useMemo to derive layout synchronously during render, ensuring GridLayout always receives correct layout on the same render cycle as children changes. Also use effectiveLayout in compactType effect to avoid stale data during concurrent changes.

Added regression test for the toolbox remove/re-add scenario.

Description

This PR [adds/removes/fixes/replaces] the [feature/bug/etc].

What type of PR is this? (check all applicable)

  • 🍕 Feature
  • 🐛 Bug Fix
  • 📝 Documentation Update
  • 🎨 Style
  • 🧑‍💻 Code Refactor
  • 🔥 Performance Improvements
  • ✅ Test
  • 🤖 Build
  • 🔁 CI
  • 📦 Chore (Release)
  • ⏩ Revert

Related Tickets & Documents

Mobile & Desktop Screenshots/Recordings

Added tests?

  • 👍 yes
  • 🙅 no, because they aren't needed
  • 🙋 no, because I need help

Added to documentation?

  • 📜 README.md
  • 📓 examples
  • 🙅 no documentation needed

@github-actions github-actions bot added the tests use this label for changes in tests label Dec 14, 2025
When items were removed from the layout and re-added (toolbox pattern),
they would flicker infinitely between their correct size and default 1x1.

Root cause: The layout sync from props used useEffect which runs AFTER
render. When props changed, GridLayout received stale layout state on
the first render, creating items with default dimensions, triggering
callbacks that updated props, causing an infinite loop.

Fix: Use useMemo to derive layout synchronously during render, ensuring
GridLayout always receives correct layout on the same render cycle as
children changes. Also use effectiveLayout in compactType effect to
avoid stale data during concurrent changes.

Added regression tests for the toolbox remove/re-add scenario and
StrictMode double-render compatibility.
@STRML STRML merged commit 7810a73 into master Dec 14, 2025
4 checks passed
@STRML STRML deleted the fix/toolbox-bug branch December 14, 2025 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests use this label for changes in tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants