Accessibility plugin does O(n²) DOM reads when many draggables mount
Maintainers usually reply within 1 day
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
- Domain
- frontend, performance
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
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from clauderic/dnd-kit
-
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
Accessibilty plugin statuses are always in `document.body`Possibly taken @dev-noman claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
clauderic/dnd-kit#2185 · 1 comment ·
Maintainers usually reply within 1 day
-
Declare @types/react as an optional peer dependencyPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
DndContext does not detach the active sensor when it unmounts mid-dragPossibly taken A pull request linked to this issue is open or already merged. Open
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
clauderic/dnd-kit#2179 · 1 comment ·
Maintainers usually reply within 1 day
-
bug experimental react triage:done
Difficulty 1/5 Under an hour Newbie friendliness 65/100
clauderic/dnd-kit#1654 · 5 comments ·
Maintainers usually reply within 1 day
All issues in clauderic/dnd-kit
Similar issues
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 92/100
lingdojo/kana-dojo#34449 · 1 comment · 5 reactions ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
drizzle-team/drizzle-orm#6726 ·
Maintainers usually reply within 2 days
-
bug platform-desktop platform-windows
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Termix-SSH/Termix#1951 · 2 comments ·
Maintainers usually reply within 1 day
-
Grok provider voice list shows 5 of xAI's 28 built-in voicesPossibly taken @hkjarral claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
hkjarral/AVA-AI-Voice-Agent-for-Asterisk#883 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100