Skip to content

Commit 19169a1

Browse files
committed
refactor(core): Remove unused code and optimize conditions
1 parent 5e91d3e commit 19169a1

File tree

3 files changed

+7
-47
lines changed

3 files changed

+7
-47
lines changed

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
"email": "[email protected]",
2424
"url": "https://million.dev"
2525
},
26-
"sideEffects": false,
2726
"type": "commonjs",
2827
"exports": {
2928
"./package.json": "./package.json",

src/core/index.ts

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,8 @@ export const start = () => {
171171
onRender(fiber, render) {
172172
options.onRender?.(fiber, render);
173173
const outline = getOutline(fiber, render);
174-
if (outline) {
175-
ReactScanInternals.scheduledOutlines.push(outline);
176-
}
174+
if (!outline) return;
175+
ReactScanInternals.scheduledOutlines.push(outline);
177176

178177
if (options.playSound && audioContext) {
179178
const renderTimeThreshold = 10;
@@ -194,31 +193,6 @@ export const start = () => {
194193

195194
requestAnimationFrame(() => {
196195
flushOutlines(ctx, new Map(), toolbar, perfObserver);
197-
198-
// const fiberData = ReactScanInternals.fiberMap.get(fiber);
199-
// const now = Date.now();
200-
// let count = render.count;
201-
// let time = render.time;
202-
// if (fiberData) {
203-
// // clear aggregated fibers after 5 seconds
204-
// if (
205-
// now - fiberData.lastUpdated >
206-
// (options.resetCountTimeout ?? 5000)
207-
// ) {
208-
// ReactScanInternals.fiberMap.delete(fiber);
209-
// } else {
210-
// count += fiberData.count;
211-
// time += fiberData.time;
212-
// render.count = count;
213-
// render.time = time;
214-
// }
215-
// }
216-
217-
// ReactScanInternals.fiberMap.set(fiber, {
218-
// count,
219-
// time,
220-
// lastUpdated: now,
221-
// });
222196
});
223197
},
224198
onCommitFinish() {

src/core/web/outline.ts

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { ReactScanInternals } from '../index';
55
import { getLabelText } from '../utils';
66
import { isOutlineUnstable, throttle } from './utils';
77
import { log } from './log';
8+
import { recalcOutlineColor } from './perf-observer';
89
// import { recalcOutlineColor } from './perf-observer';
910

1011
export interface PendingOutline {
@@ -38,19 +39,7 @@ export const getOutlineKey = (outline: PendingOutline): string => {
3839
return `${outline.rect.top}-${outline.rect.left}-${outline.rect.width}-${outline.rect.height}`;
3940
};
4041

41-
const getRectCache = new WeakMap<
42-
HTMLElement,
43-
{ rect: DOMRect; timestamp: number }
44-
>();
45-
4642
export const getRect = (domNode: HTMLElement): DOMRect | null => {
47-
const cachedRect = getRectCache.get(domNode);
48-
if (
49-
cachedRect &&
50-
performance.now() - cachedRect.timestamp < DEFAULT_THROTTLE_TIME
51-
) {
52-
return cachedRect.rect;
53-
}
5443
const style = window.getComputedStyle(domNode);
5544
if (
5645
style.display === 'none' ||
@@ -63,17 +52,15 @@ export const getRect = (domNode: HTMLElement): DOMRect | null => {
6352
const rect = domNode.getBoundingClientRect();
6453

6554
const isVisible =
66-
rect.top >= 0 ||
67-
rect.left >= 0 ||
68-
rect.bottom <= window.innerHeight ||
55+
rect.top >= 0 &&
56+
rect.left >= 0 &&
57+
rect.bottom <= window.innerHeight &&
6958
rect.right <= window.innerWidth;
7059

7160
if (!isVisible || !rect.width || !rect.height) {
7261
return null;
7362
}
7463

75-
getRectCache.set(domNode, { rect, timestamp: performance.now() });
76-
7764
return rect;
7865
};
7966

@@ -168,7 +155,7 @@ export const flushOutlines = (
168155

169156
requestAnimationFrame(() => {
170157
if (perfObserver) {
171-
// recalcOutlineColor(perfObserver.takeRecords());
158+
recalcOutlineColor(perfObserver.takeRecords());
172159
}
173160
recalcOutlines();
174161
void (async () => {

0 commit comments

Comments
 (0)