Skip to content

Commit 302ec04

Browse files
authored
Merge pull request #19 from aidenybai/revert-17-feat/select
Revert "Select Components" (slow)
2 parents 26eedb2 + e07339a commit 302ec04

File tree

2 files changed

+7
-84
lines changed

2 files changed

+7
-84
lines changed

src/core/index.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from './web/outline';
1010
import { createOverlay } from './web/index';
1111
import { logIntro } from './web/log';
12-
import { createToolbar, renderCheckbox } from './web/toolbar';
12+
import { createToolbar } from './web/toolbar';
1313
import { playGeigerClickSound } from './web/geiger';
1414
import { createPerfObserver } from './web/perf-observer';
1515

@@ -97,7 +97,6 @@ interface Internals {
9797
isInIframe: boolean;
9898
isPaused: boolean;
9999
componentAllowList: WeakMap<React.ComponentType<any>, Options> | null;
100-
componentNameAllowList: Set<string>;
101100
options: Options;
102101
scheduledOutlines: PendingOutline[];
103102
activeOutlines: ActiveOutline[];
@@ -124,7 +123,6 @@ export const ReactScanInternals: Internals = {
124123
isInIframe: window.self !== window.top,
125124
isPaused: false,
126125
componentAllowList: null,
127-
componentNameAllowList: new Set<string>(),
128126
options: {
129127
enabled: true,
130128
includeChildren: true,
@@ -182,15 +180,7 @@ export const start = () => {
182180
options.onRender?.(fiber, render);
183181
const outline = getOutline(fiber, render);
184182
if (!outline) return;
185-
const { componentNameAllowList } = ReactScanInternals;
186-
if (
187-
!render.name ||
188-
!componentNameAllowList.size ||
189-
componentNameAllowList.has(render.name)
190-
) {
191-
ReactScanInternals.scheduledOutlines.push(outline);
192-
}
193-
183+
ReactScanInternals.scheduledOutlines.push(outline);
194184

195185
if (options.playSound && audioContext) {
196186
const renderTimeThreshold = 10;
@@ -209,7 +199,6 @@ export const start = () => {
209199
time: (prev?.time ?? 0) + render.time,
210200
renders: prev.renders,
211201
};
212-
renderCheckbox();
213202
}
214203

215204
requestAnimationFrame(() => {

src/core/web/toolbar.ts

Lines changed: 5 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getReport, ReactScanInternals } from '../../index';
1+
import { ReactScanInternals } from '../../index';
22
import { createElement } from './utils';
33
import { MONO_FONT } from './outline';
44

@@ -7,32 +7,16 @@ export const createToolbar = () => {
77
`<div id="react-scan-toolbar" 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">react-scan</div>`,
88
) as HTMLDivElement;
99

10-
// Create a scrollable and resizable div containing checkboxes
11-
const checkboxContainer = createElement(
12-
`<div id="react-scan-checkbox-list" style="position:fixed;bottom:3px;left:3px;min-width:200px;max-width:400px;height:200px;background:rgba(0,0,0,0.5);padding:8px;border:1px solid rgba(255,255,255,0.4);border-radius:6px;box-shadow:0 2px 8px rgba(0,0,0,0.15);z-index:2147483647;font-family:${MONO_FONT};overflow-y:auto;resize:horizontal;display:none;">
13-
<div style="font-weight:400;margin-bottom:8px;color:white;border-bottom:1px solid rgba(255,255,255,0.4);padding-bottom:4px; font-size:14px;">Component Filters</div>
14-
</div>`,
15-
) as HTMLDivElement;
16-
17-
document.documentElement.appendChild(checkboxContainer);
18-
1910
let isHidden =
20-
// Discord doesn't support localStorage
11+
// discord doesn't support localStorage
2112
'localStorage' in globalThis &&
2213
localStorage.getItem('react-scan-hidden') === 'true';
2314

24-
let isCheckboxContainerHidden = true;
25-
26-
const toggleButton = createElement(
27-
`<button style="margin-left:8px;background:rgba(255,255,255,0.2);border:1px solid rgba(255,255,255,0.4);color:white;cursor:pointer;padding:3px 6px;border-radius:4px;font-size:16px;transition:all 0.2s;" title="Toggle component list">☰</button>`
28-
) as HTMLButtonElement;
29-
3015
const updateVisibility = () => {
3116
const overlay = document.getElementById('react-scan-overlay');
3217
if (!overlay) return;
3318
overlay.style.display = isHidden ? 'none' : 'block';
34-
status.textContent = isHidden ? 'start' : 'stop';
35-
status.appendChild(toggleButton);
19+
status.textContent = isHidden ? 'start ►' : 'stop ⏹';
3620
ReactScanInternals.isPaused = isHidden;
3721
if (ReactScanInternals.isPaused) {
3822
ReactScanInternals.activeOutlines = [];
@@ -45,30 +29,18 @@ export const createToolbar = () => {
4529

4630
updateVisibility();
4731

48-
status.addEventListener('click', (e) => {
49-
if (e.target === toggleButton) return;
32+
status.addEventListener('click', () => {
5033
isHidden = !isHidden;
5134
updateVisibility();
5235
});
5336

54-
toggleButton.addEventListener('click', () => {
55-
isCheckboxContainerHidden = !isCheckboxContainerHidden;
56-
checkboxContainer.style.display = isCheckboxContainerHidden ? 'none' : 'block';
57-
renderCheckbox();
58-
});
59-
6037
status.addEventListener('mouseenter', () => {
61-
if (status.textContent !== '☰') {
62-
status.textContent = isHidden ? 'start' : 'stop';
63-
status.appendChild(toggleButton);
64-
}
38+
status.textContent = isHidden ? 'start ►' : 'stop ⏹';
6539
status.style.backgroundColor = 'rgba(0,0,0,1)';
66-
toggleButton.style.backgroundColor = 'rgba(255,255,255,0.3)';
6740
});
6841

6942
status.addEventListener('mouseleave', () => {
7043
status.style.backgroundColor = 'rgba(0,0,0,0.5)';
71-
toggleButton.style.backgroundColor = 'rgba(255,255,255,0.2)';
7244
});
7345

7446
const prevElement = document.getElementById('react-scan-toolbar');
@@ -79,41 +51,3 @@ export const createToolbar = () => {
7951

8052
return status;
8153
};
82-
83-
export const renderCheckbox = () => {
84-
const checkboxContainer = document.getElementById('react-scan-checkbox-list');
85-
if (!checkboxContainer) return;
86-
87-
checkboxContainer.innerHTML = `
88-
<div style="font-weight:600;margin-bottom:8px;color:white;border-bottom:1px solid rgba(255,255,255,0.4);padding-bottom:4px;">Component Filters</div>
89-
`;
90-
91-
for (const [name, { count, time }] of Object.entries(getReport())) {
92-
const label = createElement(
93-
`<label style="display:flex;align-items:center;padding:4px 0;border-radius:4px;cursor:pointer;transition:background 0.2s;margin:2px 0;color:white;font-size:13px;">
94-
<input type="checkbox" value="${name}" style="margin-right:8px;">
95-
<div style="flex:1;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">${name}</div>
96-
<div style="margin-left:8px;color:rgba(255,255,255,0.7);white-space:nowrap;">✖︎${count} · ${time.toFixed(1)}ms</div>
97-
</label>`,
98-
) as HTMLLabelElement;
99-
100-
const checkbox = label.querySelector('input')!;
101-
checkbox.checked = ReactScanInternals.componentNameAllowList.has(name);
102-
103-
label.addEventListener('mouseenter', () => {
104-
label.style.background = 'rgba(255,255,255,0.1)';
105-
});
106-
107-
label.addEventListener('mouseleave', () => {
108-
label.style.background = 'transparent';
109-
});
110-
111-
checkbox.addEventListener('change', () => {
112-
if (checkbox.checked)
113-
ReactScanInternals.componentNameAllowList.add(name);
114-
else ReactScanInternals.componentNameAllowList.delete(name);
115-
});
116-
117-
checkboxContainer.appendChild(label);
118-
}
119-
};

0 commit comments

Comments
 (0)