@bugsee/react-native 0.0.0-stage → 7.0.0-beta1
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/BugseeReactNative.podspec +95 -0
- package/LICENSE +21 -0
- package/README.md +552 -2
- package/android/build.gradle +162 -0
- package/android/consumer-rules.pro +2 -0
- package/android/src/main/AndroidManifest.xml +33 -0
- package/android/src/main/java/com/bugsee/reactnative/AppearanceBridge.java +82 -0
- package/android/src/main/java/com/bugsee/reactnative/AttributeBridge.java +209 -0
- package/android/src/main/java/com/bugsee/reactnative/BreadcrumbFilterBridge.java +443 -0
- package/android/src/main/java/com/bugsee/reactnative/BridgeJson.java +168 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeModule.java +1869 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeOptionEnums.java +136 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseePackage.java +42 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeReactNativeWrapper.java +200 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeStatusMapper.java +66 -0
- package/android/src/main/java/com/bugsee/reactnative/BugseeTokens.java +22 -0
- package/android/src/main/java/com/bugsee/reactnative/ConsoleEchoDedup.java +202 -0
- package/android/src/main/java/com/bugsee/reactnative/CreatedReports.java +127 -0
- package/android/src/main/java/com/bugsee/reactnative/DataRequestBridge.java +375 -0
- package/android/src/main/java/com/bugsee/reactnative/ExceptionBridge.java +88 -0
- package/android/src/main/java/com/bugsee/reactnative/ExceptionExecutors.java +33 -0
- package/android/src/main/java/com/bugsee/reactnative/LogFilterBridge.java +375 -0
- package/android/src/main/java/com/bugsee/reactnative/NetworkEvents.java +227 -0
- package/android/src/main/java/com/bugsee/reactnative/NetworkFilterBridge.java +498 -0
- package/android/src/main/java/com/bugsee/reactnative/PluginEndpoint.java +48 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactNativeWebException.java +19 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactNativeWrapperInitProvider.java +61 -0
- package/android/src/main/java/com/bugsee/reactnative/ReactRootOriginTracker.java +867 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportArgs.java +58 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportHandlerBridge.java +336 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportHandlerDeadlines.java +57 -0
- package/android/src/main/java/com/bugsee/reactnative/ReportOps.java +287 -0
- package/android/src/main/java/com/bugsee/reactnative/SecureRectanglePulls.java +113 -0
- package/android/src/main/java/com/bugsee/reactnative/SecureRectangleStore.java +692 -0
- package/android/src/main/java/com/bugsee/reactnative/SpanHandles.java +143 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperChannelHolder.java +137 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperEventBus.java +110 -0
- package/android/src/main/java/com/bugsee/reactnative/WrapperRegistrar.java +54 -0
- package/app.plugin.js +4 -0
- package/ios/BGSRNConsoleCapture.h +52 -0
- package/ios/BGSRNConsoleCapture.mm +344 -0
- package/ios/BugseeModule.h +25 -0
- package/ios/BugseeModule.mm +2728 -0
- package/ios/Package.swift +71 -0
- package/ios/Support/Package.resolved +14 -0
- package/ios/Support/Package.swift +44 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNAttributes.m +52 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReportOps.m +236 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReports.m +184 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNDataRequestBridge.m +431 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNErrorMessage.m +40 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNEventBus.m +70 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNExceptions.m +63 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNGuardedEmit.mm +32 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNJSON.m +40 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNLaunchHold.m +147 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNMainThread.m +23 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkEvents.m +159 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkFilter.m +155 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNPluginEndpoint.m +21 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReactRootOriginTracker.m +63 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReactWindow.m +251 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportArgs.m +47 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportDeadlines.m +8 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportHandlerBridge.m +308 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNReportOps.m +345 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSecureRectangles.m +508 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSettleOnce.m +62 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNSpanHandles.m +136 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNStatusMapper.m +18 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNTokens.m +9 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNValues.m +5 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapper.m +54 -0
- package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapperChannelHolder.m +59 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNAttributes.h +63 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReportOps.h +51 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReports.h +81 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNDataRequestBridge.h +118 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNErrorMessage.h +30 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNEventBus.h +45 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNExceptions.h +31 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNGuardedEmit.h +31 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNJSON.h +25 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNLaunchHold.h +86 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNMainThread.h +32 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkEvents.h +28 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkFilter.h +28 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNPluginEndpoint.h +17 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactRootOriginTracker.h +48 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactWindow.h +135 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportArgs.h +17 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportDeadlines.h +37 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportHandlerBridge.h +94 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportOps.h +86 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSecureRectangles.h +198 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSettleOnce.h +25 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSpanHandles.h +49 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNStatusMapper.h +26 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNTokens.h +14 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNValues.h +18 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapper.h +40 -0
- package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapperChannelHolder.h +74 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNAttributesTests.m +194 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportOpsTests.m +274 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportsTests.m +240 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNDataRequestBridgeTests.m +685 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNErrorMessageTests.m +102 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNEventBusTests.m +136 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNExceptionsTests.m +68 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.h +41 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.m +166 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNGuardedEmitTests.mm +85 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNJSONTests.m +281 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNLaunchHoldTests.m +230 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNMainThreadTests.m +97 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkEventsTests.m +99 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkFilterTests.m +134 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNPluginEndpointTests.m +38 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactRootOriginTrackerTests.m +210 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactWindowTests.m +548 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportArgsTests.m +51 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportDeadlinesTests.m +22 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportHandlerBridgeTests.m +382 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportOpsTests.m +295 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSecureRectanglesTests.m +568 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSettleOnceTests.m +134 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSpanHandlesTests.m +153 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNStatusMapperTests.m +81 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNValuesTests.m +32 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperChannelHolderTests.m +205 -0
- package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperTests.m +66 -0
- package/ios/react-native-spm-prefix.h +10 -0
- package/native-versions.json +10 -0
- package/package.json +62 -3
- package/plugin/build/bundle-phase.d.ts +41 -0
- package/plugin/build/bundle-phase.js +116 -0
- package/plugin/build/bundle-phase.js.map +1 -0
- package/plugin/build/dsym-script.d.ts +32 -0
- package/plugin/build/dsym-script.js +159 -0
- package/plugin/build/dsym-script.js.map +1 -0
- package/plugin/build/endpoint.d.ts +30 -0
- package/plugin/build/endpoint.js +69 -0
- package/plugin/build/endpoint.js.map +1 -0
- package/plugin/build/gradle.d.ts +65 -0
- package/plugin/build/gradle.js +1066 -0
- package/plugin/build/gradle.js.map +1 -0
- package/plugin/build/index.d.ts +85 -0
- package/plugin/build/index.js +217 -0
- package/plugin/build/index.js.map +1 -0
- package/plugin/build/manifest.d.ts +48 -0
- package/plugin/build/manifest.js +69 -0
- package/plugin/build/manifest.js.map +1 -0
- package/plugin/build/native-versions.baked.json +4 -0
- package/plugin/build/native-versions.d.ts +10 -0
- package/plugin/build/native-versions.js +27 -0
- package/plugin/build/native-versions.js.map +1 -0
- package/plugin/build/pbx-string.d.ts +8 -0
- package/plugin/build/pbx-string.js +31 -0
- package/plugin/build/pbx-string.js.map +1 -0
- package/plugin/build/podfile.d.ts +3 -0
- package/plugin/build/podfile.js +28 -0
- package/plugin/build/podfile.js.map +1 -0
- package/plugin/build/properties.d.ts +19 -0
- package/plugin/build/properties.js +41 -0
- package/plugin/build/properties.js.map +1 -0
- package/plugin/build/scheme.d.ts +20 -0
- package/plugin/build/scheme.js +107 -0
- package/plugin/build/scheme.js.map +1 -0
- package/react-native.config.js +26 -0
- package/scripts/bugsee-sourcemaps.gradle +201 -0
- package/scripts/bugsee-xcode.sh +83 -0
- package/scripts/compose-then-inject.js +113 -0
- package/scripts/hermes-sourcemaps.js +634 -0
- package/scripts/hermesc-preserve-js.cmd +6 -0
- package/scripts/hermesc-preserve-js.js +200 -0
- package/scripts/hermesc-preserve-js.sh +7 -0
- package/src/NativeBugsee.ts +622 -0
- package/src/apm/notify.ts +58 -0
- package/src/apm/span.ts +403 -0
- package/src/apm/types.ts +57 -0
- package/src/appearance/report.ts +171 -0
- package/src/architecture.ts +48 -0
- package/src/attributes/errors.ts +39 -0
- package/src/attributes/validate.ts +150 -0
- package/src/breadcrumbs/add.ts +58 -0
- package/src/breadcrumbs/data.ts +33 -0
- package/src/breadcrumbs/filter.ts +215 -0
- package/src/breadcrumbs/types.ts +64 -0
- package/src/bridge/json.ts +110 -0
- package/src/console/capture.ts +180 -0
- package/src/console/dedup.ts +175 -0
- package/src/data/validate.ts +259 -0
- package/src/errorName.ts +32 -0
- package/src/exceptions/ErrorBoundary.tsx +92 -0
- package/src/exceptions/RootErrorReporter.tsx +61 -0
- package/src/exceptions/debugIds.ts +118 -0
- package/src/exceptions/handlers.ts +236 -0
- package/src/exceptions/options.ts +85 -0
- package/src/exceptions/payload.ts +456 -0
- package/src/exceptions/report.ts +170 -0
- package/src/exceptions/sha1.ts +148 -0
- package/src/exceptions/stack.ts +355 -0
- package/src/index.ts +944 -0
- package/src/logs/filter.ts +90 -0
- package/src/logs/log.ts +36 -0
- package/src/network/add.ts +165 -0
- package/src/network/filter.ts +198 -0
- package/src/options/AndroidLaunchOptions.ts +78 -0
- package/src/options/BugseeLaunchOptions.ts +190 -0
- package/src/options/IOSLaunchOptions.ts +57 -0
- package/src/options/android-options-manifest.json +646 -0
- package/src/options/createDefaultLaunchOptions.ts +29 -0
- package/src/options/endpoint.ts +58 -0
- package/src/options/enums.ts +104 -0
- package/src/options/ios-enums.json +19 -0
- package/src/options/keys.ts +39 -0
- package/src/options/option-enums.json +34 -0
- package/src/options/option-keys.json +107 -0
- package/src/report/BugseeReport.ts +264 -0
- package/src/report/CreatedReport.ts +127 -0
- package/src/report/dispatcher.ts +95 -0
- package/src/report/errors.ts +48 -0
- package/src/report/fields.ts +40 -0
- package/src/report/types.ts +157 -0
- package/src/report/validate.ts +197 -0
- package/src/secure/BugseeSecure.tsx +202 -0
- package/src/secure/ancestry.ts +622 -0
- package/src/secure/drivers.ts +342 -0
- package/src/secure/followEvents.ts +57 -0
- package/src/secure/hold.ts +99 -0
- package/src/secure/measureLoop.ts +323 -0
- package/src/secure/nativeAnimation.ts +1005 -0
- package/src/secure/rectangles.ts +93 -0
- package/src/secure/registry.ts +237 -0
- package/src/secure/surface.ts +83 -0
- package/src/secure/tracker.ts +723 -0
- package/src/secure/transition.ts +488 -0
- package/src/secure/unit.ts +22 -0
- package/src/status.ts +16 -0
- package/src/version.ts +9 -0
- package/src/viewtree/anchor.tsx +105 -0
- package/src/viewtree/constants.ts +20 -0
- package/src/viewtree/fiber.ts +251 -0
- package/src/viewtree/requests.ts +347 -0
- package/src/viewtree/walk.ts +902 -0
- package/src/wrapper/channel.ts +33 -0
- package/src/wrapper/collect.ts +52 -0
- package/src/wrapper/events.ts +45 -0
- package/src/wrapper/identity.ts +54 -0
- package/src/wrapper/lifecycle-events.ts +89 -0
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The ONLY module in this package that reads React or React Native
|
|
3
|
+
* internals. Everything else in `viewtree/` (starting with `walk.ts`) works
|
|
4
|
+
* against the `FiberLike` shape declared here and never imports `react` or
|
|
5
|
+
* `react-native` itself, so the privacy-sensitive tree walk stays testable
|
|
6
|
+
* with plain fake objects and stays reviewable without React's own source.
|
|
7
|
+
*
|
|
8
|
+
* `scripts/check-rn-compat.sh` greps React Native's sources for the exact
|
|
9
|
+
* internals this file depends on, on every supported minor version, so a
|
|
10
|
+
* renderer change that would silently break this file fails CI instead.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
// React's own fiber tags (react-reconciler/src/ReactWorkTags.js). Only the
|
|
14
|
+
// tags this package's walk needs to recognise are listed; the numeric values
|
|
15
|
+
// are the ones React itself assigns and have been stable across the
|
|
16
|
+
// supported versions for years. The compat script's internals guard pins two
|
|
17
|
+
// of them at a distinctive, version-independent call site each — `SimpleMemo`
|
|
18
|
+
// (15, where a plain-function `memo()` downgrades to it) and `Offscreen` (22,
|
|
19
|
+
// compared directly against a fiber's `.tag`) — not all seventeen; the rest
|
|
20
|
+
// rely on React's own tag numbering never being renumbered wholesale, the
|
|
21
|
+
// same assumption every consumer of these internals makes.
|
|
22
|
+
export const FiberTag = {
|
|
23
|
+
FunctionComponent: 0,
|
|
24
|
+
ClassComponent: 1,
|
|
25
|
+
HostRoot: 3,
|
|
26
|
+
HostPortal: 4,
|
|
27
|
+
HostComponent: 5,
|
|
28
|
+
HostText: 6,
|
|
29
|
+
Fragment: 7,
|
|
30
|
+
Mode: 8,
|
|
31
|
+
ContextConsumer: 9,
|
|
32
|
+
ContextProvider: 10,
|
|
33
|
+
ForwardRef: 11,
|
|
34
|
+
Profiler: 12,
|
|
35
|
+
Suspense: 13,
|
|
36
|
+
Memo: 14,
|
|
37
|
+
SimpleMemo: 15,
|
|
38
|
+
Offscreen: 22,
|
|
39
|
+
LegacyHidden: 23,
|
|
40
|
+
} as const;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The subset of a real React Fiber's fields this package reads. Deliberately
|
|
44
|
+
* narrower than React's own (unexported) `Fiber` type: everything the walk
|
|
45
|
+
* needs and nothing it doesn't, so a fake fiber tree in a test is exactly as
|
|
46
|
+
* capable as a real one for this package's purposes.
|
|
47
|
+
*
|
|
48
|
+
* `child`/`sibling`/`return` are typed as `FiberLike | null`, but nothing in
|
|
49
|
+
* `walk.ts` trusts that a real or malformed fiber actually honours it —
|
|
50
|
+
* `undefined`, or a non-object value entirely, is tolerated the same as
|
|
51
|
+
* `null` throughout, since only React's own reconciler is obliged to keep
|
|
52
|
+
* that promise and this package reads fibers it did not build.
|
|
53
|
+
*/
|
|
54
|
+
export interface FiberLike {
|
|
55
|
+
tag: number;
|
|
56
|
+
type: unknown;
|
|
57
|
+
elementType?: unknown;
|
|
58
|
+
child: FiberLike | null;
|
|
59
|
+
sibling: FiberLike | null;
|
|
60
|
+
return: FiberLike | null;
|
|
61
|
+
memoizedProps: unknown;
|
|
62
|
+
/**
|
|
63
|
+
* Only ever inspected on an `Offscreen`/`LegacyHidden` fiber, to tell a
|
|
64
|
+
* hidden subtree from a visible one: React's `updateOffscreenComponent`
|
|
65
|
+
* sets this to a `{ baseLanes, cachePool }` object while `mode === "hidden"`
|
|
66
|
+
* and to `null` otherwise (both current and stale-then-cleared cases) —
|
|
67
|
+
* the same field React's own commit phase relies on, not a prop and not
|
|
68
|
+
* the `_visibility` bit some renderer versions also keep on `stateNode`.
|
|
69
|
+
* See `walk.ts`'s `isHidden`.
|
|
70
|
+
*/
|
|
71
|
+
memoizedState: unknown;
|
|
72
|
+
stateNode: unknown;
|
|
73
|
+
/**
|
|
74
|
+
* The other fiber of the pair React swaps between the committed tree and
|
|
75
|
+
* the one being rendered. Only `secure/ancestry.ts` reads it, to find which
|
|
76
|
+
* of the two is committed.
|
|
77
|
+
*/
|
|
78
|
+
alternate?: FiberLike | null;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
export interface WindowRect {
|
|
82
|
+
x: number;
|
|
83
|
+
y: number;
|
|
84
|
+
width: number;
|
|
85
|
+
height: number;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* A host public instance (what a `ref` to a host component resolves to, e.g.
|
|
90
|
+
* a `View`) carries the fiber it was created for on `__internalInstanceHandle`
|
|
91
|
+
* — assigned in `ReactNativeElement.js` on every supported version, and also
|
|
92
|
+
* in `ReactFabricHostComponent.js` on React Native 0.81 (removed outright,
|
|
93
|
+
* not folded elsewhere, by 0.87 — `ReactFabricPublicInstance.js` only ever
|
|
94
|
+
* *reads* the field). Both assignment sites are covered by the compat
|
|
95
|
+
* script's internals guard, which checks for an actual assignment, not a
|
|
96
|
+
* read or a type declaration. Walking `.return` from there to the nearest
|
|
97
|
+
* `HostRoot` fiber and reading that fiber's `stateNode` recovers the
|
|
98
|
+
* `FiberRoot`, whose `.current` is the tree's current root fiber — the
|
|
99
|
+
* argument `buildViewTree` (`walk.ts`) walks from.
|
|
100
|
+
*
|
|
101
|
+
* Never throws and never loops forever: a missing, non-object or cyclic
|
|
102
|
+
* `.return` chain (all of which would be a bug elsewhere, never legitimate)
|
|
103
|
+
* ends the walk with `null` rather than a `TypeError` or a hang. Nor does a
|
|
104
|
+
* *hostile* `publicInstance` — one whose fields are throwing getters, or a
|
|
105
|
+
* revoked `Proxy` — because `Task 6.4`'s exported `registerAnchor(instance:
|
|
106
|
+
* unknown)` calls this on whatever gets registered, and its own spec turns
|
|
107
|
+
* any throw here into a `null` reply for every root, for as long as that one
|
|
108
|
+
* bad object stays registered. See the `try`/`catch` in `fiberRootOf` itself.
|
|
109
|
+
*/
|
|
110
|
+
const FIBER_ROOT_RETURN_CHAIN_CAP = 10_000;
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* True for a real object, `false` for `null`, `undefined` and every
|
|
114
|
+
* primitive — a single, once-tested answer to "is this safe to treat as a
|
|
115
|
+
* fiber/handle/state node", instead of a `=== null || typeof !== 'object'`
|
|
116
|
+
* (or `== null || …`) repeated at each of `fiberRootOf`'s four checks, which
|
|
117
|
+
* would leave each repetition's own redundancy to prove on its own.
|
|
118
|
+
*/
|
|
119
|
+
function isObject(value: unknown): value is object {
|
|
120
|
+
return value !== null && typeof value === 'object';
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function fiberRootOf(publicInstance: unknown): { current: FiberLike } | null {
|
|
124
|
+
// Both defences stay, deliberately: the explicit `isObject` checks below
|
|
125
|
+
// make every *plain*, well-formed-but-wrong-shaped input safe on their
|
|
126
|
+
// own (a missing/non-object handle, a `.return` chain that never reaches
|
|
127
|
+
// a HostRoot, a HostRoot with no usable `stateNode`), and each is tested
|
|
128
|
+
// in isolation. The outer `try`/`catch` is for the input those checks
|
|
129
|
+
// cannot see coming: a throwing getter on any of `__internalInstanceHandle`
|
|
130
|
+
// / `.tag` / `.return` / `.stateNode`, a `Proxy` whose `get` trap throws,
|
|
131
|
+
// or a revoked `Proxy` used as `publicInstance` or as the handle itself —
|
|
132
|
+
// none of which are "a fiber", but all of which this function's public
|
|
133
|
+
// contract ("never throws") must still survive, since `Task 6.4`'s
|
|
134
|
+
// `registerAnchor(instance: unknown)` calls this on whatever a consumer
|
|
135
|
+
// registers. A round of review found this function still threw on exactly
|
|
136
|
+
// those inputs when the `try` was left off in favour of the explicit
|
|
137
|
+
// checks alone (see the equivalent-mutant note below) — a public-surface
|
|
138
|
+
// "never throws" contract is worth more than a few fully-equivalent
|
|
139
|
+
// mutants inside the checks the `try` now also backstops.
|
|
140
|
+
try {
|
|
141
|
+
if (!isObject(publicInstance)) {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const handle = (publicInstance as { __internalInstanceHandle?: unknown }).__internalInstanceHandle;
|
|
146
|
+
if (!isObject(handle)) {
|
|
147
|
+
return null;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
let fiber = handle as FiberLike;
|
|
151
|
+
for (let steps = 0; fiber.tag !== FiberTag.HostRoot; steps += 1) {
|
|
152
|
+
if (steps >= FIBER_ROOT_RETURN_CHAIN_CAP) {
|
|
153
|
+
// A `.return` chain this long is a cycle (or some other corruption),
|
|
154
|
+
// never a real tree: React's own depth cap is nowhere near this.
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
// `isObject`, not just `!== null`: a malformed fiber's `.return` being
|
|
158
|
+
// `undefined` (rather than the `null` React itself would leave at the
|
|
159
|
+
// top), or any other non-object value, ends the walk the same way, not
|
|
160
|
+
// with a `TypeError` on the next iteration.
|
|
161
|
+
const parent = fiber.return;
|
|
162
|
+
if (!isObject(parent)) {
|
|
163
|
+
return null;
|
|
164
|
+
}
|
|
165
|
+
fiber = parent;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const stateNode = fiber.stateNode;
|
|
169
|
+
if (!isObject(stateNode)) {
|
|
170
|
+
return null;
|
|
171
|
+
}
|
|
172
|
+
const current = (stateNode as { current?: unknown }).current;
|
|
173
|
+
if (!isObject(current)) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
return stateNode as { current: FiberLike };
|
|
177
|
+
} catch {
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
type MeasureInWindowCallback = (x: number, y: number, width: number, height: number) => void;
|
|
183
|
+
|
|
184
|
+
interface RendererProxyLike {
|
|
185
|
+
// Declared as callable, not optional: if the real module ever disagrees
|
|
186
|
+
// (missing, or some other shape), calling it throws, and the `try` below
|
|
187
|
+
// is what turns that into a clean `null` — a type check ahead of the call
|
|
188
|
+
// would only ever be re-deciding the same thing the `try` already decides.
|
|
189
|
+
getPublicInstanceFromInternalInstanceHandle: (fiber: unknown) => unknown;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Measures a host fiber's on-screen rectangle the same way a `ref.current`
|
|
194
|
+
* would (`measureInWindow`), but from the fiber alone — the wrapper never
|
|
195
|
+
* holds a `ref` to the app's own views. `RendererProxy` (re-exporting
|
|
196
|
+
* `RendererImplementation`, per the compat script's guard) is the supported
|
|
197
|
+
* way to go from an internal instance handle to the public instance that
|
|
198
|
+
* carries `measureInWindow`. The rectangle is the main React root's window,
|
|
199
|
+
* the same space `<BugseeSecure>` publishes. A host inside a React Native
|
|
200
|
+
* `<Modal>` (its own window; an Android `Dialog`) does not line up with the
|
|
201
|
+
* native tree.
|
|
202
|
+
*
|
|
203
|
+
* Required lazily, not imported at module load: React Native ships this
|
|
204
|
+
* module as untranspiled Flow/ESM source, meant to be read by Metro, and
|
|
205
|
+
* loading it under plain Jest throws a SyntaxError. Every caller of this
|
|
206
|
+
* function mocks the module; nothing that merely imports `FiberTag` or
|
|
207
|
+
* `FiberLike` from this file should have to.
|
|
208
|
+
*/
|
|
209
|
+
export function measureHostFiber(fiber: FiberLike): WindowRect | null {
|
|
210
|
+
// Two `try` blocks, each around exactly one call into code this module
|
|
211
|
+
// does not control: loading the module and asking it for the public
|
|
212
|
+
// instance, then asking that instance to measure itself. Nothing here
|
|
213
|
+
// pre-checks the shape of what comes back first — a bad shape throws when
|
|
214
|
+
// used a line later, inside the very next `try`, which is indistinguishable
|
|
215
|
+
// from the renderer itself throwing and must be handled the same way
|
|
216
|
+
// regardless.
|
|
217
|
+
let publicInstance: unknown;
|
|
218
|
+
try {
|
|
219
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports -- see the doc comment above: this must stay a lazy require.
|
|
220
|
+
const rendererProxy: RendererProxyLike = require('react-native/Libraries/ReactNative/RendererProxy');
|
|
221
|
+
publicInstance = rendererProxy.getPublicInstanceFromInternalInstanceHandle(fiber);
|
|
222
|
+
} catch {
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const measurable = publicInstance as { measureInWindow: (callback: MeasureInWindowCallback) => void };
|
|
227
|
+
|
|
228
|
+
// Pinned behaviour, tested explicitly (not merely an untested consequence
|
|
229
|
+
// of the `catch`): if the callback fires synchronously with a good rect
|
|
230
|
+
// and `measureInWindow` *itself* then throws — some cleanup step inside
|
|
231
|
+
// the renderer failing after already reporting a measurement — this still
|
|
232
|
+
// returns `null`, not the rect the callback captured. A mid-call throw
|
|
233
|
+
// means the renderer's own state around this measurement is not something
|
|
234
|
+
// this module trusts, and there is exactly one "unmeasurable" outcome for
|
|
235
|
+
// every way that call can go wrong, not a special case for "wrong, but
|
|
236
|
+
// only after telling us something first".
|
|
237
|
+
let delivered = false;
|
|
238
|
+
let result: WindowRect | null = null;
|
|
239
|
+
try {
|
|
240
|
+
measurable.measureInWindow((x, y, width, height) => {
|
|
241
|
+
delivered = true;
|
|
242
|
+
if (Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(width) && Number.isFinite(height)) {
|
|
243
|
+
result = { x, y, width, height };
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
} catch {
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
return delivered ? result : null;
|
|
251
|
+
}
|
|
@@ -0,0 +1,347 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The JS side of the native SDK's `'vh'` (view hierarchy) data request:
|
|
3
|
+
* tracks which anchors (`anchor.tsx`'s `wrap`) are mounted, turns
|
|
4
|
+
* `onDataRequest` on and off with them, and answers every delivery by walking
|
|
5
|
+
* the fiber trees those anchors sit in (`./walk`'s `buildViewTree`) and
|
|
6
|
+
* replying with the result.
|
|
7
|
+
*
|
|
8
|
+
* The only module besides `anchor.tsx` and `./fiber`/`./walk` that knows
|
|
9
|
+
* about the view tree at all; everything platform- or React-specific that
|
|
10
|
+
* `WalkEnv` needs (the renderer's measurement, the secure boundary and
|
|
11
|
+
* wrapper identities, the platform's unit and scale, a clock) is assembled
|
|
12
|
+
* here, once per request, from real `react-native` and this package's own
|
|
13
|
+
* modules -- `walk.ts` itself stays free of both.
|
|
14
|
+
*/
|
|
15
|
+
import { Platform } from 'react-native';
|
|
16
|
+
import NativeBugsee from '../NativeBugsee';
|
|
17
|
+
import { RootErrorReporter } from '../exceptions/RootErrorReporter';
|
|
18
|
+
import { BugseeSecure } from '../secure/BugseeSecure';
|
|
19
|
+
import { nativeTagOfFiber } from '../secure/surface';
|
|
20
|
+
import { secureRectangleScale } from '../secure/unit';
|
|
21
|
+
import { VH_ANCHOR_NATIVE_ID } from './constants';
|
|
22
|
+
import { errorName } from '../errorName';
|
|
23
|
+
import { FiberTag, fiberRootOf, measureHostFiber } from './fiber';
|
|
24
|
+
import type { FiberLike } from './fiber';
|
|
25
|
+
import { buildViewTree } from './walk';
|
|
26
|
+
import type { WalkEnv } from './walk';
|
|
27
|
+
|
|
28
|
+
/** The only data-request type this version answers; native answers every other type itself. */
|
|
29
|
+
export const VH_DATA_TYPE = 'vh';
|
|
30
|
+
|
|
31
|
+
interface DataRequestEvent {
|
|
32
|
+
requestId: string;
|
|
33
|
+
type: string;
|
|
34
|
+
originX: number;
|
|
35
|
+
originY: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Every public instance `registerAnchor` currently holds, in registration
|
|
40
|
+
* order. A `Set`, not a count: `unregisterAnchor` must remove the exact
|
|
41
|
+
* instance it was given, and two anchors in the same surface must still walk
|
|
42
|
+
* that surface's root only once (`currentRoots` dedupes by `FiberRoot`
|
|
43
|
+
* identity, not by anchor count).
|
|
44
|
+
*/
|
|
45
|
+
const anchors = new Set<unknown>();
|
|
46
|
+
|
|
47
|
+
/** Set exactly once, the first time any anchor ever registers, and never unset -- the subscription outlives every individual anchor mounting and unmounting. */
|
|
48
|
+
let subscribedToDataRequests = false;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Every function `wrap` has ever returned, so `isWrapper` can recognise ANY
|
|
52
|
+
* of them by identity even though `wrap` may be called more than once (and
|
|
53
|
+
* therefore produce more than one distinct function). A `WeakSet` rather than
|
|
54
|
+
* comparing against one remembered reference, the way `isSecureBoundary`
|
|
55
|
+
* compares against the single `BugseeSecure` function -- there is only ever
|
|
56
|
+
* one `BugseeSecure`, but a fresh component is minted on every `wrap` call.
|
|
57
|
+
*
|
|
58
|
+
* Internal: only `anchor.tsx`'s `wrap` calls `markWrapComponent`. Not part of
|
|
59
|
+
* this module's public contract with the rest of the package.
|
|
60
|
+
*/
|
|
61
|
+
const wrapComponents = new WeakSet<object>();
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Marks `component` as one `wrap()` produced. See `wrapComponents`.
|
|
65
|
+
* @internal Only `anchor.tsx`'s `wrap` calls this; it is exported (rather
|
|
66
|
+
* than made a closure `wrap` and `isWrapper` both capture) only because they
|
|
67
|
+
* live in different modules, and is not part of the package's public API.
|
|
68
|
+
*/
|
|
69
|
+
export function markWrapComponent(component: object): void {
|
|
70
|
+
wrapComponents.add(component);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* True for the fiber `wrap()` itself renders as, the `RootErrorReporter`
|
|
75
|
+
* it mounts around the app root, or for the anchor view it renders alongside
|
|
76
|
+
* -- none of those are real app content, and `walk.ts` flattens them away
|
|
77
|
+
* (their children, if any, are promoted to whatever ancestor node IS
|
|
78
|
+
* emitted) rather than showing a synthetic "BugseeRoot" / reporter node or
|
|
79
|
+
* the invisible anchor in the captured tree.
|
|
80
|
+
*
|
|
81
|
+
* The anchor is recognised by its `nativeID`, not by fiber identity: the
|
|
82
|
+
* fiber `wrap()`'s `<View>` element resolves to is rebuilt on every render,
|
|
83
|
+
* while the prop survives unchanged for as long as the anchor is mounted.
|
|
84
|
+
* Reading `nativeID` off a host fiber is exactly what `walk.ts`'s own privacy
|
|
85
|
+
* rule already allows (`tagOptions`), so this reads nothing the walk itself
|
|
86
|
+
* could not have read anyway.
|
|
87
|
+
*
|
|
88
|
+
* Exported only so `walk.test.ts` can assert the RootErrorReporter identity
|
|
89
|
+
* check against the same predicate production uses (manual mutate 3); not
|
|
90
|
+
* part of this module's public contract with the rest of the package.
|
|
91
|
+
*/
|
|
92
|
+
export function isWrapper(fiber: FiberLike): boolean {
|
|
93
|
+
const type = fiber.type;
|
|
94
|
+
if (type === RootErrorReporter) {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
if (typeof type === 'function' && wrapComponents.has(type)) {
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
if (fiber.tag !== FiberTag.HostComponent) {
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
const props = fiber.memoizedProps as { nativeID?: unknown } | null | undefined;
|
|
104
|
+
return props?.nativeID === VH_ANCHOR_NATIVE_ID;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* True for the fiber that is the `<BugseeSecure>` boundary itself.
|
|
109
|
+
*
|
|
110
|
+
* `BugseeSecure` is a plain function component (its own doc comment: "no
|
|
111
|
+
* `memo`, no `forwardRef`: the view tree walk recognises it by identity"),
|
|
112
|
+
* so today a real fiber only ever matches on `.type`: a plain
|
|
113
|
+
* `FunctionComponent` fiber's `.type` IS the function. Checking `.elementType`
|
|
114
|
+
* too is not, despite an earlier version of this comment, coverage for
|
|
115
|
+
* `memo`/`forwardRef` -- `memo(BugseeSecure)` still matches on `.type` (a
|
|
116
|
+
* `SimpleMemo` fiber's `.type` is the inner function; a `Memo` fiber with a
|
|
117
|
+
* custom `compare` has its own `FunctionComponent` child fiber, unaffected
|
|
118
|
+
* either way), and wrapping `BugseeSecure` in `forwardRef` would match
|
|
119
|
+
* neither `.type` nor `.elementType`. `.elementType` differs from `.type`
|
|
120
|
+
* only when a component's type is *resolved at render time* -- a Fast
|
|
121
|
+
* Refresh family (dev only) or `React.lazy` -- so this check costs nothing
|
|
122
|
+
* and is free insurance against exactly that, not against a wrapper change.
|
|
123
|
+
* If `BugseeSecure` is ever wrapped (`forwardRef`, `memo` with a custom
|
|
124
|
+
* `compare` that still fails to match for some other reason, etc.), THIS
|
|
125
|
+
* function must change too -- `wrap.integration.test.tsx`'s real-render test
|
|
126
|
+
* would catch a regression here, since it renders the actual component.
|
|
127
|
+
*
|
|
128
|
+
* Fails closed on `<BugseeSecure enabled={false}>` too: this reads only the
|
|
129
|
+
* fiber's type, never its `enabled` prop, so a disabled boundary is still
|
|
130
|
+
* secure from the WALK's point of view. That is deliberate (privacy over
|
|
131
|
+
* completeness, matching `walk.ts`'s own `safeIsSecureBoundary` stance) and
|
|
132
|
+
* costs nothing extra to document: reading `enabled` here would mean one more
|
|
133
|
+
* prop this module touches, for a case `BugseeSecure` itself already handles
|
|
134
|
+
* by not being mounted at all when disabled long enough to matter.
|
|
135
|
+
*/
|
|
136
|
+
function isSecureBoundary(fiber: FiberLike): boolean {
|
|
137
|
+
return fiber.type === BugseeSecure || fiber.elementType === BugseeSecure;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* `performance.now()` when it exists AND returns a finite number (every real
|
|
142
|
+
* React Native and browser-like JS engine), `Date.now()` otherwise -- a plain
|
|
143
|
+
* JVM/Node test environment with no `performance` global, or a hostile/buggy
|
|
144
|
+
* one whose `.now()` returns `NaN`/`undefined`/a string, say. Only ever used
|
|
145
|
+
* as a duration's two endpoints, so the epoch it counts from does not matter.
|
|
146
|
+
*
|
|
147
|
+
* The finite check matters on its own, not just the existence check:
|
|
148
|
+
* `walk.ts`'s `safeNow` coerces a non-finite `now()` result to `0`
|
|
149
|
+
* (`Number.isFinite`), and if BOTH the walk's start time and every later
|
|
150
|
+
* check coerced to the same `0`, the 250 ms walk budget (`VH_WALK_BUDGET_MS`)
|
|
151
|
+
* would never trip -- silently disabling the one bound that keeps a
|
|
152
|
+
* pathological tree's walk inside the SDK's own capture deadline. Falling
|
|
153
|
+
* back to `Date.now()` here, instead of letting a bad `performance.now()`
|
|
154
|
+
* reach `safeNow` at all, keeps that budget live regardless.
|
|
155
|
+
*
|
|
156
|
+
* Exported only for `__tests__/requests.test.ts`'s own direct tests of this
|
|
157
|
+
* fallback; not part of this module's public contract with the rest of the
|
|
158
|
+
* package (see `markWrapComponent`'s doc comment for the same caveat).
|
|
159
|
+
*/
|
|
160
|
+
export function monotonicNow(): number {
|
|
161
|
+
const perf = (globalThis as { performance?: { now?: () => number } }).performance;
|
|
162
|
+
if (perf && typeof perf.now === 'function') {
|
|
163
|
+
const value = perf.now();
|
|
164
|
+
if (Number.isFinite(value)) {
|
|
165
|
+
return value;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return Date.now();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Every currently-registered anchor's `FiberRoot`, deduped by `FiberRoot`
|
|
173
|
+
* identity so two anchors mounted under the same root (two `wrap()`ped
|
|
174
|
+
* surfaces sharing one React root, however unlikely) walk it once, not twice.
|
|
175
|
+
* An anchor whose `fiberRootOf` is `null` -- unmounted, or never a real host
|
|
176
|
+
* instance -- is skipped rather than represented as an empty root.
|
|
177
|
+
*/
|
|
178
|
+
function currentRoots(): { current: FiberLike }[] {
|
|
179
|
+
const seen = new Set<{ current: FiberLike }>();
|
|
180
|
+
const roots: { current: FiberLike }[] = [];
|
|
181
|
+
for (const instance of anchors) {
|
|
182
|
+
const root = fiberRootOf(instance);
|
|
183
|
+
if (root === null || seen.has(root)) {
|
|
184
|
+
continue;
|
|
185
|
+
}
|
|
186
|
+
seen.add(root);
|
|
187
|
+
roots.push(root);
|
|
188
|
+
}
|
|
189
|
+
return roots;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function buildEnv(event: DataRequestEvent): WalkEnv {
|
|
193
|
+
return {
|
|
194
|
+
measure: measureHostFiber,
|
|
195
|
+
isSecureBoundary,
|
|
196
|
+
isWrapper,
|
|
197
|
+
// Only Android and iOS are meaningfully distinguished anywhere in this
|
|
198
|
+
// package (see `secure/unit.ts`'s identical choice for the same reason):
|
|
199
|
+
// every other `Platform.OS` (windows/macos/web) maps to iOS's 1:1, no-
|
|
200
|
+
// scaling convention rather than to a third `WalkEnv.platform` value the
|
|
201
|
+
// type does not even have room for.
|
|
202
|
+
platform: Platform.OS === 'android' ? 'android' : 'ios',
|
|
203
|
+
scale: secureRectangleScale(),
|
|
204
|
+
originX: event.originX,
|
|
205
|
+
originY: event.originY,
|
|
206
|
+
nativeTagOf: nativeTagOfFiber,
|
|
207
|
+
originForSurface: (surface) => {
|
|
208
|
+
try {
|
|
209
|
+
const origin: unknown = NativeBugsee.secureSurfaceOrigin(surface);
|
|
210
|
+
// Number.isFinite never coerces, so a missing element fails it too.
|
|
211
|
+
if (Array.isArray(origin) && Number.isFinite(origin[0]) && Number.isFinite(origin[1])) {
|
|
212
|
+
return { x: origin[0] as number, y: origin[1] as number };
|
|
213
|
+
}
|
|
214
|
+
} catch {
|
|
215
|
+
// Keep the enclosing origin for that Modal's subtree.
|
|
216
|
+
}
|
|
217
|
+
return null;
|
|
218
|
+
},
|
|
219
|
+
now: monotonicNow,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* The JSON text to reply with for a `'vh'` request that has at least one root
|
|
225
|
+
* to walk, or `null` for every outcome that isn't a real tree.
|
|
226
|
+
*
|
|
227
|
+
* `buildViewTree` returning `null` (nothing measurable yet, everything under
|
|
228
|
+
* a hidden `Offscreen`, or every root's `.current` empty) must reply actual
|
|
229
|
+
* `null` -- `JSON.stringify(null)` is the four-character STRING `"null"`, a
|
|
230
|
+
* non-empty string the SDK would store as a real (if odd) `managed` payload
|
|
231
|
+
* instead of recognising "nothing to report". `undefined` (not a contract
|
|
232
|
+
* `buildViewTree` documents, but `payload` must survive it regardless) and a
|
|
233
|
+
* throwing `JSON.stringify` (a cyclic structure, or a `BigInt` somehow
|
|
234
|
+
* reaching a node) both collapse to `null` the same way.
|
|
235
|
+
*/
|
|
236
|
+
function replyPayloadFor(tree: ReturnType<typeof buildViewTree>): string | null {
|
|
237
|
+
if (tree == null) {
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
try {
|
|
241
|
+
const json = JSON.stringify(tree);
|
|
242
|
+
return typeof json === 'string' ? json : null;
|
|
243
|
+
} catch {
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Answers one `onDataRequest` delivery. Always calls `replyDataRequest`
|
|
250
|
+
* exactly once, synchronously -- the SDK waits on it mid-capture -- no matter
|
|
251
|
+
* which of `type`, "nothing mounted", "the walk itself threw" or "the reply
|
|
252
|
+
* itself threw" applies.
|
|
253
|
+
*
|
|
254
|
+
* The payload is computed entirely inside the `try`; `replyDataRequest` is
|
|
255
|
+
* then called exactly once, outside it, in its own `try` that only warns.
|
|
256
|
+
* Computing the payload first (rather than calling `replyDataRequest` from
|
|
257
|
+
* inside each branch, as an earlier version of this function did) means a
|
|
258
|
+
* throwing `replyDataRequest` cannot be retried into throwing a second time:
|
|
259
|
+
* there is exactly one call site for it, not one per branch plus one in the
|
|
260
|
+
* `catch`.
|
|
261
|
+
*
|
|
262
|
+
* A `type` other than `'vh'` is native's own to answer; this replies `null`
|
|
263
|
+
* without walking anything. `roots.length === 0` (nothing registered, or
|
|
264
|
+
* every registered anchor's fiber root is gone) also replies `null` directly,
|
|
265
|
+
* rather than asking `buildViewTree` to walk zero roots only to have it
|
|
266
|
+
* return `null` itself -- the two are observably the same to native, but the
|
|
267
|
+
* former skips work `buildViewTree` cannot do anything useful with anyway.
|
|
268
|
+
*
|
|
269
|
+
* "Warns once" means once per FAILING request, not once ever for the whole
|
|
270
|
+
* process: a walk that fails deterministically (a persistently broken
|
|
271
|
+
* `isSecureBoundary`, say) should keep saying so on every capture pass, not
|
|
272
|
+
* go quiet after the first one the way `BugseeSecure`'s own one-time
|
|
273
|
+
* `console.warn` does for an unrelated, expected-to-be-rare failure.
|
|
274
|
+
*/
|
|
275
|
+
function onDataRequest(event: DataRequestEvent): void {
|
|
276
|
+
let payload: string | null = null;
|
|
277
|
+
try {
|
|
278
|
+
if (event.type === VH_DATA_TYPE) {
|
|
279
|
+
const roots = currentRoots();
|
|
280
|
+
if (roots.length > 0) {
|
|
281
|
+
payload = replyPayloadFor(buildViewTree(roots, buildEnv(event)));
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
} catch (error) {
|
|
285
|
+
console.warn('[Bugsee] could not answer a view-hierarchy data request', errorName(error));
|
|
286
|
+
payload = null;
|
|
287
|
+
}
|
|
288
|
+
try {
|
|
289
|
+
NativeBugsee.replyDataRequest(event.requestId, payload);
|
|
290
|
+
} catch (error) {
|
|
291
|
+
console.warn('[Bugsee] could not deliver a view-hierarchy reply', errorName(error));
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Registers a mounted anchor's public instance (`anchor.tsx`'s `wrap`, on
|
|
297
|
+
* mount). The first anchor ever registered subscribes to `onDataRequest` --
|
|
298
|
+
* once, for the life of the process, never torn down -- and every transition
|
|
299
|
+
* from zero registered anchors to one turns view-tree capture on
|
|
300
|
+
* (`setViewTreeEnabled(true)`), so the SDK only asks for `'vh'` while there is
|
|
301
|
+
* somewhere to answer it from.
|
|
302
|
+
*
|
|
303
|
+
* Idempotent per instance: registering the SAME instance twice in a row (an
|
|
304
|
+
* anchor's own effect re-running under `<StrictMode>`'s double-invoke, say)
|
|
305
|
+
* is a no-op the second time -- `isNew` is checked BEFORE adding, rather than
|
|
306
|
+
* inferred from a size comparison after, so this holds regardless of how many
|
|
307
|
+
* OTHER anchors are registered at the same time.
|
|
308
|
+
*/
|
|
309
|
+
export function registerAnchor(instance: unknown): void {
|
|
310
|
+
const isNew = !anchors.has(instance);
|
|
311
|
+
anchors.add(instance);
|
|
312
|
+
if (!subscribedToDataRequests) {
|
|
313
|
+
subscribedToDataRequests = true;
|
|
314
|
+
NativeBugsee.onDataRequest(onDataRequest);
|
|
315
|
+
}
|
|
316
|
+
if (isNew && anchors.size === 1) {
|
|
317
|
+
NativeBugsee.setViewTreeEnabled(true);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Unregisters a mounted anchor's public instance (`anchor.tsx`'s `wrap`, on
|
|
323
|
+
* unmount). The transition from one registered anchor to zero turns view-tree
|
|
324
|
+
* capture off (`setViewTreeEnabled(false)`); the subscription itself is never
|
|
325
|
+
* removed, so a later `registerAnchor` can turn capture back on without
|
|
326
|
+
* resubscribing.
|
|
327
|
+
*
|
|
328
|
+
* Idempotent per instance: `Set.delete` returns whether `instance` was
|
|
329
|
+
* actually present, so unregistering an instance that is already gone -- a
|
|
330
|
+
* stale second call, from `<StrictMode>`'s double-invoke or any other
|
|
331
|
+
* duplicate teardown -- never reaches `setViewTreeEnabled` at all, tied
|
|
332
|
+
* directly to whether THIS call actually removed something, rather than to a
|
|
333
|
+
* `sizeBefore`/`sizeAfter` comparison captured around the delete. An earlier
|
|
334
|
+
* version of this function used exactly that `sizeBefore === 1 && size === 0`
|
|
335
|
+
* comparison; it happened to still be correct for every sequence tested, but
|
|
336
|
+
* was one step further from the property that actually matters ("did this
|
|
337
|
+
* specific call remove the last anchor") than this version is, and a review
|
|
338
|
+
* round flagged the gap: `register(a); register(b); unregister(a);
|
|
339
|
+
* unregister(a)` -- the redundant second `unregister(a)` -- is exactly the
|
|
340
|
+
* stale-double-unregister-while-another-anchor-is-mounted case this version
|
|
341
|
+
* is tested against directly.
|
|
342
|
+
*/
|
|
343
|
+
export function unregisterAnchor(instance: unknown): void {
|
|
344
|
+
if (anchors.delete(instance) && anchors.size === 0) {
|
|
345
|
+
NativeBugsee.setViewTreeEnabled(false);
|
|
346
|
+
}
|
|
347
|
+
}
|