Accessibility plugin does O(n²) DOM reads when many draggables mount

Open Beginner friendly
#2,187 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@dev-noman is already working on this.

Since Nov 16, 2026.

  • #2195 by @dev-noman — open

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
react, typescript

Research direction

Start with the effect and scheduled task in packages/dom/src/core/plugins/accessibility/Accessibility.ts; trace how registry.draggables.value and the scheduler behave as draggables register. Move the attribute reads into the scheduled task while keeping the signal reads that trigger updates, and check that isSafari() is computed once per plugin instance. Done means the DOM checks run once per frame over the latest draggable list and the written attributes remain unchanged.

Written by the indexing model from the issue text.

Description

Problem

The Accessibility plugin's effect (packages/dom/src/core/plugins/accessibility/Accessibility.ts) reads registry.draggables.value, so it re-runs every time a draggable registers. Each run loops over every draggable and, for each one, calls isFocusable(), isSafari() (a regex on navigator.userAgent) and 4 to 6 hasAttribute/getAttribute reads. Draggables register one at a time as they mount, so mounting n of them does those reads n times each: O(n²), all in the same commit.

Measured in Chrome on a production build of a kanban board (@dnd-kit/react 0.5.1, one useSortable per card; the cards are links, so isFocusable() is true and isSafari() runs for every one):

  • 120 cards: about 40 ms per mount in this effect, 31 ms of it in isSafari()
  • 250 cards: about 150 ms per mount, 119 ms of it in isSafari()

It shows on first load and on every remount of the list, for example when switching between two layouts of the same board. The code is unchanged on main.

Suggested fix

Keep reading the signals in the effect, so it still re-runs when handle, element, isDragging or disabled change, but only collect { activator, isDragging, disabled } there. Move the attribute checks into the task the effect already schedules with scheduler.schedule. The scheduler dedupes that task, so the DOM checks run once per frame over the latest list, however many draggables registered. isSafari() can be computed once per plugin instance.

With that change, the same 250-card mount spends about 1 ms in the plugin. The attributes written don't change, and the writes were already deferred to the scheduler.

Happy to open a PR.

Dominant language
TypeScript
Stars
17.8k
Forks
934
Avg merge
1d 4h
Merged PRs (30d)
7

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from clauderic/dnd-kit

All issues in clauderic/dnd-kit

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.