Skip to content

Commit 1e0c1f8

Browse files
robhoganmeta-codesync[bot]
authored andcommitted
Add reporter hook to loadBundleFromServer (#56155)
Summary: Pull Request resolved: #56155 Add a `global.__BUNDLE_LOADER_REPORTER__` optional hook to `loadBundleFromServer.js`, following the same pattern as `global.__NETWORK_REPORTER__` in `RCTNetworking`. This provides an OSS-safe abstraction for reporting dev-mode bundle load timing and failure events. The OSS side calls `onStart`/`onSuccess`/`onError` through optional chaining, making it a complete no-op when no reporter is installed. Changelog: [General][Added] Call methods on `global.__BUNDLE_LOADER_REPORTER__`, if given, during dev-mode bundler loads from Metro Reviewed By: huntie Differential Revision: D97115145 fbshipit-source-id: bba55aaddf20c7aa774699b0cddf9e6cc0a34366
1 parent d21ffc9 commit 1e0c1f8

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

packages/react-native/Libraries/Core/Devtools/loadBundleFromServer.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ import getDevServer from './getDevServer';
1515

1616
declare var global: {
1717
globalEvalWithSourceUrl?: (string, string) => unknown,
18+
__BUNDLE_LOADER_REPORTER__?: {
19+
onStart: (url: string | URL) => void,
20+
onSuccess: (url: string | URL) => void,
21+
onError: (url: string | URL, error: Error) => void,
22+
},
1823
...
1924
};
2025

@@ -153,6 +158,7 @@ export default function loadBundleFromServer(
153158
}
154159
DevLoadingView.showMessage('Downloading...', 'load');
155160
++pendingRequests;
161+
global.__BUNDLE_LOADER_REPORTER__?.onStart(requestUrl);
156162

157163
loadPromise = asyncRequest(requestUrl)
158164
.then<void>(({body, headers}) => {
@@ -183,9 +189,11 @@ export default function loadBundleFromServer(
183189
// eslint-disable-next-line no-eval
184190
eval(body);
185191
}
192+
global.__BUNDLE_LOADER_REPORTER__?.onSuccess(requestUrl);
186193
})
187194
.catch<void>(e => {
188195
cachedPromisesByUrl.delete(requestUrl);
196+
global.__BUNDLE_LOADER_REPORTER__?.onError(requestUrl, e);
189197
throw e;
190198
})
191199
.finally(() => {

0 commit comments

Comments
 (0)