Skip to content

Stop the sidebar section drag from looping into React #185 - #1858

Merged
SawyerHood merged 1 commit into
mainfrom
bb/fix-1830-dnd-kit-react-185-crash-loop-thr_zfbyi6mdy5
Aug 19, 2026
Merged

SawyerHood merged 1 commit into
mainfrom
bb/fix-1830-dnd-kit-react-185-crash-loop-thr_zfbyi6mdy5

Conversation

@SawyerHood

Copy link
Copy Markdown
Collaborator

What was wrong

The crash in #1830 is a feedback loop in the sidebar section-thread drag (useSectionThreadDnd, the multi-container sorter in ProjectRow), not a defect in dnd-kit's useRect. handleDragOver re-projects the dragged row into whatever list dnd-kit reports as over. 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 moves scrollTop to keep the visible rows still, but dnd-kit offsets its measured rects by that scroll delta even though nothing moved on screen. over then resolves to the source list under a pointer that never moved, the row is un-projected, over flips 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 whichever setState runs 51st, which is why the packaged stack lands on dnd-kit's setRect.

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 exceeded and [bb] the app crashed; the per-over log shows the projection flipping Alpha → Beta → Alpha with scrollTop alternating 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: SectionThreadProjectionGate allows 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 on document from drag start until end, cancel, or unmount.
  • apps/app/src/app.css: overflow-anchor: none on the sidebar scroller while body[data-sidebar-dragging="true"], so a projection cannot move scrollTop and 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.
  • No wire or CLI changes.

How you verified

  • New useSectionThreadDnd.projection.test.tsx: renders the hook, drags a thread over section B, then reports over on 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/app and pnpm exec turbo run test --filter=@bb/app (360 files, 2862 tests) pass.
  • Manual: headless Chromium repro above crashes on main and does not crash with the fix; a normal drag from Alpha into Beta still projects and drops (thread sectionId updated).

Fixes #1830

AGENT GENERATED: by Claude Opus 5

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]>
@bb-slop-cop

bb-slop-cop Bot commented Aug 19, 2026 •

Copy link
Copy Markdown
Contributor

🚨 SLOP COP 🚨 · review

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(() => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 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.

@bb-slop-cop bb-slop-cop Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 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/app Turbo type check passed.
  • git diff --check passed.
  • 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.

@SawyerHood
SawyerHood merged commit 88abdac into main Aug 19, 2026
12 checks passed
@SawyerHood
SawyerHood deleted the bb/fix-1830-dnd-kit-react-185-crash-loop-thr_zfbyi6mdy5 branch August 19, 2026 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dnd-kit active-node measurement can enter a React #185 loop and crash the app during drag

1 participant