Skip to content

Commit 0710efa

Browse files
committed
test6
1 parent 607ae33 commit 0710efa

File tree

4 files changed

+47
-11
lines changed

4 files changed

+47
-11
lines changed

src/layouts/components/Header.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import React, { useState } from 'react';
33
import { useEntries } from '../../features/statements/hooks/useEntries';
44
import { Dialog, DialogTrigger } from '../../components/ui/dialog';
55
import SmallCircularQuestionCounter from '../../components/ui/questionCounter/smallCircularQuestionCounter';
6-
// import UserDataModal from '../../components/modals/UserDataModal';
6+
import UserDataModal from '../../components/modals/UserDataModal';
77

88
const Header: React.FC = () => {
99
const { data } = useEntries();
@@ -39,9 +39,9 @@ const Header: React.FC = () => {
3939
<SmallCircularQuestionCounter size={18} />
4040
</button>
4141
</DialogTrigger>
42-
{/* <UserDataModal
42+
<UserDataModal
4343
onOpenChange={setIsDashboardOpen}
44-
/> */}
44+
/>
4545
</Dialog>
4646
) : (
4747
<div className='flex shrink-0 items-center border-2 border-white rounded-full px-2 py-1 sm:px-4 sm:py-2 cursor-default'>
@@ -71,7 +71,7 @@ const Header: React.FC = () => {
7171
<SmallCircularQuestionCounter size={18} />
7272
</button>
7373
</DialogTrigger>
74-
{/* <UserDataModal onOpenChange={setIsDashboardOpen} /> */}
74+
<UserDataModal onOpenChange={setIsDashboardOpen} />
7575
</Dialog>
7676
) : (
7777
<div className='flex shrink-0 items-center border-2 border-white rounded-full px-2 py-1 sm:px-4 sm:py-2 cursor-default'>

src/lib/utils/react-polyfill.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* React polyfill to handle useLayoutEffect issues in server-side rendering
3+
* This fixes the "Cannot read properties of undefined (reading 'useLayoutEffect')" error
4+
*/
5+
6+
// This is a side-effect module that makes sure React.useLayoutEffect is available
7+
// in environments where it might not be (like SSR or certain build environments)
8+
if (typeof window !== 'undefined') {
9+
// We're in the browser, so we can safely create a React object on window
10+
// This ensures that libraries that expect to find React on window won't break
11+
// @ts-ignore - intentionally modifying window
12+
window.React = window.React || {};
13+
// @ts-ignore - intentionally modifying window.React
14+
window.React.useLayoutEffect = window.React.useLayoutEffect || function() { return function() {}; };
15+
}
16+
17+
// Export a dummy function to make TypeScript happy when importing this module
18+
export default function ensureReactPolyfill() {
19+
// This function does nothing, it just ensures the side effects above are executed
20+
return true;
21+
}

src/main.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
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-
}
1+
// Import the polyfill first, before any other imports
2+
import './lib/utils/react-polyfill';
63

74
import { StrictMode } from 'react';
85
import { createRoot } from 'react-dom/client';

vite.config.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,26 @@ import { defineConfig } from 'vite';
22
import react from '@vitejs/plugin-react';
33
import path from 'path';
44

5+
// This ensures the polyfill is always included early in the bundle
6+
const polyfillPlugin = {
7+
name: 'react-polyfill',
8+
enforce: 'pre' as const,
9+
transform(code: string, id: string) {
10+
// Only add to entry point
11+
if (id.includes('main.tsx')) {
12+
// Make sure the polyfill import is at the top
13+
const hasPolyfill = code.includes("import './lib/utils/react-polyfill'");
14+
if (!hasPolyfill) {
15+
return `import './lib/utils/react-polyfill';\n${code}`;
16+
}
17+
}
18+
return code;
19+
}
20+
};
21+
522
export default defineConfig({
623
base: '/',
7-
plugins: [react()],
24+
plugins: [polyfillPlugin, react()],
825
resolve: {
926
alias: {
1027
'@': path.resolve(__dirname, './src'),
@@ -24,7 +41,8 @@ export default defineConfig({
2441
// Split React and related packages into a separate chunk
2542
if (id.includes('react') ||
2643
id.includes('scheduler') ||
27-
id.includes('prop-types')) {
44+
id.includes('prop-types') ||
45+
id.includes('src/lib/utils/react-polyfill')) {
2846
return 'vendor-react';
2947
}
3048

0 commit comments

Comments
 (0)