@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.
Files changed (250) hide show
  1. package/BugseeReactNative.podspec +95 -0
  2. package/LICENSE +21 -0
  3. package/README.md +552 -2
  4. package/android/build.gradle +162 -0
  5. package/android/consumer-rules.pro +2 -0
  6. package/android/src/main/AndroidManifest.xml +33 -0
  7. package/android/src/main/java/com/bugsee/reactnative/AppearanceBridge.java +82 -0
  8. package/android/src/main/java/com/bugsee/reactnative/AttributeBridge.java +209 -0
  9. package/android/src/main/java/com/bugsee/reactnative/BreadcrumbFilterBridge.java +443 -0
  10. package/android/src/main/java/com/bugsee/reactnative/BridgeJson.java +168 -0
  11. package/android/src/main/java/com/bugsee/reactnative/BugseeModule.java +1869 -0
  12. package/android/src/main/java/com/bugsee/reactnative/BugseeOptionEnums.java +136 -0
  13. package/android/src/main/java/com/bugsee/reactnative/BugseePackage.java +42 -0
  14. package/android/src/main/java/com/bugsee/reactnative/BugseeReactNativeWrapper.java +200 -0
  15. package/android/src/main/java/com/bugsee/reactnative/BugseeStatusMapper.java +66 -0
  16. package/android/src/main/java/com/bugsee/reactnative/BugseeTokens.java +22 -0
  17. package/android/src/main/java/com/bugsee/reactnative/ConsoleEchoDedup.java +202 -0
  18. package/android/src/main/java/com/bugsee/reactnative/CreatedReports.java +127 -0
  19. package/android/src/main/java/com/bugsee/reactnative/DataRequestBridge.java +375 -0
  20. package/android/src/main/java/com/bugsee/reactnative/ExceptionBridge.java +88 -0
  21. package/android/src/main/java/com/bugsee/reactnative/ExceptionExecutors.java +33 -0
  22. package/android/src/main/java/com/bugsee/reactnative/LogFilterBridge.java +375 -0
  23. package/android/src/main/java/com/bugsee/reactnative/NetworkEvents.java +227 -0
  24. package/android/src/main/java/com/bugsee/reactnative/NetworkFilterBridge.java +498 -0
  25. package/android/src/main/java/com/bugsee/reactnative/PluginEndpoint.java +48 -0
  26. package/android/src/main/java/com/bugsee/reactnative/ReactNativeWebException.java +19 -0
  27. package/android/src/main/java/com/bugsee/reactnative/ReactNativeWrapperInitProvider.java +61 -0
  28. package/android/src/main/java/com/bugsee/reactnative/ReactRootOriginTracker.java +867 -0
  29. package/android/src/main/java/com/bugsee/reactnative/ReportArgs.java +58 -0
  30. package/android/src/main/java/com/bugsee/reactnative/ReportHandlerBridge.java +336 -0
  31. package/android/src/main/java/com/bugsee/reactnative/ReportHandlerDeadlines.java +57 -0
  32. package/android/src/main/java/com/bugsee/reactnative/ReportOps.java +287 -0
  33. package/android/src/main/java/com/bugsee/reactnative/SecureRectanglePulls.java +113 -0
  34. package/android/src/main/java/com/bugsee/reactnative/SecureRectangleStore.java +692 -0
  35. package/android/src/main/java/com/bugsee/reactnative/SpanHandles.java +143 -0
  36. package/android/src/main/java/com/bugsee/reactnative/WrapperChannelHolder.java +137 -0
  37. package/android/src/main/java/com/bugsee/reactnative/WrapperEventBus.java +110 -0
  38. package/android/src/main/java/com/bugsee/reactnative/WrapperRegistrar.java +54 -0
  39. package/app.plugin.js +4 -0
  40. package/ios/BGSRNConsoleCapture.h +52 -0
  41. package/ios/BGSRNConsoleCapture.mm +344 -0
  42. package/ios/BugseeModule.h +25 -0
  43. package/ios/BugseeModule.mm +2728 -0
  44. package/ios/Package.swift +71 -0
  45. package/ios/Support/Package.resolved +14 -0
  46. package/ios/Support/Package.swift +44 -0
  47. package/ios/Support/Sources/BugseeRNSupport/BGSRNAttributes.m +52 -0
  48. package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReportOps.m +236 -0
  49. package/ios/Support/Sources/BugseeRNSupport/BGSRNCreatedReports.m +184 -0
  50. package/ios/Support/Sources/BugseeRNSupport/BGSRNDataRequestBridge.m +431 -0
  51. package/ios/Support/Sources/BugseeRNSupport/BGSRNErrorMessage.m +40 -0
  52. package/ios/Support/Sources/BugseeRNSupport/BGSRNEventBus.m +70 -0
  53. package/ios/Support/Sources/BugseeRNSupport/BGSRNExceptions.m +63 -0
  54. package/ios/Support/Sources/BugseeRNSupport/BGSRNGuardedEmit.mm +32 -0
  55. package/ios/Support/Sources/BugseeRNSupport/BGSRNJSON.m +40 -0
  56. package/ios/Support/Sources/BugseeRNSupport/BGSRNLaunchHold.m +147 -0
  57. package/ios/Support/Sources/BugseeRNSupport/BGSRNMainThread.m +23 -0
  58. package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkEvents.m +159 -0
  59. package/ios/Support/Sources/BugseeRNSupport/BGSRNNetworkFilter.m +155 -0
  60. package/ios/Support/Sources/BugseeRNSupport/BGSRNPluginEndpoint.m +21 -0
  61. package/ios/Support/Sources/BugseeRNSupport/BGSRNReactRootOriginTracker.m +63 -0
  62. package/ios/Support/Sources/BugseeRNSupport/BGSRNReactWindow.m +251 -0
  63. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportArgs.m +47 -0
  64. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportDeadlines.m +8 -0
  65. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportHandlerBridge.m +308 -0
  66. package/ios/Support/Sources/BugseeRNSupport/BGSRNReportOps.m +345 -0
  67. package/ios/Support/Sources/BugseeRNSupport/BGSRNSecureRectangles.m +508 -0
  68. package/ios/Support/Sources/BugseeRNSupport/BGSRNSettleOnce.m +62 -0
  69. package/ios/Support/Sources/BugseeRNSupport/BGSRNSpanHandles.m +136 -0
  70. package/ios/Support/Sources/BugseeRNSupport/BGSRNStatusMapper.m +18 -0
  71. package/ios/Support/Sources/BugseeRNSupport/BGSRNTokens.m +9 -0
  72. package/ios/Support/Sources/BugseeRNSupport/BGSRNValues.m +5 -0
  73. package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapper.m +54 -0
  74. package/ios/Support/Sources/BugseeRNSupport/BGSRNWrapperChannelHolder.m +59 -0
  75. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNAttributes.h +63 -0
  76. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReportOps.h +51 -0
  77. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNCreatedReports.h +81 -0
  78. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNDataRequestBridge.h +118 -0
  79. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNErrorMessage.h +30 -0
  80. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNEventBus.h +45 -0
  81. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNExceptions.h +31 -0
  82. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNGuardedEmit.h +31 -0
  83. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNJSON.h +25 -0
  84. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNLaunchHold.h +86 -0
  85. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNMainThread.h +32 -0
  86. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkEvents.h +28 -0
  87. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNNetworkFilter.h +28 -0
  88. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNPluginEndpoint.h +17 -0
  89. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactRootOriginTracker.h +48 -0
  90. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReactWindow.h +135 -0
  91. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportArgs.h +17 -0
  92. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportDeadlines.h +37 -0
  93. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportHandlerBridge.h +94 -0
  94. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNReportOps.h +86 -0
  95. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSecureRectangles.h +198 -0
  96. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSettleOnce.h +25 -0
  97. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNSpanHandles.h +49 -0
  98. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNStatusMapper.h +26 -0
  99. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNTokens.h +14 -0
  100. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNValues.h +18 -0
  101. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapper.h +40 -0
  102. package/ios/Support/Sources/BugseeRNSupport/include/BGSRNWrapperChannelHolder.h +74 -0
  103. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNAttributesTests.m +194 -0
  104. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportOpsTests.m +274 -0
  105. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNCreatedReportsTests.m +240 -0
  106. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNDataRequestBridgeTests.m +685 -0
  107. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNErrorMessageTests.m +102 -0
  108. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNEventBusTests.m +136 -0
  109. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNExceptionsTests.m +68 -0
  110. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.h +41 -0
  111. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNFakeReport.m +166 -0
  112. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNGuardedEmitTests.mm +85 -0
  113. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNJSONTests.m +281 -0
  114. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNLaunchHoldTests.m +230 -0
  115. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNMainThreadTests.m +97 -0
  116. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkEventsTests.m +99 -0
  117. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNNetworkFilterTests.m +134 -0
  118. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNPluginEndpointTests.m +38 -0
  119. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactRootOriginTrackerTests.m +210 -0
  120. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReactWindowTests.m +548 -0
  121. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportArgsTests.m +51 -0
  122. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportDeadlinesTests.m +22 -0
  123. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportHandlerBridgeTests.m +382 -0
  124. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNReportOpsTests.m +295 -0
  125. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSecureRectanglesTests.m +568 -0
  126. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSettleOnceTests.m +134 -0
  127. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNSpanHandlesTests.m +153 -0
  128. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNStatusMapperTests.m +81 -0
  129. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNValuesTests.m +32 -0
  130. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperChannelHolderTests.m +205 -0
  131. package/ios/Support/Tests/BugseeRNSupportTests/BGSRNWrapperTests.m +66 -0
  132. package/ios/react-native-spm-prefix.h +10 -0
  133. package/native-versions.json +10 -0
  134. package/package.json +62 -3
  135. package/plugin/build/bundle-phase.d.ts +41 -0
  136. package/plugin/build/bundle-phase.js +116 -0
  137. package/plugin/build/bundle-phase.js.map +1 -0
  138. package/plugin/build/dsym-script.d.ts +32 -0
  139. package/plugin/build/dsym-script.js +159 -0
  140. package/plugin/build/dsym-script.js.map +1 -0
  141. package/plugin/build/endpoint.d.ts +30 -0
  142. package/plugin/build/endpoint.js +69 -0
  143. package/plugin/build/endpoint.js.map +1 -0
  144. package/plugin/build/gradle.d.ts +65 -0
  145. package/plugin/build/gradle.js +1066 -0
  146. package/plugin/build/gradle.js.map +1 -0
  147. package/plugin/build/index.d.ts +85 -0
  148. package/plugin/build/index.js +217 -0
  149. package/plugin/build/index.js.map +1 -0
  150. package/plugin/build/manifest.d.ts +48 -0
  151. package/plugin/build/manifest.js +69 -0
  152. package/plugin/build/manifest.js.map +1 -0
  153. package/plugin/build/native-versions.baked.json +4 -0
  154. package/plugin/build/native-versions.d.ts +10 -0
  155. package/plugin/build/native-versions.js +27 -0
  156. package/plugin/build/native-versions.js.map +1 -0
  157. package/plugin/build/pbx-string.d.ts +8 -0
  158. package/plugin/build/pbx-string.js +31 -0
  159. package/plugin/build/pbx-string.js.map +1 -0
  160. package/plugin/build/podfile.d.ts +3 -0
  161. package/plugin/build/podfile.js +28 -0
  162. package/plugin/build/podfile.js.map +1 -0
  163. package/plugin/build/properties.d.ts +19 -0
  164. package/plugin/build/properties.js +41 -0
  165. package/plugin/build/properties.js.map +1 -0
  166. package/plugin/build/scheme.d.ts +20 -0
  167. package/plugin/build/scheme.js +107 -0
  168. package/plugin/build/scheme.js.map +1 -0
  169. package/react-native.config.js +26 -0
  170. package/scripts/bugsee-sourcemaps.gradle +201 -0
  171. package/scripts/bugsee-xcode.sh +83 -0
  172. package/scripts/compose-then-inject.js +113 -0
  173. package/scripts/hermes-sourcemaps.js +634 -0
  174. package/scripts/hermesc-preserve-js.cmd +6 -0
  175. package/scripts/hermesc-preserve-js.js +200 -0
  176. package/scripts/hermesc-preserve-js.sh +7 -0
  177. package/src/NativeBugsee.ts +622 -0
  178. package/src/apm/notify.ts +58 -0
  179. package/src/apm/span.ts +403 -0
  180. package/src/apm/types.ts +57 -0
  181. package/src/appearance/report.ts +171 -0
  182. package/src/architecture.ts +48 -0
  183. package/src/attributes/errors.ts +39 -0
  184. package/src/attributes/validate.ts +150 -0
  185. package/src/breadcrumbs/add.ts +58 -0
  186. package/src/breadcrumbs/data.ts +33 -0
  187. package/src/breadcrumbs/filter.ts +215 -0
  188. package/src/breadcrumbs/types.ts +64 -0
  189. package/src/bridge/json.ts +110 -0
  190. package/src/console/capture.ts +180 -0
  191. package/src/console/dedup.ts +175 -0
  192. package/src/data/validate.ts +259 -0
  193. package/src/errorName.ts +32 -0
  194. package/src/exceptions/ErrorBoundary.tsx +92 -0
  195. package/src/exceptions/RootErrorReporter.tsx +61 -0
  196. package/src/exceptions/debugIds.ts +118 -0
  197. package/src/exceptions/handlers.ts +236 -0
  198. package/src/exceptions/options.ts +85 -0
  199. package/src/exceptions/payload.ts +456 -0
  200. package/src/exceptions/report.ts +170 -0
  201. package/src/exceptions/sha1.ts +148 -0
  202. package/src/exceptions/stack.ts +355 -0
  203. package/src/index.ts +944 -0
  204. package/src/logs/filter.ts +90 -0
  205. package/src/logs/log.ts +36 -0
  206. package/src/network/add.ts +165 -0
  207. package/src/network/filter.ts +198 -0
  208. package/src/options/AndroidLaunchOptions.ts +78 -0
  209. package/src/options/BugseeLaunchOptions.ts +190 -0
  210. package/src/options/IOSLaunchOptions.ts +57 -0
  211. package/src/options/android-options-manifest.json +646 -0
  212. package/src/options/createDefaultLaunchOptions.ts +29 -0
  213. package/src/options/endpoint.ts +58 -0
  214. package/src/options/enums.ts +104 -0
  215. package/src/options/ios-enums.json +19 -0
  216. package/src/options/keys.ts +39 -0
  217. package/src/options/option-enums.json +34 -0
  218. package/src/options/option-keys.json +107 -0
  219. package/src/report/BugseeReport.ts +264 -0
  220. package/src/report/CreatedReport.ts +127 -0
  221. package/src/report/dispatcher.ts +95 -0
  222. package/src/report/errors.ts +48 -0
  223. package/src/report/fields.ts +40 -0
  224. package/src/report/types.ts +157 -0
  225. package/src/report/validate.ts +197 -0
  226. package/src/secure/BugseeSecure.tsx +202 -0
  227. package/src/secure/ancestry.ts +622 -0
  228. package/src/secure/drivers.ts +342 -0
  229. package/src/secure/followEvents.ts +57 -0
  230. package/src/secure/hold.ts +99 -0
  231. package/src/secure/measureLoop.ts +323 -0
  232. package/src/secure/nativeAnimation.ts +1005 -0
  233. package/src/secure/rectangles.ts +93 -0
  234. package/src/secure/registry.ts +237 -0
  235. package/src/secure/surface.ts +83 -0
  236. package/src/secure/tracker.ts +723 -0
  237. package/src/secure/transition.ts +488 -0
  238. package/src/secure/unit.ts +22 -0
  239. package/src/status.ts +16 -0
  240. package/src/version.ts +9 -0
  241. package/src/viewtree/anchor.tsx +105 -0
  242. package/src/viewtree/constants.ts +20 -0
  243. package/src/viewtree/fiber.ts +251 -0
  244. package/src/viewtree/requests.ts +347 -0
  245. package/src/viewtree/walk.ts +902 -0
  246. package/src/wrapper/channel.ts +33 -0
  247. package/src/wrapper/collect.ts +52 -0
  248. package/src/wrapper/events.ts +45 -0
  249. package/src/wrapper/identity.ts +54 -0
  250. package/src/wrapper/lifecycle-events.ts +89 -0
@@ -0,0 +1,488 @@
1
+ import { MODAL_SCREEN_HOST_TYPE, SCREEN_HOST_TYPE, measureFiber, passMemo } from './ancestry';
2
+ import type { Ancestry } from './ancestry';
3
+ import { MODAL_HOST_TYPE } from './surface';
4
+ import { FiberTag } from '../viewtree/fiber';
5
+ import type { FiberLike, WindowRect } from '../viewtree/fiber';
6
+
7
+ /**
8
+ * Native transitions carry a `<BugseeSecure>` where its measurements cannot
9
+ * follow, and draw it after React is done with it.
10
+ *
11
+ * A react-native-screens stack animates a pushed screen in, and a popped one
12
+ * out, natively: React mounts the new screen, or unmounts the popped one, at
13
+ * the start, and the screen is then drawn moving (Android 13+: 10% sideways
14
+ * over 450 ms; before that a 0.85 to 1 scale about its centre; iOS: the whole
15
+ * width) for as long as the animation runs. A `<Modal>`'s dialog slides in
16
+ * from the bottom of the display and out again the same way, with its content
17
+ * laid out where it ends. None of this is in the shadow tree, so
18
+ * `measureInWindow` reads where the view rests, and a popped screen's views
19
+ * are not measurable at all.
20
+ *
21
+ * So for {@link SECURE_TRANSITION_HOLD_MS} from the commit that starts such a
22
+ * transition, a view it carries also covers everywhere the transition can
23
+ * draw it:
24
+ * - a screen pushed onto, or popped off, a stack, and the screen it uncovers
25
+ * or covers on that stack (which moves too): by the screen's
26
+ * `stackAnimation`, the band of the view across the screen for a
27
+ * sideways slide, the column from the view down for a slide from the
28
+ * bottom, the view itself for a fade or none; for the platform default and
29
+ * anything else, the screen's whole rectangle. The stack clips what its
30
+ * screens draw to its bounds, so each of these holds for its animation in
31
+ * either direction and RTL, and the whole screen holds for any;
32
+ * - a `<Modal animationType="slide">` opening or closing: the band from the
33
+ * view's top down to the bottom of the surface, the path it slides along.
34
+ * A fading Modal does not move the view, and the hold every unmount gets
35
+ * keeps it covered where it rests while the dialog fades.
36
+ *
37
+ * A transition is told apart from a view coming and going inside a screen
38
+ * that stays by the fiber tree alone: in the commit that mounts a view, an
39
+ * ancestor created by that same commit has no alternate yet (and the time is
40
+ * kept, so a view mounted, or shown, later in the same transition is covered
41
+ * too); in the commit that unmounts it, the root of what is deleted is listed
42
+ * in its parent's `deletions`.
43
+ *
44
+ * 800 ms from the commit: on an API 30 emulator (Debug) the native animation
45
+ * started ~200 ms after the commit and react-native-screens' default Android
46
+ * animations run 450 ms (200 ms before Android 13), 650 ms in all; iOS pushes
47
+ * run ~350-500 ms. React Native screens report the end of a transition only
48
+ * to the navigator's own handlers, so the cover ends on time.
49
+ */
50
+ export const SECURE_TRANSITION_HOLD_MS = 800;
51
+
52
+ /**
53
+ * A rectangle past every edge of any surface, for a cover whose bounds cannot
54
+ * be measured: both SDKs cut what they mask to the display.
55
+ */
56
+ export const WHOLE_SURFACE: WindowRect = { x: 0, y: 0, width: 100_000, height: 100_000 };
57
+
58
+ /** The react-native-screens stacks, which animate screens in and out natively. */
59
+ export const STACK_HOST_TYPES: ReadonlySet<unknown> = new Set(['RNSScreenStack']);
60
+
61
+ /** What carries a view through a transition: its nearest stack screen, or its `<Modal>`. */
62
+ export interface Carrier {
63
+ readonly kind: 'screen' | 'modal';
64
+ /** Where the screen's, or the Modal's, host is in `Ancestry.path`. */
65
+ readonly index: number;
66
+ /** A screen's stack, in `Ancestry.path`. */
67
+ readonly stack?: number;
68
+ }
69
+
70
+ /**
71
+ * What can carry the view through a native transition: every screen in a
72
+ * stack above it (nearest first), and the `<Modal>` it is in, each
73
+ * independently (a stack inside a Modal slides in with the Modal, and pushes
74
+ * within it on its own; in nested stacks, the screen that moves is the one
75
+ * pushed or popped).
76
+ */
77
+ export function carriersOf(ancestry: Ancestry): Carrier[] {
78
+ // `hosts` stop at a Modal (a root of its own): the screens it was opened over move without it.
79
+ const carriers: Carrier[] = ancestry.hosts
80
+ .filter((host) => host.screen && STACK_HOST_TYPES.has(ancestry.path[host.above]?.type))
81
+ .map((host) => ({ kind: 'screen' as const, index: host.index, stack: host.above }));
82
+ const modal = modalOf(ancestry);
83
+ if (modal !== null) {
84
+ carriers.push(modal);
85
+ }
86
+ return carriers;
87
+ }
88
+
89
+ /**
90
+ * Where the `carriers` can draw a view seen at `view`, joined, or
91
+ * `null` when none of them moves it.
92
+ */
93
+ export function carriedCovers(
94
+ ancestry: Ancestry,
95
+ carriers: readonly Carrier[],
96
+ view: WindowRect | null | undefined,
97
+ ): WindowRect | null {
98
+ let joined: WindowRect | null = null;
99
+ for (const carrier of carriers) {
100
+ const cover = carriedCover(ancestry, carrier, view);
101
+ if (cover !== null) {
102
+ joined = bounding(cover, joined);
103
+ }
104
+ }
105
+ return joined;
106
+ }
107
+
108
+ /** The bounding box of `a` and `b` (when there is one). */
109
+ export function bounding(a: WindowRect, b: WindowRect | null | undefined): WindowRect {
110
+ if (b == null) {
111
+ return a;
112
+ }
113
+ const left = Math.min(a.x, b.x);
114
+ const top = Math.min(a.y, b.y);
115
+ const right = Math.max(a.x + a.width, b.x + b.width);
116
+ const bottom = Math.max(a.y + a.height, b.y + b.height);
117
+ return { x: left, y: top, width: right - left, height: bottom - top };
118
+ }
119
+
120
+ /** The `<Modal>` the view is in, or `null`. */
121
+ export function modalOf(ancestry: Ancestry): Carrier | null {
122
+ const index = ancestry.path.findIndex(
123
+ // Only a host has a string type.
124
+ (fiber) => fiber.type === MODAL_HOST_TYPE,
125
+ );
126
+ return index < 0 ? null : { kind: 'modal', index };
127
+ }
128
+
129
+ /**
130
+ * Until when the carrier is being carried in (`undefined`: it is not): it
131
+ * was pushed, or opened, no longer ago than {@link SECURE_TRANSITION_HOLD_MS}.
132
+ * Its birth is kept for every view that comes later, by the carrier:
133
+ * - a carrier with no alternate was created by the commit running now (a
134
+ * fiber gets its alternate the first time it is rendered again, and every
135
+ * ancestor of a view that mounts is created or rendered again by that
136
+ * commit), as a push or a Modal opening does. A tree mounted whole, as an
137
+ * app starts, is drawn where it is laid out, with no transition: something
138
+ * above the carrier must have been there before (the stack, the screen
139
+ * that opened the Modal);
140
+ * - a screen another view saw pushed onto its stack ({@link noteBirth});
141
+ * - otherwise it was there before, first seen now: when it came is not
142
+ * known (a screen pushed with a spinner, its secure content mounting a
143
+ * commit later), so it is taken as coming now. Once per carrier.
144
+ */
145
+ export function carrierEntering(ancestry: Ancestry, carrier: Carrier, now: number): number | undefined {
146
+ const { path } = ancestry;
147
+ const fiber = path[carrier.index] as FiberLike;
148
+ const key = keyOf(fiber);
149
+ if (!births.has(key)) {
150
+ const mountedWhole =
151
+ fiber.alternate == null &&
152
+ // Nothing below a created carrier can have been there before it.
153
+ // Stryker disable next-line MethodExpression -- so looking from the bottom finds the same
154
+ !path.slice(carrier.index + 1).some((above) => above.alternate != null);
155
+ births.set(key, mountedWhole ? -Infinity : now);
156
+ }
157
+ const born = births.get(key) as number;
158
+ return now - born < SECURE_TRANSITION_HOLD_MS ? born + SECURE_TRANSITION_HOLD_MS : undefined;
159
+ }
160
+
161
+ /**
162
+ * When each carrier came, by {@link keyOf}: a view that mounts, or is shown,
163
+ * while it is still being pushed or opened is carried in with it.
164
+ * `-Infinity`: mounted with the tree it is in, as an app starts.
165
+ */
166
+ const births = new WeakMap<object, number>();
167
+
168
+ /** A screen (by {@link keyOf}) seen pushed onto a stack at `now`, unless its birth is known already. */
169
+ export function noteBirth(key: object, now: number): void {
170
+ if (!births.has(key)) {
171
+ births.set(key, now);
172
+ }
173
+ }
174
+
175
+ /**
176
+ * What stays the same for a host across both fibers of its pair and every
177
+ * commit: Fabric's shared `canonical` (a host's `stateNode` is cloned on
178
+ * every update); on Paper the `stateNode` itself, which both fibers share;
179
+ * the fiber when there is neither.
180
+ */
181
+ export function keyOf(fiber: FiberLike): object {
182
+ const node = fiber.stateNode as { canonical?: unknown } | null | undefined;
183
+ const canonical = node?.canonical;
184
+ if (canonical !== null && typeof canonical === 'object') {
185
+ return canonical;
186
+ }
187
+ return node !== null && typeof node === 'object' ? node : fiber;
188
+ }
189
+
190
+ function deletes(parent: FiberLike | null | undefined, child: FiberLike): boolean {
191
+ const deletions = (parent as { deletions?: unknown } | null | undefined)?.deletions;
192
+ return Array.isArray(deletions) && (deletions.includes(child) || deletions.includes(child.alternate));
193
+ }
194
+
195
+ /**
196
+ * Where in `Ancestry.path` the root of what the running commit deletes is
197
+ * (-1: the view's own host), or `undefined` when no fiber on the way up is
198
+ * being deleted. Only meaningful while that commit unmounts the view.
199
+ */
200
+ export function deletionRoot(ancestry: Ancestry): number | undefined {
201
+ const { self, path } = ancestry;
202
+ // Only an ancestry with no fiber has no self, and it has no path either.
203
+ let child = self as FiberLike;
204
+ for (let index = -1; index < path.length - 1; index += 1) {
205
+ const parent = path[index + 1] as FiberLike;
206
+ // Either fiber of the parent's pair may be the one this commit finished.
207
+ if (deletes(parent, child) || deletes(parent.alternate, child)) {
208
+ return index;
209
+ }
210
+ child = parent;
211
+ }
212
+ return undefined;
213
+ }
214
+
215
+ /** Whether the running commit deletes the carrier itself, or something above it. */
216
+ export function carrierLeaving(ancestry: Ancestry, carrier: Carrier): boolean {
217
+ // Nothing deleted (`undefined`) is never at or above anything.
218
+ return Number(deletionRoot(ancestry)) >= carrier.index;
219
+ }
220
+
221
+ /** How a stack animation moves its screens, as far as covering goes. */
222
+ export type StackMotion = 'sideways' | 'upwards' | 'still' | 'any';
223
+
224
+ const SIDEWAYS: ReadonlySet<unknown> = new Set([
225
+ 'slide_from_right',
226
+ 'slide_from_left',
227
+ 'ios_from_right',
228
+ 'ios_from_left',
229
+ 'simple_push',
230
+ ]);
231
+ const UPWARDS: ReadonlySet<unknown> = new Set(['slide_from_bottom', 'fade_from_bottom']);
232
+ const STILL: ReadonlySet<unknown> = new Set(['fade', 'none']);
233
+ /** iOS presentations that slide a screen up over the one below by default. */
234
+ const MODAL_PRESENTATIONS: ReadonlySet<unknown> = new Set([
235
+ 'modal',
236
+ 'fullScreenModal',
237
+ 'formSheet',
238
+ 'pageSheet',
239
+ 'transparentModal',
240
+ 'containedModal',
241
+ 'containedTransparentModal',
242
+ ]);
243
+
244
+ // A missing Platform throws, and is caught; an empty catch returns undefined all the same.
245
+ // Stryker disable all
246
+ export function platformOS(): unknown {
247
+ try {
248
+ // eslint-disable-next-line @typescript-eslint/no-require-imports -- lazy: only an app has it
249
+ return (require('react-native') as { Platform?: { OS?: unknown } }).Platform?.OS;
250
+ } catch {
251
+ return undefined;
252
+ }
253
+ }
254
+ // Stryker restore all
255
+
256
+ /**
257
+ * How the screen whose host props are `props` is animated in and out: from
258
+ * its `stackAnimation`, and on iOS its presentation. The platform default
259
+ * (sideways on Android 13+, a scale before, sideways on iOS) and anything
260
+ * unknown is `any`.
261
+ */
262
+ export function stackMotionOf(props: unknown, moving = true): StackMotion {
263
+ const { stackAnimation: animation, stackPresentation: presentation } = (props ?? {}) as Record<string, unknown>;
264
+ if (SIDEWAYS.has(animation)) {
265
+ return 'sideways';
266
+ }
267
+ if (UPWARDS.has(animation)) {
268
+ return 'upwards';
269
+ }
270
+ if (STILL.has(animation)) {
271
+ return 'still';
272
+ }
273
+ const defaulted = animation === undefined || animation === 'default';
274
+ if (defaulted && MODAL_PRESENTATIONS.has(presentation) && platformOS() === 'ios') {
275
+ // The card slides up; iOS 13+ also scales the screen below it about its centre.
276
+ return moving ? 'upwards' : 'any';
277
+ }
278
+ return 'any';
279
+ }
280
+
281
+ /** react-native-screens' screen hosts, as a stack's children. */
282
+ const SCREEN_TYPES: ReadonlySet<unknown> = new Set([SCREEN_HOST_TYPE, MODAL_SCREEN_HOST_TYPE]);
283
+
284
+ /** How deep below a stack its screens can be (wrappers such as a stack item). */
285
+ const MAX_SCREEN_DEPTH = 16;
286
+
287
+ /**
288
+ * The screens on `stack` (a committed stack host fiber), by {@link keyOf},
289
+ * with their props: its descendants down to the first screen hosts.
290
+ */
291
+ export function screensOn(stack: FiberLike): Map<object, unknown> {
292
+ // Once a measure pass for every view on the stack.
293
+ return passMemo(stack, () => findScreens(stack));
294
+ }
295
+
296
+ function findScreens(stack: FiberLike): Map<object, unknown> {
297
+ const screens = new Map<object, unknown>();
298
+ const visit = (fiber: FiberLike | null, depth: number): void => {
299
+ for (let child = fiber; child != null; child = child.sibling) {
300
+ // Only a host has a screen's (string) type: the tag only spares a lookup.
301
+ // Stryker disable next-line ConditionalExpression
302
+ if (child.tag === FiberTag.HostComponent && SCREEN_TYPES.has(child.type)) {
303
+ screens.set(keyOf(child), child.memoizedProps);
304
+ } else if (depth < MAX_SCREEN_DEPTH) {
305
+ visit(child.child, depth + 1);
306
+ }
307
+ }
308
+ };
309
+ visit(stack.child, 0);
310
+ return screens;
311
+ }
312
+
313
+ /**
314
+ * Where a stack transition moving as `motion` can draw a view on a screen at
315
+ * `screen`, seen at `view` (`null`: nothing of it is on screen, cut away by
316
+ * a ScrollView, say, and so drawn nowhere as the screen moves either). `moving`:
317
+ * the screen itself is the one pushed or popped; otherwise it is the one
318
+ * uncovered or covered below, which a slide up leaves where it is.
319
+ */
320
+ export function screenCover(
321
+ motion: StackMotion,
322
+ screen: WindowRect,
323
+ view: WindowRect | null,
324
+ moving: boolean,
325
+ ): WindowRect | null {
326
+ if (view === null) {
327
+ return null;
328
+ }
329
+ if (motion === 'any') {
330
+ return screen;
331
+ }
332
+ if (motion === 'sideways') {
333
+ return { x: screen.x, y: view.y, width: screen.width, height: view.height };
334
+ }
335
+ if (motion === 'upwards' && moving) {
336
+ const bottom = Math.max(screen.y + screen.height, view.y + view.height);
337
+ return { x: view.x, y: view.y, width: view.width, height: bottom - view.y };
338
+ }
339
+ return view;
340
+ }
341
+
342
+ /** The window rectangle of a screen host, or the whole surface when it cannot be measured. */
343
+ export function screenRect(fiber: FiberLike): WindowRect {
344
+ let screen: WindowRect | null | undefined;
345
+ try {
346
+ screen = measureFiber(fiber);
347
+ } catch {
348
+ // Unmeasurable: covered as the whole surface below.
349
+ }
350
+ return screen ?? WHOLE_SURFACE;
351
+ }
352
+
353
+ /**
354
+ * Where `carrier` can draw a view seen at `view` while it is carried in or
355
+ * out (`view`: what of it is on screen, `null` when nothing is, `undefined`
356
+ * when it was never measured), or `null` when it does not move it.
357
+ */
358
+ export function carriedCover(
359
+ ancestry: Ancestry,
360
+ carrier: Carrier,
361
+ view: WindowRect | null | undefined,
362
+ ): WindowRect | null {
363
+ const fiber = (ancestry.resolved ?? ancestry.path)[carrier.index] as FiberLike;
364
+ if (carrier.kind === 'screen') {
365
+ const screen = screenRect(fiber);
366
+ return view === undefined ? screen : screenCover(stackMotionOf(fiber.memoizedProps), screen, view, true);
367
+ }
368
+ const animationType = (fiber.memoizedProps as { animationType?: unknown } | null | undefined)?.animationType;
369
+ // Never measured, or nothing of it on screen: it is drawn nowhere it was measured either.
370
+ if (view == null) {
371
+ return null;
372
+ }
373
+ if (animationType === 'slide') {
374
+ return { x: view.x, y: view.y, width: view.width, height: WHOLE_SURFACE.height - view.y };
375
+ }
376
+ return null;
377
+ }
378
+
379
+ /**
380
+ * A screen pushed onto, or popped off, a stack, as the screens left on it
381
+ * move with it until `until`.
382
+ */
383
+ export interface StackChange {
384
+ /** How the screens below it move: the pushed or popped screen's `stackMotionOf(props, false)`. */
385
+ readonly motion: StackMotion;
386
+ readonly until: number;
387
+ /** The screen pushed or popped, by {@link keyOf}. */
388
+ readonly moving: object;
389
+ /** The screen it covers (a push) or uncovers (a pop), by {@link keyOf}; `undefined`: not known. */
390
+ readonly below: object | undefined;
391
+ }
392
+
393
+ /** A view on a stack's screen, told when another screen on that stack is pushed or popped. */
394
+ export type StackNeighbour = (change: StackChange) => void;
395
+
396
+ /** What is known of a stack: kept by the stack, so a view that comes later still learns it. */
397
+ interface StackRecord {
398
+ /** Its screens as last read by any view, by {@link keyOf}, with their props; `undefined`: never read. */
399
+ screens: Map<object, unknown> | undefined;
400
+ /** Its recent changes, oldest first, the ones whose hold is over dropped as it is read. */
401
+ changes: StackChange[];
402
+ /** The views on its screens, told of a change as a view on the moving screen makes it. */
403
+ readonly views: Set<StackNeighbour>;
404
+ }
405
+
406
+ /** Every stack's record, by the stack's {@link keyOf}. */
407
+ const records = new WeakMap<object, StackRecord>();
408
+
409
+ function recordOf(stack: object): StackRecord {
410
+ let record = records.get(stack);
411
+ if (record === undefined) {
412
+ // Stryker disable next-line ArrayDeclaration -- its changes are filtered before they are read
413
+ record = { screens: undefined, changes: [], views: new Set() };
414
+ records.set(stack, record);
415
+ }
416
+ return record;
417
+ }
418
+
419
+ /** The changes still within their hold at `now`. */
420
+ function current(record: StackRecord, now: number): StackChange[] {
421
+ // Stryker disable next-line EqualityOperator -- one millisecond either way, at the end of a hold
422
+ record.changes = record.changes.filter((change) => change.until > now);
423
+ return record.changes;
424
+ }
425
+
426
+ /** Adds `neighbour` to the views on `stack`'s screens, until the returned function is called. */
427
+ export function joinStack(stack: object, neighbour: StackNeighbour): () => void {
428
+ const { views } = recordOf(stack);
429
+ views.add(neighbour);
430
+ return () => {
431
+ views.delete(neighbour);
432
+ };
433
+ }
434
+
435
+ /**
436
+ * A view on the screen `change.moving` saw it pushed or popped (`leaving`):
437
+ * records it for the stack, and tells every view on it now; a view that
438
+ * reads the stack later in the hold learns it then. A popped screen is off
439
+ * the stack's screens from now: its views, gone, read the stack no more (a
440
+ * pushed one's view reads the stack itself).
441
+ */
442
+ export function stackMoving(stack: object, change: StackChange, leaving: boolean): void {
443
+ const record = recordOf(stack);
444
+ current(record, change.until - SECURE_TRANSITION_HOLD_MS);
445
+ record.changes.push(change);
446
+ // A pushed screen's own view reads the stack before and after it tells it: dropping it changes nothing kept.
447
+ // Stryker disable next-line ConditionalExpression
448
+ if (leaving) {
449
+ record.screens?.delete(change.moving);
450
+ }
451
+ for (const neighbour of [...record.views]) {
452
+ neighbour(change);
453
+ }
454
+ }
455
+
456
+ /** The last of `screens` (a stack's children in order): the one on top. */
457
+ function topOf(screens: ReadonlyMap<object, unknown>): object | undefined {
458
+ return [...screens.keys()].pop();
459
+ }
460
+
461
+ /**
462
+ * Reads `stack` (a committed stack host fiber), whose screens are `screens`
463
+ * now, against what any view last read of it: a screen pushed or popped
464
+ * since is recorded as moving from `now`, unless it is recorded already.
465
+ * Read for the first time, it is compared with the stack's other fiber,
466
+ * its render before (a pop no view on it saw may have just happened).
467
+ * Returns every change still within its hold.
468
+ */
469
+ export function observeStack(stack: FiberLike, screens: Map<object, unknown>, now: number): readonly StackChange[] {
470
+ const record = recordOf(keyOf(stack));
471
+ const changes = current(record, now);
472
+ const before = record.screens ?? (stack.alternate == null ? screens : screensOn(stack.alternate));
473
+ record.screens = screens;
474
+ const pushed = [...screens].filter(([key]) => !before.has(key));
475
+ const popped = [...before].filter(([key]) => !screens.has(key));
476
+ // Seen come: a view on it that mounts later in its push is carried in from now.
477
+ pushed.forEach(([key]) => noteBirth(key, now));
478
+ const moved = [
479
+ ...pushed.map(([key, props]) => ({ key, props, below: topOf(before) })),
480
+ ...popped.map(([key, props]) => ({ key, props, below: topOf(screens) })),
481
+ ];
482
+ for (const { key, props, below } of moved) {
483
+ if (!changes.some((change) => change.moving === key)) {
484
+ changes.push({ motion: stackMotionOf(props, false), until: now + SECURE_TRANSITION_HOLD_MS, moving: key, below });
485
+ }
486
+ }
487
+ return changes;
488
+ }
@@ -0,0 +1,22 @@
1
+ import { PixelRatio, Platform } from 'react-native';
2
+
3
+ /**
4
+ * How many target-SDK units there are per React Native point, for this
5
+ * platform.
6
+ *
7
+ * The two SDKs take different units and the iOS header states it: "Coordinates
8
+ * are in points in the screen's coordinate space, origin top-left — the same
9
+ * convention as `+[Bugsee addSecureRectangle:]` (Android uses pixels, matching
10
+ * its own `addSecureRectangle`)."
11
+ *
12
+ * React Native measures in density-independent points, which ARE iOS points
13
+ * and are NOT Android pixels. So iOS is 1:1 and Android scales by the device
14
+ * pixel ratio.
15
+ *
16
+ * Read per call rather than cached: the ratio can change under the app when a
17
+ * display configuration changes, and a stale value redacts the wrong region
18
+ * while continuing to look correct.
19
+ */
20
+ export function secureRectangleScale(): number {
21
+ return Platform.OS === 'android' ? PixelRatio.get() : 1;
22
+ }
package/src/status.ts ADDED
@@ -0,0 +1,16 @@
1
+ // Extracted from index.ts so the wrapper's event layer can derive a status
2
+ // without importing the facade -- that would be a cycle: index -> wrapper ->
3
+ // index. Nothing about the values changed; index re-exports them.
4
+
5
+ /**
6
+ * Mirrors the SDKs' own status enum. Both platforms bring capture up off the
7
+ * main thread, so `launch` returning is not the same as being live — poll or
8
+ * observe this rather than assuming.
9
+ */
10
+ export const Status = {
11
+ Stopped: 0,
12
+ Launching: 1,
13
+ Launched: 2,
14
+ Stopping: 3,
15
+ } as const;
16
+ export type Status = (typeof Status)[keyof typeof Status];
package/src/version.ts ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * This package's own version, reported to the SDK as `wrapperVersion`.
3
+ *
4
+ * Read from package.json rather than duplicated here, so it cannot disagree
5
+ * with what npm published. A test asserts the two match.
6
+ */
7
+ import pkg from '../package.json';
8
+
9
+ export const PACKAGE_VERSION: string = pkg.version;
@@ -0,0 +1,105 @@
1
+ /**
2
+ * `Bugsee.wrap`: the app's own opt-in for view-hierarchy ("vh") capture. See
3
+ * `./requests.ts` for what actually answers the native SDK's `'vh'` data
4
+ * request once this is in place.
5
+ */
6
+ import { useLayoutEffect, useRef } from 'react';
7
+ import type { ComponentRef, ComponentType, ReactElement } from 'react';
8
+ import { View } from 'react-native';
9
+ import { RootErrorReporter } from '../exceptions/RootErrorReporter';
10
+ import { VH_ANCHOR_NATIVE_ID } from './constants';
11
+ import { markWrapComponent, registerAnchor, unregisterAnchor } from './requests';
12
+
13
+ // Re-exported from the leaf `./constants` module (see its own doc comment
14
+ // for why the constant does not live here directly): `anchor.tsx` is this
15
+ // value's documented public home, per the brief, even though `requests.ts`
16
+ // no longer needs to import THIS module to read it.
17
+ export { VH_ANCHOR_NATIVE_ID };
18
+
19
+ /**
20
+ * `displayName`, then a plain function's `.name`, then -- for `React.memo`
21
+ * and `React.forwardRef`, which are plain OBJECTS, not functions, and so
22
+ * have no `.name` of their own -- the same unwrap `walk.ts`'s own
23
+ * `compositeClassName` does for a fiber: `.type` (what `memo(...)` wraps) or
24
+ * `.render` (what `forwardRef(...)` wraps), recursively. `'Anonymous'` only
25
+ * once none of those resolves to a non-empty string.
26
+ *
27
+ * Never `??`: an anonymous function's `.name` is `''`, not `undefined`, so
28
+ * `??` alone would never fall through past it to `'Anonymous'`.
29
+ */
30
+ function nameOf(component: unknown): string {
31
+ if (typeof component === 'function' || (typeof component === 'object' && component !== null)) {
32
+ const named = component as { displayName?: unknown; name?: unknown; type?: unknown; render?: unknown };
33
+ if (typeof named.displayName === 'string' && named.displayName.length > 0) {
34
+ return named.displayName;
35
+ }
36
+ if (typeof named.name === 'string' && named.name.length > 0) {
37
+ return named.name;
38
+ }
39
+ if (named.type !== undefined) {
40
+ return nameOf(named.type);
41
+ }
42
+ if (named.render !== undefined) {
43
+ return nameOf(named.render);
44
+ }
45
+ }
46
+ return 'Anonymous';
47
+ }
48
+
49
+ /**
50
+ * Wraps the app's root component so the native SDK can capture the on-screen
51
+ * view hierarchy ("vh") -- the anonymised tree of what is on screen (no text,
52
+ * no prop but `testID`/`nativeID`) that the SDK attaches to a report or pulls
53
+ * for a live capture. Without `Bugsee.wrap`, the SDK's `'vh'` request always
54
+ * answers with nothing: there is no registered root for the walk to start
55
+ * from.
56
+ *
57
+ * Renders `Root` inside `<RootErrorReporter>` (uncaught render errors),
58
+ * alongside an invisible, zero-size anchor view that is never drawn and never
59
+ * intercepts a touch. Mounting the wrapped tree registers that anchor with the
60
+ * view-tree walk; unmounting it unregisters it -- see `./requests.ts`'s
61
+ * `registerAnchor`/`unregisterAnchor`, which is what turns the native request
62
+ * on and off.
63
+ *
64
+ * Usage: `AppRegistry.registerComponent(appName, () => Bugsee.wrap(App))`.
65
+ */
66
+ export function wrap<P extends object>(Root: ComponentType<P>): ComponentType<P> {
67
+ function BugseeRoot(props: P): ReactElement {
68
+ const anchorRef = useRef<ComponentRef<typeof View>>(null);
69
+
70
+ // A layout effect, not a passive one, for the same reason `BugseeSecure`
71
+ // uses one: it runs in the commit, so the anchor is registered before the
72
+ // first frame paints rather than after it. `[]`: the anchor instance
73
+ // registered here does not change across `BugseeRoot`'s own re-renders.
74
+ useLayoutEffect(() => {
75
+ const instance = anchorRef.current;
76
+ if (instance === null) {
77
+ return undefined;
78
+ }
79
+ registerAnchor(instance);
80
+ return () => {
81
+ unregisterAnchor(instance);
82
+ };
83
+ }, []);
84
+
85
+ return (
86
+ <>
87
+ <RootErrorReporter>
88
+ <Root {...props} />
89
+ </RootErrorReporter>
90
+ <View
91
+ ref={anchorRef}
92
+ nativeID={VH_ANCHOR_NATIVE_ID}
93
+ collapsable={false}
94
+ pointerEvents="none"
95
+ style={{ position: 'absolute', width: 0, height: 0 }}
96
+ />
97
+ </>
98
+ );
99
+ }
100
+
101
+ BugseeRoot.displayName = `BugseeRoot(${nameOf(Root)})`;
102
+ markWrapComponent(BugseeRoot);
103
+
104
+ return BugseeRoot;
105
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * A leaf module (no imports of its own) so that both `anchor.tsx` and
3
+ * `requests.ts` can read `VH_ANCHOR_NATIVE_ID` without importing each other
4
+ * for it. Before this file existed, `requests.ts` imported the constant
5
+ * straight from `anchor.tsx`, which also imports `registerAnchor`/
6
+ * `unregisterAnchor`/`markWrapComponent` from `requests.ts` -- a circular
7
+ * import that happened to be safe (every cross-reference was read inside a
8
+ * function body, never at module top level) but would silently break the
9
+ * moment either side read the other's export at its own top level instead.
10
+ */
11
+
12
+ /**
13
+ * The `nativeID` carried by the invisible anchor view `wrap` (`anchor.tsx`)
14
+ * renders, so `requests.ts`'s view-tree walk can recognise that view's own
15
+ * fiber by its props (the same `nativeID` a host fiber's own props may
16
+ * legitimately carry, per the walk's privacy rule) and leave it out of the
17
+ * captured tree, rather than by trying to keep hold of the fiber itself
18
+ * across renders.
19
+ */
20
+ export const VH_ANCHOR_NATIVE_ID = '__bugsee_view_tree_anchor';