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]: Performance issues with popper content and body scroll lock #1497

Open
stafyniaksacha opened this issue Dec 16, 2024 · 0 comments
Open
Labels
bug Something isn't working v2

Comments

@stafyniaksacha
Copy link

Environment

Client OS: Windows 11
Browser: Chrome 131

Link to minimal reproduction

https://reka-ui.com/docs/components/dropdown-menu

Steps to reproduce

  1. Go to https://reka-ui.com/docs/components/dropdown-menu
  2. Open Chrome Devtools
  3. Go to performance tab
  4. Enable CPU throttling to x4
  5. Test to open / close the dropdown (it may take seconds to apply effect)

Describe the bug

Opening and closing the dropdown menu component has latency when using a device with slow CPU (or in power saving mode).

We can see two bottlenecks when the dropdown open:
image

  • 1st Recalculate Style: getBoundingClientRect force a reflow:
    // update position automatically when `boundingClientRect` changes
    const throttleUpdate = useThrottleFn(update, 10, true, true)
    watchEffect(() => {
    if (reference.value?.getBoundingClientRect()) {
    throttleUpdate()
    }
    })
  • 2nd Recalculate Style: getComputedStyle also force a reflow:
    const contentZIndex = ref('')
    watchEffect(() => {
    if (contentElement.value)
    contentZIndex.value = window.getComputedStyle(contentElement.value).zIndex
    })

Maybe it's because they are called after styles (overflow, pointer-events, margin and padding on body) has been applied, forcing browser to reflow

Here is the performance trace recorded: https://trace.cafe/t/On8azGJwtH

Expected behavior

Other implementations like melt-ui and shadcn-ui seem to perform better even with higher CPU throttling

Context & Screenshots (if applicable)

No response

@stafyniaksacha stafyniaksacha added the bug Something isn't working label Dec 16, 2024
@zernonia zernonia added the v2 label Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v2
Projects
None yet
Development

No branches or pull requests

2 participants