Skip to content

Commit c080622

Browse files
committed
fix(content): add 100ms debounce to ResizeObserver and improve type safety for MutationObserver
1 parent 3d62d93 commit c080622

File tree

37 files changed

+15
-7
lines changed

37 files changed

+15
-7
lines changed

core/src/components/content/content.tsx

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -441,8 +441,10 @@ export class Content implements ComponentInterface {
441441
}
442442

443443
if ('ResizeObserver' in window) {
444+
let timeout: any;
444445
this.resizeObserver = new ResizeObserver(() => {
445-
this.resize();
446+
clearTimeout(timeout);
447+
timeout = setTimeout(() => this.resize(), 100);
446448
});
447449
}
448450

@@ -452,14 +454,14 @@ export class Content implements ComponentInterface {
452454

453455
for (const mutation of mutations) {
454456
if (mutation.type === 'childList') {
455-
mutation.addedNodes.forEach((node: any) => {
456-
if (node.tagName === 'ION-HEADER' || node.tagName === 'ION-FOOTER') {
457+
mutation.addedNodes.forEach((node: Node) => {
458+
if (node instanceof HTMLElement && (node.tagName === 'ION-HEADER' || node.tagName === 'ION-FOOTER')) {
457459
shouldUpdate = true;
458460
}
459461
});
460462

461-
mutation.removedNodes.forEach((node: any) => {
462-
if (node.tagName === 'ION-HEADER' || node.tagName === 'ION-FOOTER') {
463+
mutation.removedNodes.forEach((node: Node) => {
464+
if (node instanceof HTMLElement && (node.tagName === 'ION-HEADER' || node.tagName === 'ION-FOOTER')) {
463465
shouldUpdate = true;
464466
}
465467
});
@@ -499,8 +501,14 @@ export class Content implements ComponentInterface {
499501
const headers = this.el.parentElement.querySelectorAll('ion-header');
500502
const footers = this.el.parentElement.querySelectorAll('ion-footer');
501503

502-
headers.forEach((header) => this.resizeObserver!.observe(header));
503-
footers.forEach((footer) => this.resizeObserver!.observe(footer));
504+
const observer = this.resizeObserver;
505+
506+
if (observer === null || observer === undefined) {
507+
return;
508+
}
509+
510+
headers.forEach((header) => observer.observe(header));
511+
footers.forEach((footer) => observer.observe(footer));
504512
}
505513

506514
private onScrollStart() {
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)