angular/packages/zone.js/lib/browser/custom-elements.ts
arturovt 1c990cdb29 fix(zone.js): patch form-associated custom element callbacks (#50686)
This commit updates the implementation of the `customElements` patch and also
patches FACE callbacks (`formAssociatedCallback`, `formDisabledCallback`, `formResetCallback`
and `formStateRestoreCallback`). This now allows invoking those callbacks in the same zone
where the custom element has been defined.

PR Close #50686
2024-02-12 08:50:55 -08:00

23 lines
882 B
TypeScript

/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
export function patchCustomElements(_global: any, api: _ZonePrivate) {
const {isBrowser, isMix} = api.getGlobalObjects()!;
if ((!isBrowser && !isMix) || !_global['customElements'] || !('customElements' in _global)) {
return;
}
// https://html.spec.whatwg.org/multipage/custom-elements.html#concept-custom-element-definition-lifecycle-callbacks
const callbacks = [
'connectedCallback', 'disconnectedCallback', 'adoptedCallback', 'attributeChangedCallback',
'formAssociatedCallback', 'formDisabledCallback', 'formResetCallback',
'formStateRestoreCallback'
];
api.patchCallbacks(api, _global.customElements, 'customElements', 'define', callbacks);
}