Repository navigation
Stop the sidebar section drag from looping into React #185 - #1858
Conversation
The section-thread drag re-projected the dragged row into the hovered list on every dnd-kit over change. The projection changes the sidebar's scroll geometry, dnd-kit re-resolves over synchronously against the source list, the row is un-projected, and the cycle repeats until React aborts the nested update loop. Gate projection changes to one per target per user input and disable scroll anchoring on the sidebar scroller while a sidebar drag is active. Fixes #1830 Co-Authored-By: Claude <[email protected]>
|
🚨 SLOP COP 🚨 · I am the SlopCop. I started the review for PR #1858. I will check security, code quality, performance, architecture, and the sidebar drag behavior. |
| stopProjectionInputTrackingRef.current?.(); | ||
| stopProjectionInputTrackingRef.current = null; | ||
| }, []); | ||
| const startProjectionInputTracking = useCallback(() => { |
There was a problem hiding this comment.
🚨 slopcop/review — Stop input tracking when drag support becomes disabled
startProjectionInputTracking() installs four document listeners. Current cleanup depends on drag end, drag cancel, or unmount.
If enabled becomes false during a drag, handleDragOver() returns early. The listeners can remain until this hook unmounts.
Please consider an effect that stops input tracking when enabled changes to false. A focused test would protect this case.
This is a low-risk cleanup note. It does not block merge.
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
Plain English summary: This PR stops a sidebar drag from moving one thread between sections until React crashes.
It tracks real user input and disables scroll correction during each drag.
I found one low-severity cleanup issue. Four document listeners can remain if drag support becomes disabled before drag completion.
I left an inline note for that case. This issue does not block merge.
I found no security or performance issue. I also found no duplicate code that needs a shared abstraction.
Validation passed:
- Five focused test files passed with 48 tests.
- The
@bb/appTurbo type check passed. git diff --checkpassed.- Chromium completed three held edge drags and one cross-section drop.
- Chromium reported no React update-depth error and no page error.
- The final section state was correct.
- The worktree remained clean.
Review outcome: Comment only. The low-severity cleanup issue should not block merge.
What was wrong
The crash in #1830 is a feedback loop in the sidebar section-thread drag (
useSectionThreadDnd, the multi-container sorter inProjectRow), not a defect in dnd-kit'suseRect.handleDragOverre-projects the dragged row into whatever list dnd-kit reports asover. That projection re-renders the row into another list, so its droppable re-registers and dnd-kit re-measures every container in the same commit chain. When the sidebar is scrolled and the row is projected into a section above the viewport, the browser's scroll anchoring movesscrollTopto keep the visible rows still, but dnd-kit offsets its measured rects by that scroll delta even though nothing moved on screen.overthen resolves to the source list under a pointer that never moved, the row is un-projected,overflips again, and each hop is a layout-effect or synchronously flushed passive-effect update. React counts them as nested updates and aborts with error #185; the thrower is whicheversetStateruns 51st, which is why the packaged stack lands on dnd-kit'ssetRect.Reproduced on this branch with a headless Chromium script: manual sidebar mode, a 520px-tall viewport so the sidebar scrolls, scroll to the bottom, drag a section thread to the bottom edge and then to the top edge, hold. Every attempt logged
Maximum update depth exceededand[bb] the app crashed; the per-overlog shows the projection flipping Alpha → Beta → Alpha withscrollTopalternating 172 ↔ 203 and the raw pointer fixed at y=160. The same script no longer crashes with this fix (3/3 runs), and reverting the fix crashes again.What changed
apps/app/src/components/sidebar/useSectionThreadDnd.ts:SectionThreadProjectionGateallows each projection target at most once per user input (pointer move, touch move, wheel, key press). A revert that arrives without new input is our own render feeding back and is dropped. The hook tracks input with capture listeners ondocumentfrom drag start until end, cancel, or unmount.apps/app/src/app.css:overflow-anchor: noneon the sidebar scroller whilebody[data-sidebar-dragging="true"], so a projection cannot movescrollTopand desynchronize dnd-kit's rects from the pointer. Either change alone stops the reproduced crash; the gate is the general guard against the feedback loop, the CSS removes the geometry trigger.How you verified
useSectionThreadDnd.projection.test.tsx: renders the hook, drags a thread over section B, then reportsoveron the source section with no input. Fails before (expected null to be 'chronological::b'), passes after. Also covers that unvisited targets stay allowed, that input reopens targets, that listeners are removed on cancel/unmount, and the gate itself.pnpm exec turbo run typecheck --filter=@bb/appandpnpm exec turbo run test --filter=@bb/app(360 files, 2862 tests) pass.mainand does not crash with the fix; a normal drag from Alpha into Beta still projects and drops (threadsectionIdupdated).Fixes #1830