Skip to content

Commit af4b161

Browse files
committed
docs(README): Update installation guide and roadmap
1 parent fcc8fbe commit af4b161

File tree

6 files changed

+91
-28
lines changed

6 files changed

+91
-28
lines changed

README.md

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@ It's also just JavaScript, so you drop it in anywhere – script tag, npm, you n
1414

1515
## Install
1616

17-
The simplest way to use it is to add this script to your app:
17+
Get started in 5 seconds, add this script to your app:
1818

1919
```html
2020
<!-- import this BEFORE any scripts -->
2121
<script src="https://unpkg.com/react-scan/dist/auto.global.js"></script>
2222
```
2323

24-
Or, if you prefer, install via npm:
25-
2624
```bash
2725
npm install react-scan
2826
```
@@ -35,24 +33,24 @@ import React from 'react';
3533

3634
scan({
3735
enabled: true,
38-
log: true, // logs render info to console
36+
log: true, // logs render info to console (default: false)
37+
clearLog: false, // clears the console per group of renders (default: false)
3938
});
4039
```
4140

41+
And voilà! You're ready to go.
42+
4243
> Looking for a more advanced version? Check out [Million Lint](https://million.dev)!
4344
4445
## How does it work?
4546

46-
## Future work
47-
48-
- [ ] problem finder
49-
- [ ] FPS counter
50-
- [ ] combobox ("total blocking time")
51-
- [ ] vercel toolbar comment
52-
- [ ] select open certain components
53-
- [ ] only show the renders that matter
54-
- [ ] wrap scan programmatically
55-
- [ ] scan auto mode
56-
- [ ] only show when there's main thread blocking
57-
- [ ] add the stop im changing dude
58-
- [ ] list of components and props
47+
## Future roadmap
48+
49+
- [ ] Chrome extension
50+
- [ ] Cleanup config options
51+
- [ ] Name / explain the actual problem
52+
- [ ] Add more problem detections other than props
53+
- [ ] Simple FPS counter
54+
- [ ] Drag and select areas of the screen to scan
55+
- [ ] Mode to only show on main thread blocking
56+
- [ ] Add a funny mascot, like the ["Stop I'm Changing" dude](https://www.youtube.com/shorts/FwOZdX7bDKI?app=desktop)

src/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {
1111
import { MONO_FONT } from './constants';
1212
import { traverseFiber, registerDevtoolsHook, getType } from './fiber';
1313
import type { Outline, ScanOptions, WithScanOptions } from './types';
14-
import { isInIframe } from './utils';
14+
import { isInIframe, isProd } from './utils';
1515

1616
const DEFAULT_OPTIONS: ScanOptions & WithScanOptions = {
1717
enabled: true,
@@ -53,7 +53,9 @@ export const scan = (
5353
) => {
5454
currentOptions = options ?? currentOptions;
5555

56-
if (inited || isInIframe() || currentOptions.enabled === false) return;
56+
if (inited || isInIframe() || currentOptions.enabled === false || isProd()) {
57+
return;
58+
}
5759
inited = true;
5860

5961
// eslint-disable-next-line no-console
@@ -63,7 +65,7 @@ export const scan = (
6365
);
6466

6567
const ctx = createFullscreenCanvas();
66-
const indicator = createStatus();
68+
const status = createStatus();
6769

6870
const handleCommitFiberRoot = (_rendererID: number, root: FiberRoot) => {
6971
const outlines: Outline[] = [];
@@ -116,7 +118,7 @@ export const scan = (
116118
}
117119
let text = ${totalCount}`;
118120
if (totalSelfTime > 0) text += ` (${totalSelfTime.toFixed(2)}ms)`;
119-
indicator.textContent = text;
121+
status.textContent = `${text} · react-scan`;
120122
flushOutlines(ctx);
121123
}
122124
};

src/overlay.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,10 @@ export const createFullscreenCanvas = () => {
401401
});
402402

403403
onIdle(() => {
404+
const prevCanvas = document.getElementById('react-scan-canvas');
405+
if (prevCanvas) {
406+
prevCanvas.remove();
407+
}
404408
document.documentElement.appendChild(canvas);
405409
});
406410

@@ -409,30 +413,44 @@ export const createFullscreenCanvas = () => {
409413

410414
export const createStatus = () => {
411415
const status = createElement(
412-
`<div id="react-scan-indicator" style="position:fixed;bottom:3px;right:3px;background:rgba(0,0,0,0.5);padding:4px 8px;border-radius:4px;color:white;z-index:2147483647;font-family:${MONO_FONT}" aria-hidden="true">hide scanner</div>`,
416+
`<div id="react-scan-status" title="Number of unnecessary renders and time elapsed" style="position:fixed;bottom:3px;right:3px;background:rgba(0,0,0,0.5);padding:4px 8px;border-radius:4px;color:white;z-index:2147483647;font-family:${MONO_FONT}" aria-hidden="true">hide scanner</div>`,
413417
) as HTMLDivElement;
414418

415-
let isHidden = false;
416-
status.addEventListener('click', () => {
419+
let isHidden = localStorage.getItem('react-scan-hidden') === 'true';
420+
421+
const updateVisibility = () => {
417422
const canvas = document.getElementById('react-scan-canvas');
418423
if (!canvas) return;
419-
isHidden = !isHidden;
420424
canvas.style.display = isHidden ? 'none' : 'block';
421-
status.textContent = `${isHidden ? 'Start' : 'Stop'} scanning`;
425+
status.textContent = isHidden ? 'start ►' : 'stop ⏹';
422426
isPaused = isHidden;
423427
if (isPaused) {
424428
activeOutlines = [];
425429
pendingOutlines = [];
426430
}
431+
localStorage.setItem('react-scan-hidden', isHidden.toString());
432+
};
433+
434+
updateVisibility();
435+
436+
status.addEventListener('click', () => {
437+
isHidden = !isHidden;
438+
updateVisibility();
427439
});
440+
428441
status.addEventListener('mouseenter', () => {
429-
status.textContent = `${isHidden ? 'Start' : 'Stop'} scanning`;
442+
status.textContent = isHidden ? 'start ►' : 'stop ⏹';
430443
status.style.backgroundColor = 'rgba(0,0,0,1)';
431444
});
445+
432446
status.addEventListener('mouseleave', () => {
433447
status.style.backgroundColor = 'rgba(0,0,0,0.5)';
434448
});
435449

450+
const prevElement = document.getElementById('react-scan-status');
451+
if (prevElement) {
452+
prevElement.remove();
453+
}
436454
document.documentElement.appendChild(status);
437455

438456
return status;

src/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ export const isInIframe = () => {
7272
}
7373
};
7474

75+
const tempDivElement = React.createElement('div');
76+
export const isProd = () => {
77+
return '_self' in tempDivElement;
78+
};
79+
7580
export const NO_OP = () => {
7681
/**/
7782
};

test/index.html

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,54 @@
33
<head>
44
<meta charset="UTF-8" />
55
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
6+
7+
<title>React Scan</title>
8+
<meta name="title" content="React Scan" />
9+
<meta
10+
name="description"
11+
content="React Scan automatically detects and highlights components that cause performance issues in your React app. Drop it in anywhere – script tag, npm, you name it!"
12+
/>
13+
14+
<meta property="og:type" content="website" />
15+
<meta property="og:url" content="https://react-scan.million.dev" />
16+
<meta property="og:title" content="React Scan" />
17+
<meta
18+
property="og:description"
19+
content="React Scan automatically detects and highlights components that cause performance issues in your React app. Drop it in anywhere – script tag, npm, you name it!"
20+
/>
21+
<meta
22+
property="og:image"
23+
content="https://react-scan.million.dev/banner.png"
24+
/>
25+
26+
<meta property="twitter:card" content="summary_large_image" />
27+
<meta property="twitter:url" content="https://react-scan.million.dev" />
28+
<meta property="twitter:title" content="React Scan" />
29+
<meta
30+
property="twitter:description"
31+
content="React Scan automatically detects and highlights components that cause performance issues in your React app. Drop it in anywhere – script tag, npm, you name it!"
32+
/>
33+
<meta
34+
property="twitter:image"
35+
content="https://react-scan.million.dev/banner.png"
36+
/>
37+
638
<link rel="preconnect" href="https://fonts.googleapis.com" />
739
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
840
<link
941
href="https://fonts.googleapis.com/css2?family=Geist+Mono:[email protected]&family=Geist:[email protected]&display=swap"
1042
rel="stylesheet"
1143
/>
44+
1245
<link rel="icon" href="/logo.svg" type="image/svg+xml" />
13-
<title>react-scan</title>
46+
47+
<meta
48+
name="keywords"
49+
content="react, performance, debugging, developer tools, web development, javascript"
50+
/>
51+
<meta name="author" content="Aiden Bai" />
52+
<meta name="theme-color" content="#8b5cf6" />
53+
<link rel="canonical" href="https://react-scan.million.dev" />
1454
</head>
1555
<body>
1656
<div id="root"></div>

test/public/banner.png

190 KB
Loading

0 commit comments

Comments
 (0)