Skip to content

Commit 66cd5d6

Browse files
committed
refactor: write the React Scan plugin in React
1 parent b00aec8 commit 66cd5d6

15 files changed

Lines changed: 296 additions & 159 deletions

File tree

docs/plugins/react-scan.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ title: React Scan Plugin
33
id: react-scan-plugin
44
---
55

6-
You want the full [react-scan](https://github.com/aidenybai/react-scan) workbench inside TanStack Devtools, not a second floating toolbar on the page. This plugin starts `react-scan` and docks its native UI into the TanStack tab.
6+
You want the official [react-scan](https://github.com/aidenybai/react-scan) panel inside TanStack Devtools, not a second floating toolbar on the page. This plugin starts `scan()` in the app, so app re-renders are scanned. It then locks the native React Scan panel into the TanStack tab.
77

8-
That native UI includes:
8+
That native panel includes:
99

1010
- Inspect mode to pick a component on the page
1111
- The inspector: What Changed, props, and the component tree
1212
- Slowdown notifications
1313
- Outline toggle for re-renders
1414
- FPS meter
1515

16-
Page outlines stay on the page. The toolbar sits in the plugin pane.
16+
Page outlines stay on the page. The native panel fills the plugin pane. You cannot drag it and it has no close control. Close the tab from TanStack Devtools.
1717

1818
## Installation
1919

@@ -49,8 +49,9 @@ Do not also load `react-scan/dist/auto.global.js`. Two scanners will run at the
4949
1. Open the **React Scan** plugin.
5050
2. Click the inspect icon, then click a component in the app.
5151
3. The inspector shows why that component rendered and its tree.
52-
4. Click the bell for slowdown notifications.
53-
5. Use the outline toggle to turn page outlines on or off.
52+
4. Interact with the app (for example click **Increment count**). What Changed updates for the selected component.
53+
5. Click the bell for slowdown notifications.
54+
6. Use the outline toggle to turn page outlines on or off.
5455

5556
## Options
5657

@@ -82,4 +83,4 @@ If you want the real plugin in every environment, import `@tanstack/react-scan-d
8283

8384
## Example
8485

85-
See `examples/react/basic`. Open the React Scan tab, click inspect, then click **Increment count**.
86+
See `examples/react/basic`. Open the React Scan tab, click inspect, click **Increment count**, then click it again to see What Changed.

packages/react-scan-devtools/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# @tanstack/react-scan-devtools
22

3-
React Scan plugin for TanStack Devtools. It starts `react-scan` and docks the native React Scan UI (inspect, What Changed, notifications, FPS) into the TanStack tab.
3+
React Scan plugin for TanStack Devtools. It starts `react-scan` in the app and docks the official React Scan panel into the TanStack tab.
44

55
```bash
66
npm install @tanstack/react-scan-devtools react-scan

packages/react-scan-devtools/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,14 @@
6262
},
6363
"dependencies": {
6464
"@tanstack/devtools-utils": "workspace:^",
65-
"react-scan": "^0.5.7",
66-
"solid-js": "^1.9.9"
65+
"react-scan": "^0.5.7"
6766
},
6867
"devDependencies": {
6968
"@types/react": "^19.2.0",
7069
"@types/react-dom": "^19.2.0",
70+
"@vitejs/plugin-react": "^6.0.1",
7171
"react": "^19.2.0",
72-
"react-dom": "^19.2.0",
73-
"vite-plugin-solid": "^2.11.11"
72+
"react-dom": "^19.2.0"
7473
},
7574
"peerDependencies": {
7675
"@types/react": ">=17.0.0",
Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
1-
/** @jsxImportSource solid-js */
2-
3-
import { onCleanup, onMount } from 'solid-js'
1+
import { useEffect, useRef } from 'react'
42
import { dockReactScanToolbar } from '../host-toolbar'
53

6-
export function Shell() {
7-
let host: HTMLDivElement | undefined
4+
export function ReactScanDevtoolsPanel() {
5+
const hostRef = useRef<HTMLDivElement>(null)
86

9-
onMount(() => {
7+
useEffect(() => {
8+
const host = hostRef.current
109
if (!host) {
1110
return
1211
}
13-
const stop = dockReactScanToolbar(host)
14-
onCleanup(stop)
15-
})
12+
return dockReactScanToolbar(host)
13+
}, [])
1614

1715
return (
1816
<div
19-
ref={host}
17+
ref={hostRef}
2018
data-tsd-surface
2119
data-testid="react-scan-host"
2220
style={{
2321
position: 'relative',
2422
height: '100%',
2523
width: '100%',
26-
'min-height': '100%',
24+
minHeight: '100%',
2725
}}
2826
/>
2927
)
3028
}
29+
30+
export function ReactScanDevtoolsPanelNoOp() {
31+
return null
32+
}

packages/react-scan-devtools/src/core/components/index.tsx

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)