Skip to content

Commit 99bfb97

Browse files
committed
remove useless CollapsedStyles getSSRStyle thing
1 parent 00633c2 commit 99bfb97

File tree

2 files changed

+1
-31
lines changed

2 files changed

+1
-31
lines changed

packages/docusaurus-theme-common/src/components/Collapsible/index.tsx

+1-30
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import React, {
1515
type SetStateAction,
1616
type ReactNode,
1717
} from 'react';
18-
import useIsBrowser from '@docusaurus/useIsBrowser';
1918
import useIsomorphicLayoutEffect from '@docusaurus/useIsomorphicLayoutEffect';
2019
import {prefersReducedMotion} from '../../utils/accessibilityUtils';
2120

@@ -119,7 +118,7 @@ function useCollapseAnimation({
119118

120119
// On mount, we just apply styles, no animated transition
121120
if (!mounted.current) {
122-
applyCollapsedStyle(el, collapsed);
121+
queueMicrotask(() => applyCollapsedStyle(el, collapsed));
123122
mounted.current = true;
124123
return undefined;
125124
}
@@ -157,24 +156,6 @@ type CollapsibleElementType = React.ElementType<
157156
Pick<React.HTMLAttributes<unknown>, 'className' | 'onTransitionEnd' | 'style'>
158157
>;
159158

160-
/**
161-
* Prevent hydration layout shift before animations are handled imperatively
162-
* with JS
163-
*/
164-
function getSSRStyle({
165-
collapsed,
166-
isBrowser,
167-
}: {
168-
collapsed: boolean;
169-
isBrowser: boolean;
170-
}) {
171-
// After hydration, styles are applied
172-
if (isBrowser) {
173-
return undefined;
174-
}
175-
return collapsed ? CollapsedStyles : ExpandedStyles;
176-
}
177-
178159
type CollapsibleBaseProps = {
179160
/** The actual DOM element to be used in the markup. */
180161
as?: CollapsibleElementType;
@@ -192,12 +173,6 @@ type CollapsibleBaseProps = {
192173
onCollapseTransitionEnd?: (collapsed: boolean) => void;
193174
/** Class name for the underlying DOM element. */
194175
className?: string;
195-
/**
196-
* This is mostly useful for details/summary component where ssrStyle is not
197-
* needed (as details are hidden natively) and can mess up with the browser's
198-
* native behavior when JS fails to load or is disabled
199-
*/
200-
disableSSRStyle?: boolean;
201176
};
202177

203178
function CollapsibleBase({
@@ -207,9 +182,7 @@ function CollapsibleBase({
207182
animation,
208183
onCollapseTransitionEnd,
209184
className,
210-
disableSSRStyle,
211185
}: CollapsibleBaseProps) {
212-
const isBrowser = useIsBrowser();
213186
const collapsibleRef = useRef<HTMLElement>(null);
214187

215188
useCollapseAnimation({collapsibleRef, collapsed, animation});
@@ -219,8 +192,6 @@ function CollapsibleBase({
219192
// @ts-expect-error: the "too complicated type" is produced from
220193
// "CollapsibleElementType" being a huge union
221194
ref={collapsibleRef as RefObject<never>} // Refs are contravariant, which is not expressible in TS
222-
// Not even sure we need this SSRStyle anymore, try to remove it?
223-
style={disableSSRStyle ? undefined : getSSRStyle({collapsed, isBrowser})}
224195
onTransitionEnd={(e: React.TransitionEvent) => {
225196
if (e.propertyName !== 'height') {
226197
return;

packages/docusaurus-theme-common/src/components/Details/index.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ export function Details({
109109
<Collapsible
110110
lazy={false} // Content might matter for SEO in this case
111111
collapsed={collapsed}
112-
disableSSRStyle // Allows component to work fine even with JS disabled!
113112
onCollapseTransitionEnd={(newCollapsed) => {
114113
setCollapsed(newCollapsed);
115114
setOpen(!newCollapsed);

0 commit comments

Comments
 (0)