Skip to content

Commit dbd5d05

Browse files
committed
add react-scan on dev
1 parent dedee27 commit dbd5d05

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

app/root.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@ export const links: Route.LinksFunction = () => [
2525
]
2626

2727
export function Layout({ children }: { children: React.ReactNode }) {
28+
const useReactScan = import.meta?.env?.DEV || false
29+
2830
return (
2931
<html lang="en" suppressHydrationWarning>
3032
<head>
3133
<meta charSet="utf-8" />
3234
<meta name="viewport" content="width=device-width, initial-scale=1" />
3335
<script dangerouslySetInnerHTML={{ __html: themeDetectJs }} />
36+
{useReactScan && <script crossOrigin="anonymous" src="//unpkg.com/react-scan/dist/auto.global.js" />}
3437
<Meta />
3538
<Links />
3639
</head>

registry/basil-ui/lib/theme-detect.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
//
33
// This script detects the user's preferred color scheme and updates the theme accordingly.
44
//
5-
// Example usage (in React Router root.tsx):
6-
//
7-
// import themeDetectJs from '@/lib/theme-detect.js?raw'
8-
// // in the Layout component add this in the head, before other scripts to avoid UI flashing:
9-
// <script dangerouslySetInnerHTML={{ __html: themeDetectJs }} />
5+
// Example usage (in React Router app/root.tsx, or Next.js app/layout.tsx):
6+
// - Import the script as raw text: `import themeDetectJs from '@/lib/theme-detect.js?raw'`
7+
// - In the Layout component add `<script dangerouslySetInnerHTML={{ __html: themeDetectJs }} />` in the head
8+
// before stylesheets and other scripts to avoid UI flashing
9+
// - In the Layout component add `suppressHydrationWarning` to the html tag to avoid hydration errors
1010
//
1111
function getPreferredColorScheme() {
1212
if (window.matchMedia('(prefers-color-scheme: dark)').matches) {

0 commit comments

Comments
 (0)