Skip to content

Commit 607ae33

Browse files
committed
test 5
1 parent 4a337e1 commit 607ae33

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

src/lib/utils/ssr-hooks.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { useEffect, useLayoutEffect } from 'react';
2+
3+
/**
4+
* A version of useLayoutEffect that works in both browser and SSR environments
5+
* This prevents errors like "Cannot read properties of undefined (reading 'useLayoutEffect')"
6+
*/
7+
export const useIsomorphicLayoutEffect =
8+
typeof window !== 'undefined' ? useLayoutEffect : useEffect;

src/main.tsx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
// Apply React useLayoutEffect polyfill
2+
if (typeof window !== 'undefined') {
3+
window.React = window.React || {};
4+
window.React.useLayoutEffect = window.React.useEffect || function() { return function() {}; };
5+
}
6+
17
import { StrictMode } from 'react';
28
import { createRoot } from 'react-dom/client';
39
import './index.css';

src/vite-env.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,8 @@
11
/// <reference types="vite/client" />
2+
3+
interface Window {
4+
React?: {
5+
useLayoutEffect?: Function;
6+
useEffect?: Function;
7+
};
8+
}

0 commit comments

Comments
 (0)