Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: useDrawerBody() forces style recalculations #33655

Open
2 tasks done
spmonahan opened this issue Jan 15, 2025 · 0 comments
Open
2 tasks done

[Bug]: useDrawerBody() forces style recalculations #33655

spmonahan opened this issue Jan 15, 2025 · 0 comments

Comments

@spmonahan
Copy link
Contributor

Component

Drawer

Package version

9.57.0

React version

18.3.1

Environment

n/a

Current Behavior

When children are updated Drawer forces a style recalculation.

This seems to be because getScrollState reads values that force layout.

Perhaps this is because there are two calls (1, 2) that will eventually call getScrollState(). Maybe they need to be in a rAF like the onScroll call?

Edge DevTools profile showing the forced layout

I realize the 1.49ms might not sound like much but this also forces a layout calculation for another 1.73ms meaning we're doing 3.22ms of work that should be handled elsewhere. We're aiming for a 60fps refresh rate in an application (that is 16.67ms for all work in a frame, not just JS) and have observed forced style recalc + layout calc from useDrawerBody taking 5-10ms in some cases.

Expected Behavior

Updates to Drawer should not force style recalculations.

Reproduction

https://stackblitz.com/edit/tkwxyl8r?file=src%2Fexample.tsx

Steps to reproduce

  1. Load repro case
  2. Open DevTools
  3. Click on Performance tab. Start recording a profile
  4. Click the "Add child to Drawer" button several times.
  5. Stop profile recording.
  6. Examine profile.

Here's how to find the forced style recalc

Image

Are you reporting an Accessibility issue?

no

Suggested severity

High - No workaround

Products/sites affected

No response

Are you willing to submit a PR to fix?

yes

Validations

  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • The provided reproduction is a minimal reproducible example of the bug.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants