Skip to content

Commit 452799e

Browse files
vchaindzclaude
andcommitted
fix: Create dedicated React global setup module to resolve timing issues
- Add setup-react-global.ts module that imports React and sets global references - Import setup module first in main.tsx to ensure React availability before any other imports - Addresses persistent forwardRef errors by guaranteeing React.forwardRef exists when lucide-react loads - Eliminates module loading order dependency issues - Maintains proper ES module structure while providing early global compatibility 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 3d5c2df commit 452799e

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

public/data/database.jsonic

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

public/data/database.jsonic.gz

3 Bytes
Binary file not shown.

src/main.tsx

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
1-
import React, { StrictMode } from 'react';
2-
import * as ReactDOM from 'react-dom/client';
1+
// Import React global setup FIRST to prevent forwardRef errors
2+
import './setup-react-global';
3+
4+
import { StrictMode } from 'react';
5+
import { createRoot } from 'react-dom/client';
36

47
import './index.css';
58
import App from './App.tsx';
69

7-
// By importing React and ReactDOM here and attaching them to the window object,
8-
// we ensure they are available globally for libraries like lucide-react that
9-
// might rely on a global React instance. This is a more robust approach than
10-
// using an inline script in index.html, as it avoids potential issues with
11-
// module loading order and dependency duplication.
12-
(window as any).React = React;
13-
(window as any).ReactDOM = ReactDOM;
14-
15-
ReactDOM.createRoot(document.getElementById('root')!).render(
10+
createRoot(document.getElementById('root')!).render(
1611
<StrictMode>
1712
<App />
1813
</StrictMode>

src/setup-react-global.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import React from 'react';
2+
import * as ReactDOM from 'react-dom/client';
3+
4+
// Ensure React is available globally before any other modules load
5+
// This must be imported first to prevent forwardRef errors in lucide-react
6+
(window as any).React = React;
7+
(window as any).ReactDOM = ReactDOM;
8+
9+
// Also expose specific functions that libraries might access directly
10+
(window as any).forwardRef = React.forwardRef;
11+
(window as any).createElement = React.createElement;
12+
(window as any).createContext = React.createContext;
13+
14+
console.log('[Setup] React made globally available');

0 commit comments

Comments
 (0)