Skip to content

Commit 26daddd

Browse files
committed
fix hydration issues
1 parent 09f02ee commit 26daddd

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// When reused, move to base pkg
2+
import { isFirefox as isFirefoxFn } from '@ui5/webcomponents-react-base/Device';
3+
import { useEffect, useState } from 'react';
4+
5+
/**
6+
* SSR ready `isFirefox` check.
7+
*/
8+
export function useIsFirefox() {
9+
const [isFirefox, setIsFirefox] = useState(false);
10+
11+
useEffect(() => {
12+
setIsFirefox(isFirefoxFn());
13+
}, []);
14+
15+
return isFirefox;
16+
}

packages/main/src/components/AnalyticalTable/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import {
1010
useStylesheet,
1111
useSyncRef,
1212
} from '@ui5/webcomponents-react-base';
13-
import { isFirefox as isFirefoxFn } from '@ui5/webcomponents-react-base/Device';
1413
import { clsx } from 'clsx';
1514
import type { CSSProperties, MutableRefObject } from 'react';
1615
import { forwardRef, useCallback, useEffect, useId, useMemo, useRef } from 'react';
@@ -65,6 +64,7 @@ import { useColumnsDeps } from './hooks/useColumnsDeps.js';
6564
import { useColumnDragAndDrop } from './hooks/useDragAndDrop.js';
6665
import { useDynamicColumnWidths } from './hooks/useDynamicColumnWidths.js';
6766
import { useFontsReady } from './hooks/useFontsReady.js';
67+
import { useIsFirefox } from './hooks/useIsFirefox.js';
6868
import { useKeyboardNavigation } from './hooks/useKeyboardNavigation.js';
6969
import { usePopIn } from './hooks/usePopIn.js';
7070
import { useResizeColumnsConfig } from './hooks/useResizeColumnsConfig.js';
@@ -191,7 +191,7 @@ const AnalyticalTable = forwardRef<AnalyticalTableDomRef, AnalyticalTablePropTyp
191191
useStylesheet(styleData, AnalyticalTable.displayName);
192192
const isInitialized = useRef(false);
193193
const fontsReady = useFontsReady();
194-
const isFirefox = useMemo(() => isFirefoxFn(), []);
194+
const isFirefox = useIsFirefox();
195195

196196
const alwaysShowSubComponent =
197197
subComponentsBehavior === AnalyticalTableSubComponentsBehavior.Visible ||

packages/main/src/components/AnalyticalTable/scrollbars/VerticalScrollbar.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { isChrome as isChromeFn } from '@ui5/webcomponents-react-base/Device';
22
import { useSyncRef } from '@ui5/webcomponents-react-base/internal/hooks';
33
import { clsx } from 'clsx';
44
import type { MutableRefObject } from 'react';
5-
import { forwardRef, useEffect, useMemo, useRef } from 'react';
5+
import { forwardRef, useEffect, useRef } from 'react';
66
import { FlexBoxDirection } from '../../../enums/FlexBoxDirection.js';
77
import { FlexBox } from '../../FlexBox/index.js';
88
import type { ClassNames } from '../types/index.js';
@@ -15,13 +15,14 @@ interface VerticalScrollbarProps {
1515
classNames: ClassNames;
1616
}
1717

18+
const isChrome = isChromeFn();
19+
1820
export const VerticalScrollbar = forwardRef<HTMLDivElement, VerticalScrollbarProps>((props, ref) => {
1921
const { internalRowHeight, tableRef, tableBodyHeight, scrollContainerRef, classNames } = props;
2022
const hasHorizontalScrollbar = tableRef?.current?.offsetWidth !== tableRef?.current?.scrollWidth;
2123
const horizontalScrollbarSectionStyles = clsx(hasHorizontalScrollbar && classNames.bottomSection);
2224
const [componentRef, scrollbarRef] = useSyncRef<HTMLDivElement>(ref);
2325
const contentRef = useRef<HTMLDivElement>(null);
24-
const isChrome = useMemo(() => isChromeFn(), []);
2526

2627
// Force style recalculation to fix Chrome scrollbar-color bug (track height not updating correctly)
2728
useEffect(() => {
@@ -42,7 +43,7 @@ export const VerticalScrollbar = forwardRef<HTMLDivElement, VerticalScrollbarPro
4243

4344
requestAnimationFrame(forceScrollbarUpdate);
4445
}
45-
}, [tableBodyHeight, scrollContainerRef.current?.scrollHeight, scrollbarRef, isChrome]);
46+
}, [tableBodyHeight, scrollContainerRef.current?.scrollHeight, scrollbarRef]);
4647

4748
return (
4849
<FlexBox

0 commit comments

Comments
 (0)