Skip to content

fix(theme-common): handle disabled collapsible transitions#12053

Draft
rohan-patnaik wants to merge 1 commit into
facebook:mainfrom
rohan-patnaik:fix-collapsible-zero-transition
Draft

fix(theme-common): handle disabled collapsible transitions#12053
rohan-patnaik wants to merge 1 commit into
facebook:mainfrom
rohan-patnaik:fix-collapsible-zero-transition

Conversation

@rohan-patnaik
Copy link
Copy Markdown
Contributor

@rohan-patnaik rohan-patnaik commented May 22, 2026

Fixes #12043

Summary

This makes the shared Collapsible component finish its expand/collapse cleanup when the computed transition duration is 0ms.

Why

Before this change, Collapsible waited for a height transition event before applying its final styles. If site CSS forced transition: 0ms !important, that event did not fire, so expanded sidebar categories could keep temporary height/overflow styles and visually overlap later items.

Test plan

  • nvm use 26 && yarn oxfmt --list-different packages/docusaurus-theme-common/src/components/Collapsible/index.tsx
  • nvm use 26 && yarn eslint --cache --report-unused-disable-directives packages/docusaurus-theme-common/src/components/Collapsible/index.tsx
  • git diff --check

@meta-cla meta-cla Bot added the CLA Signed Signed Facebook CLA label May 22, 2026
@netlify
Copy link
Copy Markdown

netlify Bot commented May 22, 2026

[V2]

Built without sensitive environment variables

Name Link
🔨 Latest commit d5370aa
🔍 Latest deploy log https://app.netlify.com/projects/docusaurus-2/deploys/6a100f8ca7f65b0008793498
😎 Deploy Preview https://deploy-preview-12053--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.

@rohan-patnaik rohan-patnaik marked this pull request as ready for review May 22, 2026 08:35
Copy link
Copy Markdown
Collaborator

@slorber slorber left a comment

Choose a reason for hiding this comment

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

This overly complexify the code for what we attempt to do.

I'd rather find a simpler solution, one that doesn't add complexity and one that doesn't require reading computed styles.

This may mean we offer a more convenient way to achieve the initial use-case

See also my comment here: #12043 (comment)

el.style.height = collapsedStyles.height;
}

function parseTransitionTime(time: string) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

not fan of this

Comment on lines +116 to +120
const onCollapseTransitionEndRef = useRef(onCollapseTransitionEnd);

useEffect(() => {
onCollapseTransitionEndRef.current = onCollapseTransitionEnd;
}, [onCollapseTransitionEnd]);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

not fan of this

Comment on lines +141 to +151
function finishAnimation() {
applyCollapsedStyle(el, collapsed);
onCollapseTransitionEndRef.current?.(collapsed);
}

function finishAnimationIfTransitionDisabled() {
const {transitionDuration} = getComputedStyle(el);
if (parseTransitionTime(transitionDuration) === 0) {
finishAnimation();
}
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

not fan of this

@slorber slorber marked this pull request as draft May 22, 2026 15:55
@rohan-patnaik
Copy link
Copy Markdown
Contributor Author

rohan-patnaik commented May 22, 2026

Thanks for the review. I agree the current approach adds more complexity than this use case probably deserves, especially around reading computed styles.

I’ll hold off on adding more code until the preferred direction is clear. I see two simpler options:

  1. Rely on the existing prefers-reduced-motion behavior and not support forcing sidebar transitions to 0ms globally.
  2. Or to add a small supported override for this component, so sites can intentionally disable this transition without depending on computed-style detection.

Do you prefer one of those directions, or is there another simpler approach you’d rather see?

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.

Theme: can't set sidebar collapsible category transition to transition: 0ms with CSS

2 participants