Skip to content

fix(theme-common): handle zero-duration collapsible transition#12077

Open
DEEP13-2-5 wants to merge 1 commit into
facebook:mainfrom
DEEP13-2-5:fix/zero-duration-collapsible-transition
Open

fix(theme-common): handle zero-duration collapsible transition#12077
DEEP13-2-5 wants to merge 1 commit into
facebook:mainfrom
DEEP13-2-5:fix/zero-duration-collapsible-transition

Conversation

@DEEP13-2-5
Copy link
Copy Markdown

@DEEP13-2-5 DEEP13-2-5 commented May 28, 2026

Summary

Fixes #12063.

This updates the shared Collapsible component to handle zero-duration height transitions. In browsers such as Firefox, transitionend may not fire for 0ms transitions, so the component can remain stuck with temporary height/overflow animation styles.

The fix detects when the computed height transition duration is zero and runs the existing cleanup path synchronously instead of waiting for transitionend.

Details

The check is scoped to height and all transition properties, so unrelated zero-duration transitions such as opacity 0ms do not bypass normal height transition behavior.

A shared completion callback is used for both the native transitionend path and the zero-duration fallback, with a guard to avoid duplicate cleanup.

Tests

Added regression coverage for:

  • zero-duration height transitions completing without transitionend
  • normal nonzero height transitions still waiting for transitionend
  • multi-property transitions where another property has 0ms but height does not

Validation

yarn test packages/docusaurus-theme-common/src/components/Collapsible/__tests__/index.test.tsx
yarn lint:js --quiet packages/docusaurus-theme-common/src/components/Collapsible/index.tsx packages/docusaurus-theme-common/src/components/Collapsible/__tests__/index.test.tsx
yarn workspace @docusaurus/theme-common build
git diff --check

AI-assisted: Parts of the implementation were developed with Claude Code.
Root cause analysis and proposed fix by @AkshatRaj00 in #12063. I implemented the fix based on his diagnosis and added regression tests,
and verified the fix with tests and manual reproduction.

Copilot AI review requested due to automatic review settings May 28, 2026 08:01
@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented May 28, 2026

Hi @DEEP13-2-5!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@netlify
Copy link
Copy Markdown

netlify Bot commented May 28, 2026

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit 20c679d
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/6a18546457ee450008ce077a
😎 Deploy Preview https://deploy-preview-12077--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR updates the Collapsible component to avoid waiting for a transitionend event when the computed height transition duration is zero, and adds Vitest coverage for those cases.

Changes:

  • Add runtime detection for “zero-duration height transitions” and invoke the collapse/expand completion callback immediately.
  • Refactor transition-end handling to be idempotent via a ref-backed callback.
  • Add Vitest tests covering zero-duration vs non-zero-duration height transitions and multi-property transitions.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
packages/docusaurus-theme-common/src/components/Collapsible/index.tsx Adds computed-style detection for zero-duration height transitions and refactors transition-end completion logic.
packages/docusaurus-theme-common/src/components/Collapsible/tests/index.test.tsx Adds tests to validate immediate completion for zero-duration height transitions and proper waiting otherwise.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/docusaurus-theme-common/src/components/Collapsible/index.tsx Outdated
Comment thread packages/docusaurus-theme-common/src/components/Collapsible/index.tsx Outdated
@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented May 28, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the CLA Signed Signed Facebook CLA label May 28, 2026
@DEEP13-2-5 DEEP13-2-5 force-pushed the fix/zero-duration-collapsible-transition branch from 2e00cf5 to 20c679d Compare May 28, 2026 14:42
@DEEP13-2-5 DEEP13-2-5 requested a review from Copilot May 30, 2026 05:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

Comment on lines +69 to +91
function willNotTransitionHeight(el: HTMLElement) {
const style = getComputedStyle(el);
const transitionProperties = style.transitionProperty.split(',');
const transitionDurations = style.transitionDuration.split(',');

if (!style.transitionDuration || transitionDurations.length === 0) {
return true;
}

const willTransition = transitionProperties.some((property, index) => {
const propName = property.trim();
if (propName === 'height' || propName === 'all') {
const duration = transitionDurations[index % transitionDurations.length];
if (duration !== undefined) {
const parsedDuration = parseFloat(duration);
return !isNaN(parsedDuration) && parsedDuration > 0;
}
}
return false;
});

return !willTransition;
}
Comment on lines 161 to 167
requestAnimationFrame(() => {
el.style.height = CollapsedStyles.height;
el.style.overflow = CollapsedStyles.overflow;
if (willNotTransitionHeight(el)) {
onCollapseTransitionEnd.current?.();
}
});
Comment on lines +223 to +233
useEffect(() => {
transitionFinished.current = false;
collapseTransitionEnd.current = () => {
if (transitionFinished.current) {
return;
}
transitionFinished.current = true;
applyCollapsedStyle(collapsibleRef.current!, collapsed);
onCollapseTransitionEnd?.(collapsed);
};
}, [collapsed, onCollapseTransitionEnd]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed Signed Facebook CLA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: transition: 0ms on sidebar ul causes category content overlap (height animation race condition)

3 participants