Skip to content

Commit f87f058

Browse files
arturovtthePunderWoman
authored andcommittedJan 31, 2024
fix(zone.js): add __Zone_ignore_on_properties to ZoneGlobalConfigurations (#50737)
This commit updates the signature of the `ZoneGlobalConfigurations` interface and adds missing `__Zone_ignore_on_properties` property, which may be setup to ignore specific `on` properties from being patched. PR Close #50737
1 parent d6e4931 commit f87f058

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed
 

‎packages/zone.js/lib/zone.configurations.api.ts

+42
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,48 @@ declare global {
563563
*/
564564
__zone_symbol__UNPATCHED_EVENTS?: string[];
565565

566+
/**
567+
* Define a list of `on` properties to be ignored when being monkey patched by the `zone.js`.
568+
*
569+
* By default, `zone.js` monkey patches `on` properties on inbuilt browser classes as
570+
* `WebSocket`, `XMLHttpRequest`, `Worker`, `HTMLElement` and others (see `patchTargets` in
571+
* `propertyDescriptorPatch`). `on` properties may be `WebSocket.prototype.onclose`,
572+
* `XMLHttpRequest.prototype.onload`, etc.
573+
*
574+
* Sometimes, we're not able to customise third-party libraries, which setup `on` listeners.
575+
* Given a library creates a `Websocket` and sets `socket.onmessage`, this will impact
576+
* performance if the `onmessage` property is set within the Angular zone, because this will
577+
* trigger change detection on any message coming through the socket. We can exclude specific
578+
* targets and their `on` properties from being patched by zone.js.
579+
*
580+
* Users can achieve this by defining `__Zone_ignore_on_properties`, it expects an array of
581+
* objects where `target` is the actual object `on` properties will be set on:
582+
* ```
583+
* __Zone_ignore_on_properties = [
584+
* {
585+
* target: WebSocket.prototype,
586+
* ignoreProperties: ['message', 'close', 'open']
587+
* }
588+
* ];
589+
* ```
590+
*
591+
* In order to check whether `on` properties have been successfully ignored or not, it's enough
592+
* to open the console in the browser, run `WebSocket.prototype` and expand the object, we
593+
* should see the following:
594+
* ```
595+
* {
596+
* __zone_symbol__ononclosepatched: true,
597+
* __zone_symbol__ononerrorpatched: true,
598+
* __zone_symbol__ononmessagepatched: true,
599+
* __zone_symbol__ononopenpatched: true
600+
* }
601+
* ```
602+
* These `__zone_symbol__*` properties are set by zone.js when `on` properties have been patched
603+
* previously. When `__Zone_ignore_on_properties` is setup, we should not see those properties
604+
* on targets.
605+
*/
606+
__Zone_ignore_on_properties?: {target: any; ignoreProperties: string[];}[];
607+
566608
/**
567609
* Define the event names of the passive listeners.
568610
*

0 commit comments

Comments
 (0)
Please sign in to comment.