fix(theme-common): finalize collapse state when transition duration is 0ms - #12353
fix(theme-common): finalize collapse state when transition duration is 0ms#12353himanshu-2l wants to merge 1 commit into
Conversation
|
Hi @himanshu-2l! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
✅ [V2]Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Motivation
Fixes #12043.
Collapsiblerelied solely on thetransitionendDOM event to finalize collapsed/expanded state (applyingdisplay: none, cleaning up inline styles, callingonCollapseTransitionEnd). When the CSS transition duration is0ms— whether from a user CSS override (as reported in #12043) or fromprefers-reduced-motion—transitionendnever fires in the browser, so the component gets stuck with stale inline styles.This also lets us remove the old
prefers-reduced-motion1mshack added in #8906, since the new fallback timer handles the zero-duration case generically instead of needing a magic non-zero value to force the event to fire.Change
packages/docusaurus-theme-common/src/components/Collapsible/index.tsx:getAutoHeightDurationnow returns0(not1) forprefers-reduced-motion, since it no longer needs to dodge thetransitionendbug.useCollapseAnimationnow schedules asetTimeoutfallback (matching the transition duration) alongside the existingtransitionendlistener. Whichever fires first finalizes the state via a sharedfinalize()callback; afinalizedRefguard prevents double-finalizing if both fire.CollapsibleBase'sonTransitionEndhandler now calls the same sharedfinalize()instead of duplicating the finalization logic inline.Test Plan
Added
packages/docusaurus-theme-common/src/components/Collapsible/__tests__/index.test.tsx:onCollapseTransitionEndfires via the fallback timer when the transition duration is0ms(reproduces Theme: can't set sidebar collapsible category transition totransition: 0mswith CSS #12043 — this test fails against the pre-fix code and passes against the fix).transitionendevent apply.Commands run locally, all passing: