Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/ch5-base/ch5-base-class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
18 changes: 12 additions & 6 deletions src/ch5-common/ch5-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 <body>, 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) {
Expand Down