Skip to content

Commit 32d8563

Browse files
committed
fix: remove global since the problem was 2 XHRInterceptor instance
1 parent 563bfe2 commit 32d8563

File tree

3 files changed

+11
-24
lines changed

3 files changed

+11
-24
lines changed

packages/network-activity-plugin/src/react-native/http/network-inspector.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ import {
1414

1515
const networkRequestsRegistry = getNetworkRequestsRegistry();
1616
const overridesRegistry = getOverridesRegistry();
17+
const queuedClient = getQueuedClientWrapper();
1718

18-
const setupXHRInterceptor = (
19-
queuedClient: ReturnType<typeof getQueuedClientWrapper>,
20-
): void => {
19+
const setupXHRInterceptor = (): void => {
2120
XHRInterceptor.disableInterception();
2221
XHRInterceptor.setSendCallback((data, request) =>
2322
setupRequestTracking(queuedClient, networkRequestsRegistry, data, request),
@@ -34,14 +33,14 @@ export type BootRecordingOptions = BootClientOptions;
3433
* Enable XHR interception early to capture boot-time requests.
3534
*/
3635
const enableBootTimeInterception = (options?: BootRecordingOptions): void => {
37-
const queuedClient = getQueuedClientWrapper(options);
36+
queuedClient.setMaxQueueSize(options?.maxQueueSize ?? 200);
3837

3938
if (queuedClient.isBootInterceptionEnabled()) {
4039
return;
4140
}
4241

4342
queuedClient.enableBootInterception();
44-
setupXHRInterceptor(queuedClient);
43+
setupXHRInterceptor();
4544
};
4645

4746
export const withOnBootNetworkActivityRecording = (

packages/network-activity-plugin/src/react-native/http/network-requests-registry.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,10 @@ export type NetworkRequestRegistry = {
1212

1313
const REQUEST_TTL = 1000 * 60 * 5; // 5 minutes
1414

15-
declare global {
16-
var __rozeniteNetworkRequestsRegistry:
17-
| Map<string, NetworkRegistryEntry>
18-
| undefined;
19-
}
2015

2116
export const getNetworkRequestsRegistry = (): NetworkRequestRegistry => {
22-
if (!global.__rozeniteNetworkRequestsRegistry) {
23-
global.__rozeniteNetworkRequestsRegistry = new Map();
24-
}
25-
const registry = global.__rozeniteNetworkRequestsRegistry;
26-
17+
const registry: Map<string, NetworkRegistryEntry> = new Map();
18+
2719
const trimRegistry = (): void => {
2820
const now = Date.now();
2921

packages/network-activity-plugin/src/react-native/http/queued-client-wrapper.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,16 +88,12 @@ export type BootClientOptions = {
8888
maxQueueSize?: number;
8989
};
9090

91+
let instance: QueuedClientWrapper | null = null;
92+
9193
export const getQueuedClientWrapper = (
92-
options?: BootClientOptions,
9394
): QueuedClientWrapper => {
94-
if (!global.__rozeniteQueuedClientWrapper) {
95-
global.__rozeniteQueuedClientWrapper = new QueuedClientWrapper();
96-
}
97-
98-
if (options?.maxQueueSize !== undefined) {
99-
global.__rozeniteQueuedClientWrapper.setMaxQueueSize(options.maxQueueSize);
95+
if (!instance) {
96+
instance = new QueuedClientWrapper();
10097
}
101-
102-
return global.__rozeniteQueuedClientWrapper;
98+
return instance;
10399
};

0 commit comments

Comments
 (0)