Skip to content

Commit

Permalink
remove useless CollapsedStyles getSSRStyle thing
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Jan 31, 2025
1 parent 00633c2 commit 99bfb97
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import React, {
type SetStateAction,
type ReactNode,
} from 'react';
import useIsBrowser from '@docusaurus/useIsBrowser';
import useIsomorphicLayoutEffect from '@docusaurus/useIsomorphicLayoutEffect';
import {prefersReducedMotion} from '../../utils/accessibilityUtils';

Expand Down Expand Up @@ -119,7 +118,7 @@ function useCollapseAnimation({

// On mount, we just apply styles, no animated transition
if (!mounted.current) {
applyCollapsedStyle(el, collapsed);
queueMicrotask(() => applyCollapsedStyle(el, collapsed));
mounted.current = true;
return undefined;
}
Expand Down Expand Up @@ -157,24 +156,6 @@ type CollapsibleElementType = React.ElementType<
Pick<React.HTMLAttributes<unknown>, 'className' | 'onTransitionEnd' | 'style'>
>;

/**
* Prevent hydration layout shift before animations are handled imperatively
* with JS
*/
function getSSRStyle({
collapsed,
isBrowser,
}: {
collapsed: boolean;
isBrowser: boolean;
}) {
// After hydration, styles are applied
if (isBrowser) {
return undefined;
}
return collapsed ? CollapsedStyles : ExpandedStyles;
}

type CollapsibleBaseProps = {
/** The actual DOM element to be used in the markup. */
as?: CollapsibleElementType;
Expand All @@ -192,12 +173,6 @@ type CollapsibleBaseProps = {
onCollapseTransitionEnd?: (collapsed: boolean) => void;
/** Class name for the underlying DOM element. */
className?: string;
/**
* This is mostly useful for details/summary component where ssrStyle is not
* needed (as details are hidden natively) and can mess up with the browser's
* native behavior when JS fails to load or is disabled
*/
disableSSRStyle?: boolean;
};

function CollapsibleBase({
Expand All @@ -207,9 +182,7 @@ function CollapsibleBase({
animation,
onCollapseTransitionEnd,
className,
disableSSRStyle,
}: CollapsibleBaseProps) {
const isBrowser = useIsBrowser();
const collapsibleRef = useRef<HTMLElement>(null);

useCollapseAnimation({collapsibleRef, collapsed, animation});
Expand All @@ -219,8 +192,6 @@ function CollapsibleBase({
// @ts-expect-error: the "too complicated type" is produced from
// "CollapsibleElementType" being a huge union
ref={collapsibleRef as RefObject<never>} // Refs are contravariant, which is not expressible in TS
// Not even sure we need this SSRStyle anymore, try to remove it?
style={disableSSRStyle ? undefined : getSSRStyle({collapsed, isBrowser})}
onTransitionEnd={(e: React.TransitionEvent) => {
if (e.propertyName !== 'height') {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ export function Details({
<Collapsible
lazy={false} // Content might matter for SEO in this case
collapsed={collapsed}
disableSSRStyle // Allows component to work fine even with JS disabled!
onCollapseTransitionEnd={(newCollapsed) => {
setCollapsed(newCollapsed);
setOpen(!newCollapsed);
Expand Down

0 comments on commit 99bfb97

Please sign in to comment.