Repository navigation
[drawer] Avoid retaining unmounted drawers in DrawerProvider - #5921
Merged
Merged
Conversation
commit: |
Bundle size
PerformanceTotal duration: 478.37 ms -104.84 ms(-18.0%) | Renders: 76 (+0) | Paint: 871.03 ms -177.93 ms(-17.0%)
…and 3 more (+7 within noise) — details Check out the code infra dashboard for more information about this PR. |
✅ Deploy Preview for base-ui ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
atomiks
marked this pull request as ready for review
October 8, 2026 02:12
atomiks
requested review from
colmtuite,
flaviendelangle,
jjenzz and
michaldudak
as code owners
October 8, 2026 02:12
michaldudak
approved these changes
Oct 8, 2026
flaviendelangle
approved these changes
Oct 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #5915
Thanks to @bryantgillespie for the detailed report and patch.
This PR stops
Drawer.Providerfrom retaining closed drawers after they unmount. EachDrawer.RootreportssetDrawerOpen(store, false)on mount andremoveDrawer(store)on unmount. For a drawer that never opened, the functional updater returnedprev. React skips the render in that case, but still keeps the update and its closure over the drawer store on the provider's hook queue until the provider next renders. This happens in React 17, 18 and 19. The provider only renders when the open set changes, so every closed drawer that mounted and unmounted stayed reachable, along with its elements and callbacks, until some drawer opened or closed.Changes
Setheld in a ref. A call that doesn't change membership returns early without callingsetState.activeboolean, which is all the context ever exposed.setActive(boolean)passes no closure, so even a skipped update can't hold a drawer. It's also only called whenactiveactually flips.Profiler-based retention test, which also passed on the leaking code, with a jsdom test that forces GC (throughprocess.getBuiltinModule('node:v8'), no CLI flag) and asserts removed drawers are collected.Performance
In a jsdom probe, a routed child under a provider that never re-renders mounts and unmounts 21 closed drawers, then checks with
WeakRef+ forced GC whether their stores were collected:Drawer.Provider