Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: replace useLayoutEffect into useIsomorphicLayoutEffect for server side rendering #1044

Merged
merged 1 commit into from
Jan 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/components/ToastContainer.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import cx from 'clsx';
import React, { useLayoutEffect, useRef, useState } from 'react';
import React, { useRef, useState } from 'react';

import { toast } from '../core';
import { useToastContainer } from '../hooks/useToastContainer';
import { useIsomorphicLayoutEffect } from '../hooks/useIsomorphicLayoutEffect';
import { ToastContainerProps, ToastPosition } from '../types';
import { Default, Direction, isFn, parseClassName } from '../utils';
import { Toast } from './Toast';
@@ -56,7 +57,7 @@ export function ToastContainer(props: ToastContainerProps) {
}
}

useLayoutEffect(() => {
useIsomorphicLayoutEffect(() => {
if (stacked) {
const nodes = containerRef.current!.querySelectorAll('[data-in="true"]');
const gap = 12;
4 changes: 4 additions & 0 deletions src/hooks/useIsomorphicLayoutEffect.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { useEffect, useLayoutEffect } from 'react';

export const useIsomorphicLayoutEffect =
typeof window !== 'undefined' ? useLayoutEffect : useEffect;

Unchanged files with check annotations Beta

unbindFocusEvents();
};
}
}, [props.pauseOnFocusLoss]);

Check warning on line 44 in src/hooks/useToast.ts

GitHub Actions / build

React Hook useEffect has missing dependencies: 'bindFocusEvents' and 'unbindFocusEvents'. Either include them or remove the dependency array
function bindFocusEvents() {
if (!document.hasFocus()) pauseToast();
};
onEnter();
}, []);

Check warning on line 102 in src/utils/cssTransition.tsx

GitHub Actions / build

React Hook useLayoutEffect has missing dependencies: 'enterClassName', 'nodeRef', and 'playToast'. Either include them or remove the dependency array. If 'playToast' changes too often, find the parent component that defines it and wrap that definition in useCallback
useEffect(() => {
const node = nodeRef.current!;
};
if (!isIn) preventExitTransition ? onExited() : onExit();
}, [isIn]);

Check warning on line 119 in src/utils/cssTransition.tsx

GitHub Actions / build

React Hook useEffect has missing dependencies: 'done', 'exitClassName', 'nodeRef', and 'preventExitTransition'. Either include them or remove the dependency array. If 'done' changes too often, find the parent component that defines it and wrap that definition in useCallback
return <>{children}</>;
};