#2141·dnd-kit

Feedback styles are added and removed on every drag, forcing a full-page style recalculation

Author: chasegiuntaCreated Sep 28, 2026Updated Sep 28, 2026

Summary

StyleInjector only injects registered rules while a drag operation is initializing or initialized — roots is empty when idle. So every drag start prepends the Feedback plugin's <style> to <head>, and every drop removes it.

Adding or removing a stylesheet invalidates styles for the whole document. The next layout read at drag start (PositionObserver's getBoundingClientRect, then Scroller's elementFromPoint) pays for a full, synchronous style recalculation.

Impact

On a large page (~2,800 elements, ~2,300 CSS rules), each stylesheet insertion or removal costs ~20–25 ms. In Chrome:

Current Feedback styles kept mounted
First frame after drag activation 58–61 ms ~20 ms
Forced style recalculations at drag start 2 × ~22 ms none

With a fast drag, the stall shows as the item jumping to the pointer once the frame lands. Measured with Long Animation Frames plus timing wrappers around getBoundingClientRect / elementFromPoint.

Related to #2110. #2126 removed a duplicate layout read in the Scroller; this is a separate source of the same jank.

Why the rules can't simply stay mounted

  • Cursor and PreventSelection register * { cursor: grabbing !important; } and * { user-select: none !important; } in their constructors and rely on StyleInjector only injecting while dragging. Keeping every rule mounted would apply them all the time.
  • Feedback's rules only match data-dnd-* attributes, so they have no effect between drags.
  • #registeredRules is a plain Set, so registering or unregistering rules does not re-run the sync effect. Rules are only picked up because roots changes at every drag start.

Proposal

  • StyleInjector.register(cssRules, {retain: true}) keeps inert rules injected in a root after its first drag, until they are unregistered or the plugin is destroyed. Feedback opts in; Cursor and PreventSelection stay drag-only.
  • Make registered rules reactive.
  • Sync styles by diffing, so a stylesheet that is still needed is never removed and added back.

I have a PR ready and will link it here.

Versions: @dnd-kit/dom 0.5.0, @dnd-kit/vue 0.5.0, Chrome 147.