Skip to content

Commit 5cd2f21

Browse files
committed
test 4
1 parent 73d42e2 commit 5cd2f21

File tree

10 files changed

+25
-14
lines changed

10 files changed

+25
-14
lines changed

index.html

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
66
<title>Beacons</title>
7-
<!-- Prevent "useLayoutEffect does nothing on the server" warning -->
7+
<!-- Fix for React hooks in server environments -->
88
<script>
9-
// Polyfill useLayoutEffect for environments that don't support it (like Deno Deploy)
10-
if (typeof window !== 'undefined') {
11-
window.React = window.React || {};
12-
window.React.useLayoutEffect = window.React.useEffect || function() { return function() {}; };
13-
}
9+
// This needs to run before React is loaded, so React will use these implementations
10+
window.__REACT_WORKAROUND__ = true;
11+
window.requestAnimationFrame = function(cb) { setTimeout(cb, 0); };
1412
</script>
1513
</head>
1614
<body>

src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import React, { useEffect } from 'react';
3+
import React, { useEffect } from './lib/utils/react-safe';
44
import { TooltipProvider } from '@radix-ui/react-tooltip';
55

66
// Providers

src/components/ui/button.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import * as React from '../../lib/utils/react-safe';
22
import { Slot } from '@radix-ui/react-slot';
33
import type { VariantProps } from 'class-variance-authority';
44

src/components/ui/dialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import * as React from 'react';
3+
import * as React from '../../lib/utils/react-safe';
44
import * as DialogPrimitive from '@radix-ui/react-dialog';
55
import { X } from 'lucide-react';
66
import { cn } from '@/lib/utils';

src/components/ui/dropdown-menu.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import * as React from 'react';
1+
import * as React from '../../lib/utils/react-safe';
22
import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
33
import { cn } from '@/lib/utils';
44

src/components/ui/label.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import * as React from 'react';
3+
import * as React from '../../lib/utils/react-safe';
44
import * as LabelPrimitive from '@radix-ui/react-label';
55
import { cva, type VariantProps } from 'class-variance-authority';
66

src/components/ui/popover.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import * as React from 'react';
3+
import * as React from '../../lib/utils/react-safe';
44
import * as PopoverPrimitive from '@radix-ui/react-popover';
55

66
import { cn } from '@/lib/utils';

src/components/ui/tooltip.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import * as React from 'react';
3+
import * as React from '../../lib/utils/react-safe';
44
import * as TooltipPrimitive from '@radix-ui/react-tooltip';
55

66
import { cn } from '@/lib/utils';

src/lib/utils/react-safe.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* This file provides safe React hooks that work in both client and server environments.
3+
* Import these hooks instead of directly importing from React when SSR compatibility is needed.
4+
*/
5+
import React, { useEffect, useLayoutEffect } from 'react';
6+
7+
// Use a safe version of useLayoutEffect that falls back to useEffect in non-browser environments
8+
export const useIsomorphicLayoutEffect =
9+
typeof window !== 'undefined' ? useLayoutEffect : useEffect;
10+
11+
// Re-export React to ensure consistent usage
12+
export default React;
13+
export * from 'react';

src/main.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { StrictMode } from 'react';
1+
import { StrictMode } from './lib/utils/react-safe';
22
import { createRoot } from 'react-dom/client';
33
import './index.css';
44
import App from './App'; // Now your App component is the top-level one

0 commit comments

Comments
 (0)