Skip to content

Commit c4975ab

Browse files
arturovtwaltjones
andauthoredMar 7, 2025··
perf: make Zone check framework agnostic (#1151)
In this commit, we prevent coupling the Zone check to Angular, as zone.js can be used with any framework. We always ensure that we get the root zone and run the callback within it. Co-authored-by: Walt Jones <walt.jones@rollbar.com>
1 parent 467facb commit c4975ab

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed
 

‎src/browser/transport.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -115,19 +115,21 @@ Transport.prototype.postJsonPayload = function (
115115
);
116116
};
117117

118-
// Wraps _makeRequest and if Angular 2+ Zone.js is detected, changes scope
119-
// so Angular change detection isn't triggered on each API call.
120-
// This is the equivalent of runOutsideAngular().
121-
//
118+
// Wraps `_makeRequest` if zone.js is being used, ensuring that Rollbar
119+
// API calls are not intercepted by any child forked zones.
120+
// This is equivalent to `NgZone.runOutsideAngular` in Angular.
122121
Transport.prototype._makeZoneRequest = function () {
123122
var gWindow =
124123
(typeof window != 'undefined' && window) ||
125124
(typeof self != 'undefined' && self);
126-
var currentZone = gWindow && gWindow.Zone && gWindow.Zone.current;
125+
// Whenever zone.js is loaded and `Zone` is exposed globally, access
126+
// the root zone to ensure that requests are always made within it.
127+
// This approach is framework-agnostic, regardless of which
128+
// framework zone.js is used with.
129+
var rootZone = gWindow && gWindow.Zone && gWindow.Zone.root;
127130
var args = Array.prototype.slice.call(arguments);
128131

129-
if (currentZone && currentZone._name === 'angular') {
130-
var rootZone = currentZone._parent;
132+
if (rootZone) {
131133
var self = this;
132134
rootZone.run(function () {
133135
self._makeRequest.apply(undefined, args);

0 commit comments

Comments
 (0)
Please sign in to comment.