diff --git a/src/ch5-base/ch5-base-class.ts b/src/ch5-base/ch5-base-class.ts index 963459812..d91b1b042 100644 --- a/src/ch5-base/ch5-base-class.ts +++ b/src/ch5-base/ch5-base-class.ts @@ -1079,17 +1079,16 @@ export abstract class Ch5BaseClass extends HTMLElement implements ICh5CommonAttr /** * Initialize common mutation observer used in each component for checking component visibility * + * The ancestor registration was removed for the reason documented on + * Ch5Common.initCommonMutationObserver(). Kept in sync with that method deliberately - no call site + * in this class is currently active, but the two implementations should not diverge. + * * @param element */ + // eslint-disable-next-line @typescript-eslint/no-unused-vars public initCommonMutationObserver(element: Ch5BaseClass) { this._commonMutationObserver = new Ch5MutationObserver(this); this._commonMutationObserver.isConnected = true; - - let target = element as HTMLElement; - while (Ch5MutationObserver.checkElementValidity(target)) { - this._commonMutationObserver.observe(target); - target = target.parentNode as HTMLElement; - } } public disconnectCommonMutationObserver() { diff --git a/src/ch5-common/ch5-common.ts b/src/ch5-common/ch5-common.ts index c663eef35..fd9955534 100644 --- a/src/ch5-common/ch5-common.ts +++ b/src/ch5-common/ch5-common.ts @@ -1821,17 +1821,23 @@ export class Ch5Common extends HTMLElement implements ICh5CommonAttributes { /** * Initialize common mutation observer used in each component for checking component visibility * + * The observer used to be registered on every ancestor of the component up to , watching the + * 'style' and 'inert' attributes. Every notification read offsetParent and getComputedStyle in order + * to maintain elementIsVisible - a flag nothing reads, since the only two consumers (in ch5-image) + * are commented out. Measured on a project with ~2400 components across 17 preloaded pages: ~12k + * observe() registrations at load, and per page flip ~3600 observer callbacks doing ~13k + * getComputedStyle + offsetParent reads, about 65% of total page-flip time. + * + * The observer object is still created so that disconnectCommonMutationObserver() and its + * isNil/isEmpty guards keep working; only the ancestor registration is gone. Ch5BaseClass, used by + * the newer components, already has its initCommonMutationObserver() call commented out. + * * @param element */ + // eslint-disable-next-line @typescript-eslint/no-unused-vars public initCommonMutationObserver(element: Ch5Common) { this._commonMutationObserver = new Ch5MutationObserver(this); this._commonMutationObserver.isConnected = true; - - let target = element as HTMLElement; - while (Ch5MutationObserver.checkElementValidity(target)) { - this._commonMutationObserver.observe(target); - target = target.parentNode as HTMLElement; - } } public updateElementVisibilityInViewport(visibility: boolean) {