Skip to content

Commit 383e1f6

Browse files
committed
fix: replace useLayoutEffect to isomoprhic version
1 parent 0a39e81 commit 383e1f6

File tree

11 files changed

+29
-15
lines changed

11 files changed

+29
-15
lines changed

src/components/Breadcrumbs/Breadcrumbs.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import * as React from 'react';
44

5+
import {useLayoutEffect} from 'src/hooks/private';
6+
57
import {useForkRef, useResizeObserver} from '../../hooks';
68
import type {PopupPlacement} from '../Popup';
79
import type {AriaLabelingProps, DOMProps, Key, QAProps} from '../types';
@@ -131,15 +133,15 @@ export const Breadcrumbs = React.forwardRef(function Breadcrumbs(
131133
});
132134

133135
const lastChildren = React.useRef<typeof props.children | null>(null);
134-
React.useLayoutEffect(() => {
136+
useLayoutEffect(() => {
135137
if (calculated && props.children !== lastChildren.current) {
136138
lastChildren.current = props.children;
137139
setVisibleItemsCount(items.length);
138140
setCalculated(false);
139141
}
140142
}, [calculated, items.length, props.children]);
141143

142-
React.useLayoutEffect(() => {
144+
useLayoutEffect(() => {
143145
if (!calculated) {
144146
recalculate(visibleItemsCount);
145147
}

src/components/TreeSelect/TreeSelect.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import * as React from 'react';
44

5+
import {useLayoutEffect} from 'src/hooks/private';
6+
57
import {useFocusWithin, useForkRef, useUniqId} from '../../hooks';
68
import {useOpenState} from '../../hooks/useSelect/useOpenState';
79
import {SelectControl} from '../Select/components';
@@ -147,7 +149,7 @@ export const TreeSelect = React.forwardRef(function TreeSelect<T, P extends {} =
147149
}, [onItemClick, list, multiple, toggleOpen]);
148150

149151
// restoring focus when popup opens
150-
React.useLayoutEffect(() => {
152+
useLayoutEffect(() => {
151153
if (open) {
152154
// for some reason popup position on page may be wrong calculated. `preventScroll` prevent page gap in that cases
153155
containerRef.current?.focus({preventScroll: true});

src/components/lab/Virtualizer/useLoadMore.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as React from 'react';
22

3+
import {useLayoutEffect} from 'src/hooks/private';
4+
35
export interface Loadable {
46
/** Whether the items are currently loading. */
57
loading?: boolean;
@@ -11,7 +13,6 @@ export interface LoadMoreOptions extends Loadable {
1113
/**
1214
* The amount of offset from bottom that should trigger load more.
1315
* The value is multiplied to the size of the visible area.
14-
*
1516
* @default 1
1617
*/
1718
scrollOffset?: number;
@@ -50,7 +51,7 @@ export function useLoadMore(
5051
}, [scrollContainerRef, onLoadMore, scrollOffset]);
5152

5253
const prevLoadingPropRef = React.useRef(loading);
53-
React.useLayoutEffect(() => {
54+
useLayoutEffect(() => {
5455
if (loading !== prevLoadingPropRef.current) {
5556
isLoadingRef.current = loading;
5657
prevLoadingPropRef.current = loading;

src/components/layout/hooks/useCurrentActiveMediaQuery.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as React from 'react';
22

3+
import {useLayoutEffect} from 'src/hooks/private';
4+
35
import type {MediaProps, MediaType} from '../types';
46

57
export const mockMediaQueryList: MediaQueryList = {
@@ -88,7 +90,7 @@ export const useCurrentActiveMediaQuery = (
8890
initialMediaQuery ?? (fixBreakpoints ? 'xs' : 's'),
8991
);
9092

91-
React.useLayoutEffect(() => {
93+
useLayoutEffect(() => {
9294
const queries = new Queries(breakpointsMap, fixBreakpoints);
9395

9496
const setState = () => {

src/components/theme/ThemeProvider.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import * as React from 'react';
44

5-
import {useIsomorphicLayoutEffect} from '../../hooks/private';
5+
import {useLayoutEffect} from '../../hooks/private';
66
import {PrivateLayoutProvider} from '../layout/LayoutProvider/LayoutProvider';
77
import type {PrivateLayoutProviderProps} from '../layout/LayoutProvider/LayoutProvider';
88
import {block} from '../utils/cn';
@@ -67,7 +67,7 @@ export function ThemeProvider({
6767

6868
const prevRootClassName = React.useRef('');
6969

70-
useIsomorphicLayoutEffect(() => {
70+
useLayoutEffect(() => {
7171
if (!scoped) {
7272
updateBodyClassName({
7373
theme: themeValue,

src/components/useList/hooks/useListKeydown.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as React from 'react';
22

3+
import {useLayoutEffect} from 'src/hooks/private';
4+
35
import {KeyCode} from '../../../constants';
46
import type {ListOnItemClick, UseListResult} from '../types';
57
import {findNextIndex} from '../utils/findNextIndex';
@@ -58,7 +60,7 @@ export const useListKeydown = ({containerRef, onItemClick, enabled, list}: UseLi
5860
],
5961
);
6062

61-
React.useLayoutEffect(() => {
63+
useLayoutEffect(() => {
6264
const anchor = containerRef?.current;
6365

6466
if (enabled || !anchor) {

src/hooks/private/useCheckbox/useCheckbox.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as React from 'react';
22

3+
import {useLayoutEffect} from 'src/hooks/private';
4+
35
import {useControlledState, useForkRef} from '../..';
46
import type {ControlProps} from '../../../components/types';
57
import {eventBroker} from '../../../components/utils/event-broker';
@@ -41,7 +43,7 @@ export function useCheckbox({
4143

4244
const handleRef = useForkRef(controlRef, innerControlRef, fieldRef);
4345

44-
React.useLayoutEffect(() => {
46+
useLayoutEffect(() => {
4547
if (innerControlRef.current) {
4648
innerControlRef.current.indeterminate = Boolean(indeterminate);
4749
}

src/hooks/private/useElementSize/useElementSize.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import * as React from 'react';
33
import round from 'lodash/round';
44
import throttle from 'lodash/throttle';
55

6+
import {useLayoutEffect} from 'src/hooks/private';
7+
68
const RESIZE_THROTTLE = 16;
79
const ROUND_PRECISION = 2;
810

@@ -23,7 +25,7 @@ export function useElementSize<T extends HTMLElement = HTMLDivElement>(
2325
height: 0,
2426
});
2527

26-
React.useLayoutEffect(() => {
28+
useLayoutEffect(() => {
2729
const element = ref?.current;
2830
if (!element) {
2931
return undefined;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export {useIsomorphicLayoutEffect} from './useIsomorphicLayoutEffect';
1+
export {useLayoutEffect} from './useIsomorphicLayoutEffect';
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
import * as React from 'react';
22

3-
export const useIsomorphicLayoutEffect =
4-
typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
3+
export const useLayoutEffect = typeof window === 'undefined' ? () => {} : React.useLayoutEffect;

0 commit comments

Comments
 (0)