bippy 0.3.16 → 0.3.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +97 -13
- package/dist/{core-C20dLY3P.js → core-BMGX84sL.js} +12 -157
- package/dist/{core-BOYfIZ0s.d.cts → core-BPWvvzb6.d.ts} +37 -101
- package/dist/core-CqD-jmcz.d.cts +229 -0
- package/dist/{core-BS9Kf-6A.cjs → core-DDlrYYa3.cjs} +23 -229
- package/dist/core.cjs +14 -12
- package/dist/core.d.cts +3 -2
- package/dist/core.d.ts +3 -2
- package/dist/core.js +3 -2
- package/dist/experiments/inspect.cjs +9 -9
- package/dist/experiments/inspect.js +5 -4
- package/dist/index.cjs +15 -13
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.iife.js +1 -1
- package/dist/index.js +4 -3
- package/dist/override.cjs +123 -0
- package/dist/override.d.cts +14 -0
- package/dist/override.d.ts +14 -0
- package/dist/override.js +120 -0
- package/dist/rdt-hook-B2u14A_F.js +162 -0
- package/dist/rdt-hook-BDCUc59L.cjs +228 -0
- package/dist/{source-CpUl2rbU.cjs → source-Bs3pHZxr.cjs} +49 -17
- package/dist/{source-l0-0Utl0.js → source-CzshDdc9.js} +2 -1
- package/dist/source.cjs +5 -74
- package/dist/source.d.cts +2 -3
- package/dist/source.d.ts +2 -3
- package/dist/source.js +5 -4
- package/dist/{src-8X9f2vzK.cjs → src-DZp3afz6.cjs} +2 -2
- package/dist/{src-CYAt7ssK.js → src-HIN0w1H-.js} +1 -1
- package/dist/types-DKV6Tlox.d.ts +74 -0
- package/dist/types-nTMJ2k9V.d.cts +74 -0
- package/package.json +6 -16
- package/dist/chunk-DWy1uDak.cjs +0 -47
- package/dist/core-CmL25iLV.d.ts +0 -293
- package/dist/index-BtBZHVmz.d.cts +0 -1
- package/dist/index-D0E78WnU.d.ts +0 -1
- package/dist/jsx-dev-runtime.cjs +0 -32
- package/dist/jsx-dev-runtime.d.cts +0 -9
- package/dist/jsx-dev-runtime.d.ts +0 -9
- package/dist/jsx-dev-runtime.js +0 -26
- package/dist/jsx-runtime.cjs +0 -19
- package/dist/jsx-runtime.d.cts +0 -3
- package/dist/jsx-runtime.d.ts +0 -3
- package/dist/jsx-runtime.js +0 -12
- package/dist/source.iife.js +0 -14
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ by default, you cannot access react internals. bippy bypasses this by "pretendin
|
|
|
18
18
|
- no prior react source code knowledge required
|
|
19
19
|
|
|
20
20
|
```jsx
|
|
21
|
-
import { onCommitFiberRoot, traverseFiber } from 'bippy';
|
|
21
|
+
import { onCommitFiberRoot, traverseFiber } from 'bippy'; // must be imported BEFORE react
|
|
22
22
|
|
|
23
23
|
onCommitFiberRoot((root) => {
|
|
24
24
|
traverseFiber(root.current, (fiber) => {
|
|
@@ -82,7 +82,7 @@ while all of the information is there, it's not super easy to work with, and cha
|
|
|
82
82
|
|
|
83
83
|
however, fibers aren't directly accessible by the user. so, we have to hack our way around to accessing it.
|
|
84
84
|
|
|
85
|
-
luckily, react [reads from a property](https://github.com/facebook/react/blob/6a4b46cd70d2672bc4be59dcb5b8dede22ed0cef/packages/react-reconciler/src/
|
|
85
|
+
luckily, react [reads from a property](https://github.com/facebook/react/blob/6a4b46cd70d2672bc4be59dcb5b8dede22ed0cef/packages/react-reconciler/src/ReactFiberDevToolsHook.js#L48) in the window object: `window.__REACT_DEVTOOLS_GLOBAL_HOOK__` and runs handlers on it when certain events happen. this property must exist before react's bundle is executed. this is intended for react devtools, but we can use it to our advantage.
|
|
86
86
|
|
|
87
87
|
here's what it roughly looks like:
|
|
88
88
|
|
|
@@ -397,7 +397,7 @@ import { isValidFiber } from 'bippy';
|
|
|
397
397
|
console.log(isValidFiber(fiber));
|
|
398
398
|
```
|
|
399
399
|
|
|
400
|
-
|
|
400
|
+
### getFiberFromHostInstance
|
|
401
401
|
|
|
402
402
|
returns the fiber associated with a given host instance (e.g., a DOM element).
|
|
403
403
|
|
|
@@ -408,7 +408,7 @@ const fiber = getFiberFromHostInstance(document.querySelector('div'));
|
|
|
408
408
|
console.log(fiber);
|
|
409
409
|
```
|
|
410
410
|
|
|
411
|
-
|
|
411
|
+
### getLatestFiber
|
|
412
412
|
|
|
413
413
|
returns the latest fiber (since it may be double-buffered). usually use this in combination with `getFiberFromHostInstance`.
|
|
414
414
|
|
|
@@ -421,6 +421,90 @@ const latestFiber = getLatestFiber(
|
|
|
421
421
|
console.log(latestFiber);
|
|
422
422
|
```
|
|
423
423
|
|
|
424
|
+
### getFiberSource
|
|
425
|
+
|
|
426
|
+
returns the source code location of a fiber.
|
|
427
|
+
|
|
428
|
+
```typescript
|
|
429
|
+
import { getFiberSource } from 'bippy/source';
|
|
430
|
+
|
|
431
|
+
const fiber = getFiberFromHostInstance(document.querySelector('div'));
|
|
432
|
+
|
|
433
|
+
console.log(await getFiberSource(fiber));
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
> note: in order to get accurate source locations in react >= 19, you need to add this in your `tsconfig.json`:
|
|
437
|
+
>
|
|
438
|
+
> ```json
|
|
439
|
+
> {
|
|
440
|
+
> "compilerOptions": {
|
|
441
|
+
> "jsxImportSource": "bippy/dist"
|
|
442
|
+
> }
|
|
443
|
+
> }
|
|
444
|
+
> ```
|
|
445
|
+
|
|
446
|
+
### overrideProps
|
|
447
|
+
|
|
448
|
+
overrides component props at runtime by modifying the fiber's props.
|
|
449
|
+
|
|
450
|
+
```typescript
|
|
451
|
+
import { overrideProps } from 'bippy/override';
|
|
452
|
+
|
|
453
|
+
// override props on a fiber
|
|
454
|
+
overrideProps(fiber, {
|
|
455
|
+
title: 'new title',
|
|
456
|
+
config: {
|
|
457
|
+
enabled: true,
|
|
458
|
+
count: 42
|
|
459
|
+
}
|
|
460
|
+
});
|
|
461
|
+
```
|
|
462
|
+
|
|
463
|
+
the function accepts a fiber and a partial object containing the props to override. nested objects are automatically flattened into property paths.
|
|
464
|
+
|
|
465
|
+
### overrideHookState
|
|
466
|
+
|
|
467
|
+
overrides hook state (usestate, usereducer, etc.) at runtime by hook id.
|
|
468
|
+
|
|
469
|
+
```typescript
|
|
470
|
+
import { overrideHookState } from 'bippy/override';
|
|
471
|
+
|
|
472
|
+
// override the first hook (id: 0) with a new value
|
|
473
|
+
overrideHookState(fiber, 0, 'new state value');
|
|
474
|
+
|
|
475
|
+
// override nested state object
|
|
476
|
+
overrideHookState(fiber, 1, {
|
|
477
|
+
user: {
|
|
478
|
+
name: 'john',
|
|
479
|
+
age: 30
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
```
|
|
483
|
+
|
|
484
|
+
the hook id parameter corresponds to the order of hooks in the component (0-indexed). the function can accept either a primitive value or an object for nested state updates.
|
|
485
|
+
|
|
486
|
+
### overrideContext
|
|
487
|
+
|
|
488
|
+
overrides react context values at runtime by finding the appropriate context provider.
|
|
489
|
+
|
|
490
|
+
```typescript
|
|
491
|
+
import { overrideContext } from 'bippy/override';
|
|
492
|
+
|
|
493
|
+
// override context value
|
|
494
|
+
overrideContext(fiber, MyContext, {
|
|
495
|
+
theme: 'dark',
|
|
496
|
+
user: {
|
|
497
|
+
id: 123,
|
|
498
|
+
name: 'jane'
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
// override with primitive value
|
|
503
|
+
overrideContext(fiber, ThemeContext, 'dark');
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
the function traverses up the fiber tree to find the context provider matching the provided context type and overrides its value.
|
|
507
|
+
|
|
424
508
|
## examples
|
|
425
509
|
|
|
426
510
|
the best way to understand bippy is to [read the source code](https://github.com/aidenybai/bippy/blob/main/src/core.ts). here are some examples of how you can use it:
|
|
@@ -432,7 +516,7 @@ here's a mini toy version of [`react-scan`](https://github.com/aidenybai/react-s
|
|
|
432
516
|
```javascript
|
|
433
517
|
import {
|
|
434
518
|
instrument,
|
|
435
|
-
|
|
519
|
+
secure,
|
|
436
520
|
getNearestHostFiber,
|
|
437
521
|
traverseRenderedFibers,
|
|
438
522
|
} from 'bippy'; // must be imported BEFORE react
|
|
@@ -448,7 +532,7 @@ const highlightFiber = (fiber) => {
|
|
|
448
532
|
highlight.style.left = `${rect.left}px`;
|
|
449
533
|
highlight.style.width = `${rect.width}px`;
|
|
450
534
|
highlight.style.height = `${rect.height}px`;
|
|
451
|
-
highlight.style.zIndex = 999999999;
|
|
535
|
+
highlight.style.zIndex = '999999999';
|
|
452
536
|
document.documentElement.appendChild(highlight);
|
|
453
537
|
setTimeout(() => {
|
|
454
538
|
document.documentElement.removeChild(highlight);
|
|
@@ -505,10 +589,10 @@ instrument(
|
|
|
505
589
|
|
|
506
590
|
here's a mini toy version of [`why-did-you-render`](https://github.com/welldone-software/why-did-you-render) that logs why components re-render.
|
|
507
591
|
|
|
508
|
-
```
|
|
592
|
+
```javascript
|
|
509
593
|
import {
|
|
510
594
|
instrument,
|
|
511
|
-
|
|
595
|
+
secure,
|
|
512
596
|
traverseRenderedFibers,
|
|
513
597
|
isCompositeFiber,
|
|
514
598
|
getDisplayName,
|
|
@@ -572,11 +656,11 @@ instrument(
|
|
|
572
656
|
* State don't have a "name" like props, so we use an id to identify them.
|
|
573
657
|
*/
|
|
574
658
|
traverseState(fiber, (value, prevValue) => {
|
|
575
|
-
if (
|
|
659
|
+
if (value !== prevValue) {
|
|
576
660
|
changes.push({
|
|
577
661
|
name: `state ${stateId}`,
|
|
578
|
-
prev,
|
|
579
|
-
next,
|
|
662
|
+
prev: prevValue,
|
|
663
|
+
next: value,
|
|
580
664
|
});
|
|
581
665
|
}
|
|
582
666
|
stateId++;
|
|
@@ -632,9 +716,9 @@ pnpm run dev
|
|
|
632
716
|
|
|
633
717
|
## misc
|
|
634
718
|
|
|
635
|
-
|
|
719
|
+
bippy was initially created for [react-scan](https://github.com/aidenybai/react-scan), which is deployed with proper safeguards to ensure it's only used in development or error-guarded in production.
|
|
636
720
|
|
|
637
|
-
|
|
721
|
+
if you're seeking more robust solutions, you might consider [its-fine](https://github.com/pmndrs/its-fine) for accessing fibers within react using hooks, or [react-devtools-inline](https://www.npmjs.com/package/react-devtools-inline) for a headful interface.
|
|
638
722
|
|
|
639
723
|
if you plan to use this project beyond experimentation, please review [react-scan's source code](https://github.com/aidenybai/react-scan) to understand our safeguarding practices.
|
|
640
724
|
|
|
@@ -6,157 +6,8 @@
|
|
|
6
6
|
* This source code is licensed under the MIT license found in the
|
|
7
7
|
* LICENSE file in the root directory of this source tree.
|
|
8
8
|
*/
|
|
9
|
-
|
|
10
|
-
const version = "0.3.16";
|
|
11
|
-
const BIPPY_INSTRUMENTATION_STRING = `bippy-${version}`;
|
|
12
|
-
const objectDefineProperty = Object.defineProperty;
|
|
13
|
-
const objectHasOwnProperty = Object.prototype.hasOwnProperty;
|
|
14
|
-
const NO_OP = () => {};
|
|
15
|
-
const checkDCE = (fn) => {
|
|
16
|
-
try {
|
|
17
|
-
const code = Function.prototype.toString.call(fn);
|
|
18
|
-
if (code.indexOf("^_^") > -1) setTimeout(() => {
|
|
19
|
-
throw new Error("React is running in production mode, but dead code elimination has not been applied. Read how to correctly configure React for production: https://reactjs.org/link/perf-use-production-build");
|
|
20
|
-
});
|
|
21
|
-
} catch {}
|
|
22
|
-
};
|
|
23
|
-
const isRealReactDevtools = (rdtHook = getRDTHook()) => {
|
|
24
|
-
return "getFiberRoots" in rdtHook;
|
|
25
|
-
};
|
|
26
|
-
let isReactRefreshOverride = false;
|
|
27
|
-
let injectFnStr = void 0;
|
|
28
|
-
const isReactRefresh = (rdtHook = getRDTHook()) => {
|
|
29
|
-
if (isReactRefreshOverride) return true;
|
|
30
|
-
if (typeof rdtHook.inject === "function") injectFnStr = rdtHook.inject.toString();
|
|
31
|
-
return Boolean(injectFnStr?.includes("(injected)"));
|
|
32
|
-
};
|
|
33
|
-
const onActiveListeners = new Set();
|
|
34
|
-
const _renderers = new Set();
|
|
35
|
-
const installRDTHook = (onActive) => {
|
|
36
|
-
const renderers = new Map();
|
|
37
|
-
let i = 0;
|
|
38
|
-
let rdtHook = {
|
|
39
|
-
checkDCE,
|
|
40
|
-
supportsFiber: true,
|
|
41
|
-
supportsFlight: true,
|
|
42
|
-
hasUnsupportedRendererAttached: false,
|
|
43
|
-
renderers,
|
|
44
|
-
onCommitFiberRoot: NO_OP,
|
|
45
|
-
onCommitFiberUnmount: NO_OP,
|
|
46
|
-
onPostCommitFiberRoot: NO_OP,
|
|
47
|
-
inject(renderer) {
|
|
48
|
-
const nextID = ++i;
|
|
49
|
-
renderers.set(nextID, renderer);
|
|
50
|
-
_renderers.add(renderer);
|
|
51
|
-
if (!rdtHook._instrumentationIsActive) {
|
|
52
|
-
rdtHook._instrumentationIsActive = true;
|
|
53
|
-
onActiveListeners.forEach((listener) => listener());
|
|
54
|
-
}
|
|
55
|
-
return nextID;
|
|
56
|
-
},
|
|
57
|
-
_instrumentationSource: BIPPY_INSTRUMENTATION_STRING,
|
|
58
|
-
_instrumentationIsActive: false
|
|
59
|
-
};
|
|
60
|
-
try {
|
|
61
|
-
objectDefineProperty(globalThis, "__REACT_DEVTOOLS_GLOBAL_HOOK__", {
|
|
62
|
-
get() {
|
|
63
|
-
return rdtHook;
|
|
64
|
-
},
|
|
65
|
-
set(newHook) {
|
|
66
|
-
if (newHook && typeof newHook === "object") {
|
|
67
|
-
const ourRenderers = rdtHook.renderers;
|
|
68
|
-
rdtHook = newHook;
|
|
69
|
-
if (ourRenderers.size > 0) {
|
|
70
|
-
ourRenderers.forEach((renderer, id) => {
|
|
71
|
-
_renderers.add(renderer);
|
|
72
|
-
newHook.renderers.set(id, renderer);
|
|
73
|
-
});
|
|
74
|
-
patchRDTHook(onActive);
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
},
|
|
78
|
-
configurable: true,
|
|
79
|
-
enumerable: true
|
|
80
|
-
});
|
|
81
|
-
const originalWindowHasOwnProperty = window.hasOwnProperty;
|
|
82
|
-
let hasRanHack = false;
|
|
83
|
-
objectDefineProperty(window, "hasOwnProperty", {
|
|
84
|
-
value: function() {
|
|
85
|
-
try {
|
|
86
|
-
if (!hasRanHack && arguments[0] === "__REACT_DEVTOOLS_GLOBAL_HOOK__") {
|
|
87
|
-
globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__ = void 0;
|
|
88
|
-
hasRanHack = true;
|
|
89
|
-
return -0;
|
|
90
|
-
}
|
|
91
|
-
} catch {}
|
|
92
|
-
return originalWindowHasOwnProperty.apply(this, arguments);
|
|
93
|
-
},
|
|
94
|
-
configurable: true,
|
|
95
|
-
writable: true
|
|
96
|
-
});
|
|
97
|
-
} catch {
|
|
98
|
-
patchRDTHook(onActive);
|
|
99
|
-
}
|
|
100
|
-
return rdtHook;
|
|
101
|
-
};
|
|
102
|
-
const patchRDTHook = (onActive) => {
|
|
103
|
-
if (onActive) onActiveListeners.add(onActive);
|
|
104
|
-
try {
|
|
105
|
-
const rdtHook = globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__;
|
|
106
|
-
if (!rdtHook) return;
|
|
107
|
-
if (!rdtHook._instrumentationSource) {
|
|
108
|
-
rdtHook.checkDCE = checkDCE;
|
|
109
|
-
rdtHook.supportsFiber = true;
|
|
110
|
-
rdtHook.supportsFlight = true;
|
|
111
|
-
rdtHook.hasUnsupportedRendererAttached = false;
|
|
112
|
-
rdtHook._instrumentationSource = BIPPY_INSTRUMENTATION_STRING;
|
|
113
|
-
rdtHook._instrumentationIsActive = false;
|
|
114
|
-
if (rdtHook.renderers.size) {
|
|
115
|
-
rdtHook._instrumentationIsActive = true;
|
|
116
|
-
onActiveListeners.forEach((listener) => listener());
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
const prevInject = rdtHook.inject;
|
|
120
|
-
if (isReactRefresh(rdtHook) && !isRealReactDevtools()) {
|
|
121
|
-
isReactRefreshOverride = true;
|
|
122
|
-
const nextID = rdtHook.inject({ scheduleRefresh() {} });
|
|
123
|
-
if (nextID) rdtHook._instrumentationIsActive = true;
|
|
124
|
-
}
|
|
125
|
-
rdtHook.inject = (renderer) => {
|
|
126
|
-
const id = prevInject(renderer);
|
|
127
|
-
_renderers.add(renderer);
|
|
128
|
-
rdtHook._instrumentationIsActive = true;
|
|
129
|
-
onActiveListeners.forEach((listener) => listener());
|
|
130
|
-
return id;
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
if (rdtHook.renderers.size || rdtHook._instrumentationIsActive || isReactRefresh()) onActive?.();
|
|
134
|
-
} catch {}
|
|
135
|
-
};
|
|
136
|
-
const hasRDTHook = () => {
|
|
137
|
-
return objectHasOwnProperty.call(globalThis, "__REACT_DEVTOOLS_GLOBAL_HOOK__");
|
|
138
|
-
};
|
|
139
|
-
/**
|
|
140
|
-
* Returns the current React DevTools global hook.
|
|
141
|
-
*/
|
|
142
|
-
const getRDTHook = (onActive) => {
|
|
143
|
-
if (!hasRDTHook()) return installRDTHook(onActive);
|
|
144
|
-
patchRDTHook(onActive);
|
|
145
|
-
return globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__;
|
|
146
|
-
};
|
|
147
|
-
const isClientEnvironment = () => {
|
|
148
|
-
return Boolean(typeof window !== "undefined" && (window.document?.createElement || window.navigator?.product === "ReactNative"));
|
|
149
|
-
};
|
|
150
|
-
/**
|
|
151
|
-
* Usually used purely for side effect
|
|
152
|
-
*/
|
|
153
|
-
const safelyInstallRDTHook = () => {
|
|
154
|
-
try {
|
|
155
|
-
if (isClientEnvironment()) getRDTHook();
|
|
156
|
-
} catch {}
|
|
157
|
-
};
|
|
9
|
+
import { BIPPY_INSTRUMENTATION_STRING$1 as BIPPY_INSTRUMENTATION_STRING, getRDTHook$1 as getRDTHook, hasRDTHook$1 as hasRDTHook, isReactRefresh$1 as isReactRefresh, isRealReactDevtools$1 as isRealReactDevtools } from "./rdt-hook-B2u14A_F.js";
|
|
158
10
|
|
|
159
|
-
//#endregion
|
|
160
11
|
//#region src/install-hook-script-string.ts
|
|
161
12
|
const INSTALL_HOOK_SCRIPT_STRING = "(()=>{try{var t=()=>{};const n=new Map;let o=0;globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__={checkDCE:t,supportsFiber:!0,supportsFlight:!0,hasUnsupportedRendererAttached:!1,renderers:n,onCommitFiberRoot:t,onCommitFiberUnmount:t,onPostCommitFiberRoot:t,inject(t){var e=++o;return n.set(e,t),globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__._instrumentationIsActive=!0,e},_instrumentationIsActive:!1,_script:!0}}catch{}})()";
|
|
162
13
|
|
|
@@ -232,6 +83,12 @@ const isCompositeFiber = (fiber) => {
|
|
|
232
83
|
}
|
|
233
84
|
};
|
|
234
85
|
/**
|
|
86
|
+
* Returns `true` if the two {@link Fiber}s are the same reference
|
|
87
|
+
*/
|
|
88
|
+
const areFiberEqual = (fiberA, fiberB) => {
|
|
89
|
+
return fiberA === fiberB || fiberA.alternate === fiberB || fiberB.alternate === fiberA;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
235
92
|
* Traverses up or down a {@link Fiber}'s contexts, return `true` to stop and select the current and previous context value.
|
|
236
93
|
*/
|
|
237
94
|
const traverseContexts = (fiber, selector) => {
|
|
@@ -664,7 +521,7 @@ const secure = (options, secureOptions = {}) => {
|
|
|
664
521
|
const isUsingRealReactDevtools = isRealReactDevtools();
|
|
665
522
|
const isUsingReactRefresh = isReactRefresh();
|
|
666
523
|
let timeout;
|
|
667
|
-
let
|
|
524
|
+
let isDevelopment = !secureOptions.isProduction;
|
|
668
525
|
options.onActive = () => {
|
|
669
526
|
clearTimeout(timeout);
|
|
670
527
|
let isSecure = true;
|
|
@@ -674,10 +531,8 @@ const secure = (options, secureOptions = {}) => {
|
|
|
674
531
|
const [majorVersion] = renderer.version.split(".");
|
|
675
532
|
if (Number(majorVersion) < (secureOptions.minReactMajorVersion ?? 17)) isSecure = false;
|
|
676
533
|
const buildType = detectReactBuildType(renderer);
|
|
677
|
-
if (buildType
|
|
678
|
-
|
|
679
|
-
if (!secureOptions.dangerouslyRunInProduction) isSecure = false;
|
|
680
|
-
}
|
|
534
|
+
if (buildType === "development") isDevelopment = true;
|
|
535
|
+
else if (!secureOptions.dangerouslyRunInProduction) isSecure = false;
|
|
681
536
|
}
|
|
682
537
|
} catch (err) {
|
|
683
538
|
secureOptions.onError?.(err);
|
|
@@ -721,7 +576,7 @@ const secure = (options, secureOptions = {}) => {
|
|
|
721
576
|
}
|
|
722
577
|
};
|
|
723
578
|
if (!isRDTHookInstalled && !isUsingRealReactDevtools && !isUsingReactRefresh) timeout = setTimeout(() => {
|
|
724
|
-
if (
|
|
579
|
+
if (isDevelopment) secureOptions.onError?.(INSTALL_ERROR);
|
|
725
580
|
stop();
|
|
726
581
|
}, secureOptions.installCheckTimeout ?? 100);
|
|
727
582
|
return options;
|
|
@@ -741,4 +596,4 @@ const onCommitFiberRoot = (handler) => {
|
|
|
741
596
|
};
|
|
742
597
|
|
|
743
598
|
//#endregion
|
|
744
|
-
export {
|
|
599
|
+
export { CONCURRENT_MODE_NUMBER, CONCURRENT_MODE_SYMBOL_STRING, ClassComponentTag, ContextConsumerTag, DEPRECATED_ASYNC_MODE_SYMBOL_STRING, DehydratedSuspenseComponentTag, ELEMENT_TYPE_SYMBOL_STRING, ForwardRefTag, FragmentTag, FunctionComponentTag, HostComponentTag, HostHoistableTag, HostRootTag, HostSingletonTag, HostTextTag, INSTALL_ERROR, INSTALL_HOOK_SCRIPT_STRING, LegacyHiddenComponentTag, MemoComponentTag, OffscreenComponentTag, SimpleMemoComponentTag, SuspenseComponentTag, TRANSITIONAL_ELEMENT_TYPE_SYMBOL_STRING, _fiberRoots, areFiberEqual, createFiberVisitor, detectReactBuildType, didFiberCommit, didFiberRender, fiberIdMap, getDisplayName, getFiberFromHostInstance, getFiberId, getFiberStack, getLatestFiber, getMutatedHostFibers, getNearestHostFiber, getNearestHostFibers, getTimings, getType, hasMemoCache, instrument, isCompositeFiber, isHostFiber, isInstrumentationActive, isValidElement, isValidFiber, mountFiberRecursively, onCommitFiberRoot, secure, setFiberId, shouldFilterFiber, traverseContexts, traverseFiber, traverseProps, traverseRenderedFibers, traverseState, unmountFiber, unmountFiberChildrenRecursively, updateFiberRecursively };
|
|
@@ -1,74 +1,6 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import { ContextDependency, Fiber, FiberRoot, MemoizedState, ReactDevToolsGlobalHook, ReactRenderer } from "./types-DKV6Tlox.js";
|
|
2
|
+
import * as React$1 from "react";
|
|
3
3
|
|
|
4
|
-
//#region src/types.d.ts
|
|
5
|
-
interface ReactDevToolsGlobalHook {
|
|
6
|
-
checkDCE: (fn: unknown) => void;
|
|
7
|
-
supportsFiber: boolean;
|
|
8
|
-
supportsFlight: boolean;
|
|
9
|
-
renderers: Map<number, ReactRenderer>;
|
|
10
|
-
hasUnsupportedRendererAttached: boolean;
|
|
11
|
-
onCommitFiberRoot: (rendererID: number, root: FiberRoot, priority: void | number) => void;
|
|
12
|
-
onCommitFiberUnmount: (rendererID: number, fiber: Fiber$1) => void;
|
|
13
|
-
onPostCommitFiberRoot: (rendererID: number, root: FiberRoot) => void;
|
|
14
|
-
inject: (renderer: ReactRenderer) => number;
|
|
15
|
-
_instrumentationSource?: string;
|
|
16
|
-
_instrumentationIsActive?: boolean;
|
|
17
|
-
_sw?: boolean;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Represents a react-internal Fiber node.
|
|
21
|
-
*/
|
|
22
|
-
type Fiber$1<T = any> = Omit<Fiber, 'stateNode' | 'dependencies' | 'child' | 'sibling' | 'return' | 'alternate' | 'memoizedProps' | 'pendingProps' | 'memoizedState' | 'updateQueue'> & {
|
|
23
|
-
stateNode: T;
|
|
24
|
-
dependencies: Dependencies | null;
|
|
25
|
-
child: Fiber$1 | null;
|
|
26
|
-
sibling: Fiber$1 | null;
|
|
27
|
-
return: Fiber$1 | null;
|
|
28
|
-
alternate: Fiber$1 | null;
|
|
29
|
-
memoizedProps: Props;
|
|
30
|
-
pendingProps: Props;
|
|
31
|
-
memoizedState: MemoizedState;
|
|
32
|
-
updateQueue: {
|
|
33
|
-
lastEffect: Effect | null;
|
|
34
|
-
[key: string]: unknown;
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
interface ReactRenderer {
|
|
38
|
-
version: string;
|
|
39
|
-
bundleType: 0 | 1;
|
|
40
|
-
findFiberByHostInstance?: (hostInstance: unknown) => Fiber$1 | null;
|
|
41
|
-
currentDispatcherRef: React.RefObject<unknown>;
|
|
42
|
-
}
|
|
43
|
-
interface ContextDependency<T> {
|
|
44
|
-
context: ReactContext<T>;
|
|
45
|
-
memoizedValue: T;
|
|
46
|
-
observedBits: number;
|
|
47
|
-
next: ContextDependency<unknown> | null;
|
|
48
|
-
}
|
|
49
|
-
interface Dependencies {
|
|
50
|
-
lanes: Lanes;
|
|
51
|
-
firstContext: ContextDependency<unknown> | null;
|
|
52
|
-
}
|
|
53
|
-
interface Effect {
|
|
54
|
-
next: Effect | null;
|
|
55
|
-
create: (...args: unknown[]) => unknown;
|
|
56
|
-
destroy: ((...args: unknown[]) => unknown) | null;
|
|
57
|
-
deps: unknown[] | null;
|
|
58
|
-
tag: number;
|
|
59
|
-
[key: string]: unknown;
|
|
60
|
-
}
|
|
61
|
-
interface MemoizedState {
|
|
62
|
-
memoizedState: unknown;
|
|
63
|
-
next: MemoizedState | null;
|
|
64
|
-
[key: string]: unknown;
|
|
65
|
-
}
|
|
66
|
-
interface Props {
|
|
67
|
-
[key: string]: unknown;
|
|
68
|
-
}
|
|
69
|
-
declare global {
|
|
70
|
-
var __REACT_DEVTOOLS_GLOBAL_HOOK__: ReactDevToolsGlobalHook | undefined;
|
|
71
|
-
} //#endregion
|
|
72
4
|
//#region src/install-hook-script-string.d.ts
|
|
73
5
|
declare const INSTALL_HOOK_SCRIPT_STRING = "(()=>{try{var t=()=>{};const n=new Map;let o=0;globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__={checkDCE:t,supportsFiber:!0,supportsFlight:!0,hasUnsupportedRendererAttached:!1,renderers:n,onCommitFiberRoot:t,onCommitFiberUnmount:t,onPostCommitFiberRoot:t,inject(t){var e=++o;return n.set(e,t),globalThis.__REACT_DEVTOOLS_GLOBAL_HOOK__._instrumentationIsActive=!0,e},_instrumentationIsActive:!1,_script:!0}}catch{}})()";
|
|
74
6
|
|
|
@@ -120,47 +52,51 @@ declare const DEPRECATED_ASYNC_MODE_SYMBOL_STRING = "Symbol(react.async_mode)";
|
|
|
120
52
|
*
|
|
121
53
|
* @see https://react.dev/reference/react/isValidElement
|
|
122
54
|
*/
|
|
123
|
-
declare const isValidElement: (element: unknown) => element is React$
|
|
55
|
+
declare const isValidElement: (element: unknown) => element is React$1.ReactElement;
|
|
124
56
|
/**
|
|
125
57
|
* Returns `true` if object is a React Fiber.
|
|
126
58
|
*/
|
|
127
|
-
declare const isValidFiber: (fiber: unknown) => fiber is Fiber
|
|
59
|
+
declare const isValidFiber: (fiber: unknown) => fiber is Fiber;
|
|
128
60
|
/**
|
|
129
61
|
* Returns `true` if fiber is a host fiber. Host fibers are DOM nodes in react-dom, `View` in react-native, etc.
|
|
130
62
|
*
|
|
131
63
|
* @see https://reactnative.dev/architecture/glossary#host-view-tree-and-host-view
|
|
132
64
|
*/
|
|
133
|
-
declare const isHostFiber: (fiber: Fiber
|
|
65
|
+
declare const isHostFiber: (fiber: Fiber) => boolean;
|
|
134
66
|
/**
|
|
135
67
|
* Returns `true` if fiber is a composite fiber. Composite fibers are fibers that can render (like functional components, class components, etc.)
|
|
136
68
|
*
|
|
137
69
|
* @see https://reactnative.dev/architecture/glossary#react-composite-components
|
|
138
70
|
*/
|
|
139
|
-
declare const isCompositeFiber: (fiber: Fiber
|
|
71
|
+
declare const isCompositeFiber: (fiber: Fiber) => boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Returns `true` if the two {@link Fiber}s are the same reference
|
|
74
|
+
*/
|
|
75
|
+
declare const areFiberEqual: (fiberA: Fiber, fiberB: Fiber) => boolean;
|
|
140
76
|
/**
|
|
141
77
|
* Traverses up or down a {@link Fiber}'s contexts, return `true` to stop and select the current and previous context value.
|
|
142
78
|
*/
|
|
143
|
-
declare const traverseContexts: (fiber: Fiber
|
|
79
|
+
declare const traverseContexts: (fiber: Fiber, selector: (nextValue: ContextDependency<unknown> | null | undefined, prevValue: ContextDependency<unknown> | null | undefined) => boolean | void) => boolean;
|
|
144
80
|
/**
|
|
145
81
|
* Traverses up or down a {@link Fiber}'s states, return `true` to stop and select the current and previous state value. This stores both state values and effects.
|
|
146
82
|
*/
|
|
147
|
-
declare const traverseState: (fiber: Fiber
|
|
83
|
+
declare const traverseState: (fiber: Fiber, selector: (nextValue: MemoizedState | null | undefined, prevValue: MemoizedState | null | undefined) => boolean | void) => boolean;
|
|
148
84
|
/**
|
|
149
85
|
* Traverses up or down a {@link Fiber}'s props, return `true` to stop and select the current and previous props value.
|
|
150
86
|
*/
|
|
151
|
-
declare const traverseProps: (fiber: Fiber
|
|
87
|
+
declare const traverseProps: (fiber: Fiber, selector: (propName: string, nextValue: unknown, prevValue: unknown) => boolean | void) => boolean;
|
|
152
88
|
/**
|
|
153
89
|
* Returns `true` if the {@link Fiber} has rendered. Note that this does not mean the fiber has rendered in the current commit, just that it has rendered in the past.
|
|
154
90
|
*/
|
|
155
|
-
declare const didFiberRender: (fiber: Fiber
|
|
91
|
+
declare const didFiberRender: (fiber: Fiber) => boolean;
|
|
156
92
|
/**
|
|
157
93
|
* Returns `true` if the {@link Fiber} has committed. Note that this does not mean the fiber has committed in the current commit, just that it has committed in the past.
|
|
158
94
|
*/
|
|
159
|
-
declare const didFiberCommit: (fiber: Fiber
|
|
95
|
+
declare const didFiberCommit: (fiber: Fiber) => boolean;
|
|
160
96
|
/**
|
|
161
97
|
* Returns all host {@link Fiber}s that have committed and rendered.
|
|
162
98
|
*/
|
|
163
|
-
declare const getMutatedHostFibers: (fiber: Fiber
|
|
99
|
+
declare const getMutatedHostFibers: (fiber: Fiber) => Fiber[];
|
|
164
100
|
/**
|
|
165
101
|
* Returns the stack of {@link Fiber}s from the current fiber to the root fiber.
|
|
166
102
|
*
|
|
@@ -169,23 +105,23 @@ declare const getMutatedHostFibers: (fiber: Fiber$1) => Fiber$1[];
|
|
|
169
105
|
* [fiber, fiber.return, fiber.return.return, ...]
|
|
170
106
|
* ```
|
|
171
107
|
*/
|
|
172
|
-
declare const getFiberStack: (fiber: Fiber
|
|
108
|
+
declare const getFiberStack: (fiber: Fiber) => Fiber[];
|
|
173
109
|
/**
|
|
174
110
|
* Returns `true` if the {@link Fiber} should be filtered out during reconciliation.
|
|
175
111
|
*/
|
|
176
|
-
declare const shouldFilterFiber: (fiber: Fiber
|
|
112
|
+
declare const shouldFilterFiber: (fiber: Fiber) => boolean;
|
|
177
113
|
/**
|
|
178
114
|
* Returns the nearest host {@link Fiber} to the current {@link Fiber}.
|
|
179
115
|
*/
|
|
180
|
-
declare const getNearestHostFiber: (fiber: Fiber
|
|
116
|
+
declare const getNearestHostFiber: (fiber: Fiber, ascending?: boolean) => Fiber | null;
|
|
181
117
|
/**
|
|
182
118
|
* Returns all host {@link Fiber}s in the tree that are associated with the current {@link Fiber}.
|
|
183
119
|
*/
|
|
184
|
-
declare const getNearestHostFibers: (fiber: Fiber
|
|
120
|
+
declare const getNearestHostFibers: (fiber: Fiber) => Fiber[];
|
|
185
121
|
/**
|
|
186
122
|
* Traverses up or down a {@link Fiber}, return `true` to stop and select a node.
|
|
187
123
|
*/
|
|
188
|
-
declare const traverseFiber: (fiber: Fiber
|
|
124
|
+
declare const traverseFiber: (fiber: Fiber | null, selector: (node: Fiber) => boolean | void, ascending?: boolean) => Fiber | null;
|
|
189
125
|
/**
|
|
190
126
|
* Returns the timings of the {@link Fiber}.
|
|
191
127
|
*
|
|
@@ -195,18 +131,18 @@ declare const traverseFiber: (fiber: Fiber$1 | null, selector: (node: Fiber$1) =
|
|
|
195
131
|
* console.log(selfTime, totalTime);
|
|
196
132
|
* ```
|
|
197
133
|
*/
|
|
198
|
-
declare const getTimings: (fiber?: Fiber
|
|
134
|
+
declare const getTimings: (fiber?: Fiber | null | undefined) => {
|
|
199
135
|
selfTime: number;
|
|
200
136
|
totalTime: number;
|
|
201
137
|
};
|
|
202
138
|
/**
|
|
203
139
|
* Returns `true` if the {@link Fiber} uses React Compiler's memo cache.
|
|
204
140
|
*/
|
|
205
|
-
declare const hasMemoCache: (fiber: Fiber
|
|
141
|
+
declare const hasMemoCache: (fiber: Fiber) => boolean;
|
|
206
142
|
/**
|
|
207
143
|
* Returns the type (e.g. component definition) of the {@link Fiber}
|
|
208
144
|
*/
|
|
209
|
-
declare const getType: (type: unknown) => React$
|
|
145
|
+
declare const getType: (type: unknown) => React$1.ComponentType<unknown> | null;
|
|
210
146
|
/**
|
|
211
147
|
* Returns the display name of the {@link Fiber} type.
|
|
212
148
|
*/
|
|
@@ -222,16 +158,16 @@ declare const isInstrumentationActive: () => boolean;
|
|
|
222
158
|
/**
|
|
223
159
|
* Returns the latest fiber (since it may be double-buffered).
|
|
224
160
|
*/
|
|
225
|
-
declare const getLatestFiber: (fiber: Fiber
|
|
161
|
+
declare const getLatestFiber: (fiber: Fiber) => Fiber;
|
|
226
162
|
type RenderPhase = 'mount' | 'update' | 'unmount';
|
|
227
|
-
type RenderHandler = <S>(fiber: Fiber
|
|
228
|
-
declare const fiberIdMap: WeakMap<Fiber
|
|
229
|
-
declare const setFiberId: (fiber: Fiber
|
|
230
|
-
declare const getFiberId: (fiber: Fiber
|
|
231
|
-
declare const mountFiberRecursively: (onRender: RenderHandler, firstChild: Fiber
|
|
232
|
-
declare const updateFiberRecursively: (onRender: RenderHandler, nextFiber: Fiber
|
|
233
|
-
declare const unmountFiber: (onRender: RenderHandler, fiber: Fiber
|
|
234
|
-
declare const unmountFiberChildrenRecursively: (onRender: RenderHandler, fiber: Fiber
|
|
163
|
+
type RenderHandler = <S>(fiber: Fiber, phase: RenderPhase, state?: S) => unknown;
|
|
164
|
+
declare const fiberIdMap: WeakMap<Fiber, number>;
|
|
165
|
+
declare const setFiberId: (fiber: Fiber, id?: number) => void;
|
|
166
|
+
declare const getFiberId: (fiber: Fiber) => number;
|
|
167
|
+
declare const mountFiberRecursively: (onRender: RenderHandler, firstChild: Fiber, traverseSiblings: boolean) => void;
|
|
168
|
+
declare const updateFiberRecursively: (onRender: RenderHandler, nextFiber: Fiber, prevFiber: Fiber, parentFiber: Fiber | null) => void;
|
|
169
|
+
declare const unmountFiber: (onRender: RenderHandler, fiber: Fiber) => void;
|
|
170
|
+
declare const unmountFiberChildrenRecursively: (onRender: RenderHandler, fiber: Fiber) => void;
|
|
235
171
|
/**
|
|
236
172
|
* Creates a fiber visitor function. Must pass a fiber root and a render handler.
|
|
237
173
|
* @example
|
|
@@ -248,10 +184,10 @@ declare const createFiberVisitor: ({
|
|
|
248
184
|
}: {
|
|
249
185
|
onRender: RenderHandler;
|
|
250
186
|
onError: (error: unknown) => unknown;
|
|
251
|
-
}) => (<S>(_rendererID: number, root: FiberRoot | Fiber
|
|
187
|
+
}) => (<S>(_rendererID: number, root: FiberRoot | Fiber, _state?: S) => void);
|
|
252
188
|
interface InstrumentationOptions {
|
|
253
189
|
onCommitFiberRoot?: (rendererID: number, root: FiberRoot, priority: void | number) => unknown;
|
|
254
|
-
onCommitFiberUnmount?: (rendererID: number, fiber: Fiber
|
|
190
|
+
onCommitFiberUnmount?: (rendererID: number, fiber: Fiber) => unknown;
|
|
255
191
|
onPostCommitFiberRoot?: (rendererID: number, root: FiberRoot) => unknown;
|
|
256
192
|
onActive?: () => unknown;
|
|
257
193
|
name?: string;
|
|
@@ -269,7 +205,7 @@ interface InstrumentationOptions {
|
|
|
269
205
|
* });
|
|
270
206
|
*/
|
|
271
207
|
declare const instrument: (options: InstrumentationOptions) => ReactDevToolsGlobalHook;
|
|
272
|
-
declare const getFiberFromHostInstance: <T>(hostInstance: T) => Fiber
|
|
208
|
+
declare const getFiberFromHostInstance: <T>(hostInstance: T) => Fiber | null;
|
|
273
209
|
declare const INSTALL_ERROR: Error;
|
|
274
210
|
declare const _fiberRoots: Set<any>;
|
|
275
211
|
declare const secure: (options: InstrumentationOptions, secureOptions?: {
|
|
@@ -290,4 +226,4 @@ declare const secure: (options: InstrumentationOptions, secureOptions?: {
|
|
|
290
226
|
declare const onCommitFiberRoot: (handler: (root: FiberRoot) => void) => ReactDevToolsGlobalHook;
|
|
291
227
|
|
|
292
228
|
//#endregion
|
|
293
|
-
export { BIPPY_INSTRUMENTATION_STRING,
|
|
229
|
+
export { BIPPY_INSTRUMENTATION_STRING, CONCURRENT_MODE_NUMBER as CONCURRENT_MODE_NUMBER$1, CONCURRENT_MODE_SYMBOL_STRING as CONCURRENT_MODE_SYMBOL_STRING$1, ClassComponentTag as ClassComponentTag$1, ContextConsumerTag as ContextConsumerTag$1, DEPRECATED_ASYNC_MODE_SYMBOL_STRING as DEPRECATED_ASYNC_MODE_SYMBOL_STRING$1, DehydratedSuspenseComponentTag as DehydratedSuspenseComponentTag$1, ELEMENT_TYPE_SYMBOL_STRING as ELEMENT_TYPE_SYMBOL_STRING$1, ForwardRefTag as ForwardRefTag$1, FragmentTag as FragmentTag$1, FunctionComponentTag as FunctionComponentTag$1, HostComponentTag as HostComponentTag$1, HostHoistableTag as HostHoistableTag$1, HostRootTag as HostRootTag$1, HostSingletonTag as HostSingletonTag$1, HostTextTag as HostTextTag$1, INSTALL_ERROR as INSTALL_ERROR$1, INSTALL_HOOK_SCRIPT_STRING as INSTALL_HOOK_SCRIPT_STRING$1, InstrumentationOptions, LegacyHiddenComponentTag as LegacyHiddenComponentTag$1, MemoComponentTag as MemoComponentTag$1, OffscreenComponentTag as OffscreenComponentTag$1, RenderHandler, RenderPhase, SimpleMemoComponentTag as SimpleMemoComponentTag$1, SuspenseComponentTag as SuspenseComponentTag$1, TRANSITIONAL_ELEMENT_TYPE_SYMBOL_STRING as TRANSITIONAL_ELEMENT_TYPE_SYMBOL_STRING$1, _fiberRoots as _fiberRoots$1, _renderers, areFiberEqual as areFiberEqual$1, createFiberVisitor as createFiberVisitor$1, detectReactBuildType as detectReactBuildType$1, didFiberCommit as didFiberCommit$1, didFiberRender as didFiberRender$1, fiberIdMap as fiberIdMap$1, getDisplayName as getDisplayName$1, getFiberFromHostInstance as getFiberFromHostInstance$1, getFiberId as getFiberId$1, getFiberStack as getFiberStack$1, getLatestFiber as getLatestFiber$1, getMutatedHostFibers as getMutatedHostFibers$1, getNearestHostFiber as getNearestHostFiber$1, getNearestHostFibers as getNearestHostFibers$1, getRDTHook, getTimings as getTimings$1, getType as getType$1, hasMemoCache as hasMemoCache$1, hasRDTHook, installRDTHook, instrument as instrument$1, isClientEnvironment, isCompositeFiber as isCompositeFiber$1, isHostFiber as isHostFiber$1, isInstrumentationActive as isInstrumentationActive$1, isReactRefresh, isRealReactDevtools, isValidElement as isValidElement$1, isValidFiber as isValidFiber$1, mountFiberRecursively as mountFiberRecursively$1, onCommitFiberRoot as onCommitFiberRoot$1, patchRDTHook, safelyInstallRDTHook, secure as secure$1, setFiberId as setFiberId$1, shouldFilterFiber as shouldFilterFiber$1, traverseContexts as traverseContexts$1, traverseFiber as traverseFiber$1, traverseProps as traverseProps$1, traverseRenderedFibers as traverseRenderedFibers$1, traverseState as traverseState$1, unmountFiber as unmountFiber$1, unmountFiberChildrenRecursively as unmountFiberChildrenRecursively$1, updateFiberRecursively as updateFiberRecursively$1, version };
|