Feedback styles are added and removed on every drag, forcing a full-page style recalculation
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
CursorandPreventSelectionregister* { cursor: grabbing !important; }and* { user-select: none !important; }in their constructors and rely onStyleInjectoronly injecting while dragging. Keeping every rule mounted would apply them all the time.Feedback's rules only matchdata-dnd-*attributes, so they have no effect between drags.#registeredRulesis a plainSet, so registering or unregistering rules does not re-run the sync effect. Rules are only picked up becauserootschanges 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.Feedbackopts in;CursorandPreventSelectionstay 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.
Source: clauderic/dnd-kit