chore: import upstream snapshot with attribution
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
# Astro Guide
|
||||
|
||||
## As a script tag
|
||||
|
||||
Add the script tag to your root layout.
|
||||
|
||||
Refer to the [CDN Guide](https://github.com/aidenybai/react-scan/blob/main/docs/installation/cdn.md) for the available URLs.
|
||||
|
||||
```astro
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<script is:inline src="https://unpkg.com/react-scan/dist/auto.global.js" />
|
||||
|
||||
<!-- rest of your scripts go under -->
|
||||
</head>
|
||||
<body>
|
||||
<!-- ... -->
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
## As a module import
|
||||
|
||||
Add the script to your root layout
|
||||
|
||||
```astro
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<script>
|
||||
import { scan } from 'react-scan';
|
||||
|
||||
scan({
|
||||
enabled: true,
|
||||
});
|
||||
</script>
|
||||
<!-- rest of your scripts go under -->
|
||||
</head>
|
||||
<body>
|
||||
<!-- ... -->
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
If you want react-scan to also run in production, use the react-scan/all-environments import path
|
||||
```diff
|
||||
- import { scan } from "react-scan";
|
||||
+ import { scan } from "react-scan/all-environments";
|
||||
```
|
||||
@@ -0,0 +1,23 @@
|
||||
# CDN
|
||||
|
||||
You can choose one of the following URLs to initialize React Scan via CDN.
|
||||
|
||||
## Usage
|
||||
|
||||
```html
|
||||
<script src="https://cdn.jsdelivr.net/npm/react-scan/dist/auto.global.js"></script>
|
||||
```
|
||||
|
||||
## Available URLs
|
||||
|
||||
### JSDelivr
|
||||
|
||||
```txt
|
||||
https://cdn.jsdelivr.net/npm/react-scan/dist/auto.global.js
|
||||
```
|
||||
|
||||
### UNPKG
|
||||
|
||||
```txt
|
||||
https://unpkg.com/react-scan/dist/auto.global.js
|
||||
```
|
||||
@@ -0,0 +1,45 @@
|
||||
# Create React App (CRA) Guide
|
||||
|
||||
## As a script tag
|
||||
|
||||
Add the script tag to your `index.html`.
|
||||
|
||||
Refer to the [CDN Guide](https://github.com/aidenybai/react-scan/blob/main/docs/installation/cdn.md) for the available URLs.
|
||||
|
||||
```html
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<script src="https://unpkg.com/react-scan/dist/auto.global.js"></script>
|
||||
|
||||
<!-- rest of your scripts go under -->
|
||||
</head>
|
||||
<body>
|
||||
<!-- ... -->
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
## As a module import
|
||||
|
||||
In your project entrypoint (e.g. `src/index`, `src/main`):
|
||||
|
||||
```jsx
|
||||
// src/index.jsx
|
||||
|
||||
// must be imported before React and React DOM
|
||||
import { scan } from "react-scan";
|
||||
import React from "react";
|
||||
|
||||
scan({
|
||||
enabled: true,
|
||||
});
|
||||
```
|
||||
If you want react-scan to also run in production, use the react-scan/all-environments import path
|
||||
```diff
|
||||
- import { scan } from "react-scan";
|
||||
+ import { scan } from "react-scan/all-environments";
|
||||
```
|
||||
|
||||
> [!CAUTION]
|
||||
> React Scan must be imported before React (and other React renderers like React DOM) in your entire project, as it needs to hijack React DevTools before React gets to access it.
|
||||
@@ -0,0 +1,71 @@
|
||||
# NextJS App Router Guide
|
||||
|
||||
## As a script tag
|
||||
|
||||
Add the script tag to your `app/layout`.
|
||||
|
||||
Refer to the [CDN Guide](https://github.com/aidenybai/react-scan/blob/main/docs/installation/cdn.md) for the available URLs.
|
||||
|
||||
```jsx
|
||||
// app/layout
|
||||
export default function RootLayout({ children }) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<head>
|
||||
<script src="https://unpkg.com/react-scan/dist/auto.global.js" />
|
||||
{/* rest of your scripts go under */}
|
||||
</head>
|
||||
<body>{children}</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
## As a module import
|
||||
|
||||
Create a `<ReactScan>` client component:
|
||||
|
||||
```jsx
|
||||
// path/to/ReactScanComponent
|
||||
|
||||
"use client";
|
||||
// react-scan must be imported before react
|
||||
import { scan } from "react-scan";
|
||||
import { JSX, useEffect } from "react";
|
||||
|
||||
export function ReactScan(): JSX.Element {
|
||||
useEffect(() => {
|
||||
scan({
|
||||
enabled: true,
|
||||
});
|
||||
}, []);
|
||||
|
||||
return <></>;
|
||||
}
|
||||
```
|
||||
|
||||
Import the `<ReactScan>` component into `app/layout`:
|
||||
|
||||
```jsx
|
||||
// app/layout
|
||||
|
||||
// This component must be the top-most import in this file!
|
||||
import { ReactScan } from "path/to/ReactScanComponent";
|
||||
|
||||
// ...
|
||||
|
||||
export default function RootLayout({ children }) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<ReactScan />
|
||||
<body>{children}</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
If you want react-scan to also run in production, use the react-scan/all-environments import path
|
||||
```diff
|
||||
- import { scan } from "react-scan";
|
||||
+ import { scan } from "react-scan/all-environments";
|
||||
```
|
||||
@@ -0,0 +1,57 @@
|
||||
# NextJS Page Router Guide
|
||||
|
||||
## As a script tag
|
||||
|
||||
Add the script tag to your `pages/_document`
|
||||
|
||||
Refer to the [CDN Guide](https://github.com/aidenybai/react-scan/blob/main/docs/installation/cdn.md) for the available URLs.
|
||||
|
||||
```jsx
|
||||
// pages/_document
|
||||
import { Html, Head, Main, NextScript } from "next/document";
|
||||
|
||||
export default function Document() {
|
||||
return (
|
||||
<Html lang="en">
|
||||
<Head>
|
||||
<script src="https://unpkg.com/react-scan/dist/auto.global.js" />
|
||||
|
||||
{/* rest of your scripts go under */}
|
||||
</Head>
|
||||
<body>
|
||||
<Main />
|
||||
<NextScript />
|
||||
</body>
|
||||
</Html>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
## As a module import
|
||||
|
||||
Add the following code to your `App` component in `pages/_app`:
|
||||
|
||||
```jsx
|
||||
// pages/_app
|
||||
|
||||
// react-scan must be the top-most import
|
||||
import { scan } from "react-scan";
|
||||
import { useEffect } from "react";
|
||||
|
||||
export default function App({ Component, pageProps }) {
|
||||
useEffect(() => {
|
||||
// Make sure to run React Scan after hydration
|
||||
scan({
|
||||
enabled: true,
|
||||
});
|
||||
}, []);
|
||||
return <Component {...pageProps} />;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
If you want react-scan to also run in production, use the react-scan/all-environments import path
|
||||
```diff
|
||||
- import { scan } from "react-scan";
|
||||
+ import { scan } from "react-scan/all-environments";
|
||||
```
|
||||
@@ -0,0 +1,21 @@
|
||||
# Parcel Guide
|
||||
|
||||
## As a script tag
|
||||
|
||||
Add the script tag to your `index.html`
|
||||
|
||||
Refer to the [CDN Guide](https://github.com/aidenybai/react-scan/blob/main/docs/installation/cdn.md) for the available URLs.
|
||||
|
||||
```html
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<script src="https://unpkg.com/react-scan/dist/auto.global.js"></script>
|
||||
|
||||
<!-- rest of your scripts go under -->
|
||||
</head>
|
||||
<body>
|
||||
<!-- ... -->
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
@@ -0,0 +1,83 @@
|
||||
# React Router v7 Guide
|
||||
|
||||
## As a script tag
|
||||
|
||||
Add the script tag to your `Layout` component in the `app/root`.
|
||||
|
||||
Refer to the [CDN Guide](https://github.com/aidenybai/react-scan/blob/main/docs/installation/cdn.md) for the available URLs.
|
||||
|
||||
```jsx
|
||||
// app/root
|
||||
// ...
|
||||
export function Layout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<head>
|
||||
<script src="https://unpkg.com/react-scan/dist/auto.global.js" />
|
||||
<meta charSet="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<Meta />
|
||||
<Links />
|
||||
</head>
|
||||
<body>
|
||||
{children}
|
||||
<ScrollRestoration />
|
||||
<Scripts />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
// ...
|
||||
```
|
||||
|
||||
> [!CAUTION]
|
||||
> This only works for React 19
|
||||
|
||||
## As an import
|
||||
|
||||
Add the following code to your `app/root`
|
||||
|
||||
```jsx
|
||||
// app/root
|
||||
|
||||
// Must be imported before React Router
|
||||
import { scan } from "react-scan";
|
||||
import { Links, Meta, Scripts, ScrollRestoration } from "react-router";
|
||||
import { useEffect } from "react";
|
||||
|
||||
export function Layout({ children }) {
|
||||
useEffect(() => {
|
||||
// Make sure to run react-scan only after hydration
|
||||
scan({
|
||||
enabled: true,
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charSet="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<Meta />
|
||||
<Links />
|
||||
</head>
|
||||
<body>
|
||||
{children}
|
||||
<ScrollRestoration />
|
||||
<Scripts />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
||||
// ...
|
||||
```
|
||||
|
||||
If you want react-scan to also run in production, use the react-scan/all-environments import path
|
||||
```diff
|
||||
- import { scan } from "react-scan";
|
||||
+ import { scan } from "react-scan/all-environments";
|
||||
```
|
||||
|
||||
> [!CAUTION]
|
||||
> React Scan must be imported before React (and other React renderers like React DOM), as well as React Router, in your entire project, as it needs to hijack React DevTools before React gets to access it.
|
||||
@@ -0,0 +1,123 @@
|
||||
# Remix Guide
|
||||
|
||||
## As a script tag
|
||||
|
||||
Add the script tag to your `<Layout>` component in `app/root`.
|
||||
|
||||
Refer to the [CDN Guide](https://github.com/aidenybai/react-scan/blob/main/docs/installation/cdn.md) for the available URLs.
|
||||
|
||||
```jsx
|
||||
// app/root.jsx
|
||||
import {
|
||||
Links,
|
||||
Meta,
|
||||
Scripts,
|
||||
ScrollRestoration,
|
||||
} from "@remix-run/react";
|
||||
|
||||
export function Layout({ children }: { children: React.ReactNode }) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<head>
|
||||
{/* Must run before any of your scripts */}
|
||||
<script src="https://unpkg.com/react-scan/dist/auto.global.js" />
|
||||
<meta charSet="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<Meta />
|
||||
<Links />
|
||||
</head>
|
||||
<body>
|
||||
{children}
|
||||
<ScrollRestoration />
|
||||
<Scripts />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
||||
// ...
|
||||
```
|
||||
|
||||
> [!CAUTION]
|
||||
> This only works for React 19
|
||||
|
||||
## As a module import
|
||||
|
||||
Add the following code to your `app/root`:
|
||||
|
||||
```jsx
|
||||
// app/root.jsx
|
||||
import { scan } from "react-scan"; // Must be imported before Remix
|
||||
import {
|
||||
Links,
|
||||
Meta,
|
||||
Outlet,
|
||||
Scripts,
|
||||
ScrollRestoration,
|
||||
} from "@remix-run/react";
|
||||
|
||||
export function Layout({ children }) {
|
||||
useEffect(() => {
|
||||
// Make sure to run React Scan after hydration
|
||||
scan({
|
||||
enabled: true,
|
||||
});
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charSet="utf-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||
<Meta />
|
||||
<Links />
|
||||
</head>
|
||||
<body>
|
||||
{children}
|
||||
<ScrollRestoration />
|
||||
<Scripts />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
||||
export default function App() {
|
||||
return <Outlet />;
|
||||
}
|
||||
```
|
||||
|
||||
If you want react-scan to also run in production, use the react-scan/all-environments import path
|
||||
```diff
|
||||
- import { scan } from "react-scan";
|
||||
+ import { scan } from "react-scan/all-environments";
|
||||
```
|
||||
|
||||
> [!CAUTION]
|
||||
> React Scan must be imported before React (and other React renderers like React DOM), as well as Remix, in your entire project, as it needs to hijack React DevTools before React gets to access it.
|
||||
|
||||
Alternatively you can also do the following code in `app/entry.client`:
|
||||
|
||||
```jsx
|
||||
// app/entry.client.jsx
|
||||
import { RemixBrowser } from "@remix-run/react";
|
||||
import { StrictMode, startTransition } from "react";
|
||||
import { hydrateRoot } from "react-dom/client";
|
||||
import { scan } from "react-scan";
|
||||
|
||||
scan({
|
||||
enabled: true,
|
||||
});
|
||||
|
||||
// Hydration must happen in sync!
|
||||
// startTransition(() => {
|
||||
hydrateRoot(
|
||||
document,
|
||||
<StrictMode>
|
||||
<RemixBrowser />
|
||||
</StrictMode>
|
||||
);
|
||||
// });
|
||||
```
|
||||
|
||||
> [!CAUTION]
|
||||
> This only works for React 19
|
||||
@@ -0,0 +1,65 @@
|
||||
# Rsbuild Guide
|
||||
|
||||
## As a script tag
|
||||
|
||||
If you are using Rsbuild's default HTML template, add the script tag via [html.tags](https://rsbuild.dev/config/html/tags).
|
||||
|
||||
Refer to the [CDN Guide](https://github.com/aidenybai/react-scan/blob/main/docs/installation/cdn.md) for the available URLs.
|
||||
|
||||
```ts
|
||||
// rsbuild.config.ts
|
||||
export default {
|
||||
html: {
|
||||
tags: [
|
||||
{
|
||||
tag: "script",
|
||||
attrs: {
|
||||
src: "https://cdn.jsdelivr.net/npm/react-scan/dist/auto.global.js",
|
||||
},
|
||||
append: false,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
```
|
||||
|
||||
If you are using a custom HTML template, add the script tag to your template file.
|
||||
|
||||
```html
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<script src="https://cdn.jsdelivr.net/npm/react-scan/dist/auto.global.js"></script>
|
||||
|
||||
<!-- rest of your scripts go under -->
|
||||
</head>
|
||||
<body>
|
||||
<!-- ... -->
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
## As a module import
|
||||
|
||||
In your project entrypoint (e.g. `src/index`, `src/main`):
|
||||
|
||||
```jsx
|
||||
// src/index.jsx
|
||||
|
||||
// must be imported before React and React DOM
|
||||
import { scan } from "react-scan";
|
||||
import React from "react";
|
||||
|
||||
scan({
|
||||
enabled: true,
|
||||
});
|
||||
```
|
||||
|
||||
If you want react-scan to also run in production, use the react-scan/all-environments import path
|
||||
```diff
|
||||
- import { scan } from "react-scan";
|
||||
+ import { scan } from "react-scan/all-environments";
|
||||
```
|
||||
|
||||
> [!CAUTION]
|
||||
> React Scan must be imported before React (and other React renderers like React DOM) in your entire project, as it needs to hijack React DevTools before React gets to access it.
|
||||
@@ -0,0 +1,99 @@
|
||||
# TanStack Router Guide
|
||||
|
||||
## As a script tag
|
||||
|
||||
Add the script tag to your `<RootDocument>` component at `app/routes/__root`.
|
||||
|
||||
Refer to the [CDN Guide](https://github.com/aidenybai/react-scan/blob/main/docs/installation/cdn.md) for the available URLs.
|
||||
|
||||
```jsx
|
||||
// app/routes/__root
|
||||
import { Meta, Scripts } from "@tanstack/start";
|
||||
// ...
|
||||
|
||||
function RootDocument({ children }) {
|
||||
return (
|
||||
<html>
|
||||
<head>
|
||||
<script src="https://unpkg.com/react-scan/dist/auto.global.js" />
|
||||
<Meta />
|
||||
</head>
|
||||
<body>
|
||||
{children}
|
||||
<Scripts />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
|
||||
// ...
|
||||
```
|
||||
|
||||
> [!CAUTION]
|
||||
> This only works for React 19
|
||||
|
||||
## As a module import
|
||||
|
||||
Add the following code to your `<RootDocument>` component at `app/routes/__root`:
|
||||
|
||||
```jsx
|
||||
// app/routes/__root
|
||||
|
||||
// react-scan must be imported before React and TanStack Start
|
||||
import { scan } from "react-scan";
|
||||
import { Meta, Scripts } from "@tanstack/start";
|
||||
import { useEffect } from "react";
|
||||
|
||||
// ...
|
||||
|
||||
function RootDocument({ children }) {
|
||||
useEffect(() => {
|
||||
// Make sure to run this only after hydration
|
||||
scan({
|
||||
enabled: true,
|
||||
});
|
||||
}, []);
|
||||
return (
|
||||
<html>
|
||||
<head>
|
||||
<Meta />
|
||||
</head>
|
||||
<body>
|
||||
{children}
|
||||
<Scripts />
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
> [!CAUTION]
|
||||
> React Scan must be imported before React (and other React renderers like React DOM) in your entire project, as it needs to hijack React DevTools before React gets to access it.
|
||||
|
||||
Alternatively you can also do the following code in `app/client`:
|
||||
|
||||
```jsx
|
||||
// app/client
|
||||
import { scan } from "react-scan"; // must be imported before React and React DOM
|
||||
import { hydrateRoot } from "react-dom/client";
|
||||
import { StartClient } from "@tanstack/start";
|
||||
import { createRouter } from "./router";
|
||||
|
||||
scan({
|
||||
enabled: true,
|
||||
});
|
||||
|
||||
const router = createRouter();
|
||||
|
||||
hydrateRoot(document, <StartClient router={router} />);
|
||||
```
|
||||
|
||||
> [!CAUTION]
|
||||
> This only works for React 19
|
||||
|
||||
If you want react-scan to also run in production, use the react-scan/all-environments import path
|
||||
|
||||
```diff
|
||||
- import { scan } from "react-scan";
|
||||
+ import { scan } from "react-scan/all-environments";
|
||||
```
|
||||
@@ -0,0 +1,54 @@
|
||||
# Vite Guide
|
||||
|
||||
## As a script tag
|
||||
|
||||
Add the script tag to your `index.html`.
|
||||
|
||||
Refer to the [CDN Guide](https://github.com/aidenybai/react-scan/blob/main/docs/installation/cdn.md) for the available URLs.
|
||||
|
||||
```html
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<script src="https://unpkg.com/react-scan/dist/auto.global.js"></script>
|
||||
|
||||
<!-- rest of your scripts go under -->
|
||||
</head>
|
||||
<body>
|
||||
<!-- ... -->
|
||||
</body>
|
||||
</html>
|
||||
```
|
||||
|
||||
## As a module import
|
||||
|
||||
In your project entrypoint (e.g. `src/index`, `src/main`):
|
||||
|
||||
```jsx
|
||||
// src/index
|
||||
import { scan } from "react-scan"; // must be imported before React and React DOM
|
||||
import React from "react";
|
||||
|
||||
scan({
|
||||
enabled: true,
|
||||
});
|
||||
```
|
||||
|
||||
If you want react-scan to also run in production, use the react-scan/all-environments import path
|
||||
|
||||
```diff
|
||||
- import { scan } from "react-scan";
|
||||
+ import { scan } from "react-scan/all-environments";
|
||||
```
|
||||
|
||||
|
||||
> [!CAUTION]
|
||||
> React Scan must be imported before React (and other React renderers like React DOM) in your entire project, as it needs to hijack React DevTools before React gets to access it.
|
||||
|
||||
## Vite plugin
|
||||
|
||||
TODO
|
||||
|
||||
## Preserving component names
|
||||
|
||||
TODO
|
||||
Reference in New Issue
Block a user