perf(scroll-state): remove AnimationFrames loop#410
perf(scroll-state): remove AnimationFrames loop#410fvarano wants to merge 2 commits intosvecosystem:mainfrom
Conversation
…nObserver Remove continuous requestAnimationFrame loop that caused forced reflows by calling getComputedStyle() every frame. Replace with opt-in MutationObserver for dynamic content scenarios. - Remove AnimationFrames loop - Add observe option (default: false) for DOM change detection - Align with VueUse's useScroll pattern - Fixes performance bottleneck visible in Chrome DevTools profiler
Add documentation for the new observe option that enables MutationObserver for detecting DOM changes affecting scroll state.
|
FYI, it's most probably due to nodejs 25, had the same issue for runed/ contribution, tests failing on node25 using nodev24 resolved it, but as you said it's not important if you don't add tests |
This utility uses
requestAnimationFrameto continuously updatearrivedState, which has quite a big overhead.This PR removes continuous requestAnimationFrame loop that caused forced reflows by calling getComputedStyle() every frame. Replace with opt-in MutationObserver for dynamic content scenarios.
The original useScroll utility from Vue does not, instead it provides an optional
observeoption.These are (naive) profiles on the docs page of this utility, which are slightly skewed to the old version, since that one is on a production build, while the website hosted locally is not:
Before:

After:

Cannot run tests locally, at the moment, but this utility does not have specific tests.
Pull request checklist
pnpm lint,pnpm format)pnpm check)pnpm test)