mirror of
https://github.com/facebook/docusaurus.git
synced 2025-07-24 03:58:49 +02:00
fix(core): fix React hydration errors, change html minifier settings (#10786)
This commit is contained in:
parent
2565601af3
commit
f196a1eb29
4 changed files with 27 additions and 34 deletions
|
@ -15,7 +15,7 @@ import React, {
|
|||
type SetStateAction,
|
||||
type ReactNode,
|
||||
} from 'react';
|
||||
import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
|
||||
import useIsBrowser from '@docusaurus/useIsBrowser';
|
||||
import useIsomorphicLayoutEffect from '@docusaurus/useIsomorphicLayoutEffect';
|
||||
import {prefersReducedMotion} from '../../utils/accessibilityUtils';
|
||||
|
||||
|
@ -161,8 +161,15 @@ type CollapsibleElementType = React.ElementType<
|
|||
* Prevent hydration layout shift before animations are handled imperatively
|
||||
* with JS
|
||||
*/
|
||||
function getSSRStyle(collapsed: boolean) {
|
||||
if (ExecutionEnvironment.canUseDOM) {
|
||||
function getSSRStyle({
|
||||
collapsed,
|
||||
isBrowser,
|
||||
}: {
|
||||
collapsed: boolean;
|
||||
isBrowser: boolean;
|
||||
}) {
|
||||
// After hydration, styles are applied
|
||||
if (isBrowser) {
|
||||
return undefined;
|
||||
}
|
||||
return collapsed ? CollapsedStyles : ExpandedStyles;
|
||||
|
@ -202,6 +209,7 @@ function CollapsibleBase({
|
|||
className,
|
||||
disableSSRStyle,
|
||||
}: CollapsibleBaseProps) {
|
||||
const isBrowser = useIsBrowser();
|
||||
const collapsibleRef = useRef<HTMLElement>(null);
|
||||
|
||||
useCollapseAnimation({collapsibleRef, collapsed, animation});
|
||||
|
@ -211,7 +219,8 @@ 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
|
||||
style={disableSSRStyle ? undefined : getSSRStyle(collapsed)}
|
||||
// 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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue