fix(studio): show inspector selection bounds after click reliably#789
Conversation
miguel-heygen
left a comment
There was a problem hiding this comment.
Clean fix for a subtle React rendering bug.
Root cause analysis: The click handler wrote overlayRectRef.current = candidateRect before calling setOverlayRect(candidateRect). Since setOverlayRect deduplicates via rectsEqual(overlayRectRef.current, next), the early ref write made the setter think nothing changed — setOverlayRectState was never called, no re-render happened, and the selection bounds didn't appear.
Fix is correct: removing the premature ref write in DomEditOverlay.tsx:226 lets setOverlayRect (inside useDomEditOverlayRects) be the single authority on both the ref and the React state — they stay in sync.
Gesture handler cleanup is also right: setDraftOverlayRect and setDraftGroupOverlayItems in the gesture handlers were doing redundant ref-then-equality checks that duplicate what useDomEditOverlayRects.setOverlayRect already does. Removing them simplifies the flow and prevents the same premature-ref-write pattern from causing issues during drag operations.
Test: the harness correctly mocks the overlay geometry to return a deterministic rect, renders a DomEditOverlay, dispatches a pointerdown, and asserts the selection box appears. The mock for useDomEditOverlayRects faithfully replicates the deduplication logic from the real hook.
Looks good to merge.
What
Fix Studio inspector bounds not showing right after click.
Why
Click could select the element, but the bounds still did not show.
This happened because the bounds ref was updated first. Then the React state update looked like "nothing changed", so the UI did not re-render.
How
Keep bounds updates going through the overlay setters.
Do not write to the bounds ref before calling the setter.
This keeps the ref and React state in sync, so the selected bounds render right after click.
Test plan
How was this tested?