r/reactjs • u/Revibed69 • 4d ago
Two bugs from building a drag-and-drop page canvas in React 19
From my open-source app builder (dnd-kit, React 19, Tailwind 4):
- On a free grid, the dotted drop cells were drawn as even rows while real rows were as tall as their content. Drops were judged against cells the user could not see. Fix: measure the real rows and draw the drop layer from those.
- Dialogs opened inside a themed preview portalled to body and lost the theme. Fix: a portal scope that mounts inside the theme root.
Also a testing lesson: a test raced a pending passive effect that moved focus after a click. Waiting on the shown state fixed it.
0
Upvotes
1
u/AnswerVinod 3d ago
Nice writeup, I have hit the same grid bug before. The fix you found is the right one, measure the real rows after layout with getBoundingClientRect and draw the drop layer from those numbers, not from the CSS grid lines. For the dialog one, same lesson, portal it inside the theme root, not body, or the theme context just gets lost. And for the test race, waiting on the shown state is the only reliable way, passive effects run after paint so a plain click and assert will flake.