Skip to content

Commit 457e9a8

Browse files
committed
Disconnect old observer when done
1 parent 1524120 commit 457e9a8

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/common/gui/base/List.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ export class List<T, VH extends ViewHolder<T>> implements ClassComponent<ListAtt
121121
private activeIndex: number | null = null
122122
private lastThemeId: ThemeId = theme.themeId
123123

124+
private observer: ResizeObserver | null = null
125+
124126
view({ attrs }: Vnode<ListAttrs<T, VH>>) {
125127
const oldRenderConfig = this.lastAttrs?.renderConfig
126128
this.lastAttrs = attrs
@@ -134,7 +136,9 @@ export class List<T, VH extends ViewHolder<T>> implements ClassComponent<ListAtt
134136
// Some of the tech-savvy users like to disable *all* "experimental features" in their Safari devices and there's also a toggle to disable
135137
// ResizeObserver. Since the app works without it anyway we just fall back to not handling the resize events.
136138
if (typeof ResizeObserver !== "undefined") {
137-
createResizeObserver(() => this.updateSize()).observe(this.containerDom)
139+
this.observer?.disconnect()
140+
this.observer = createResizeObserver(() => this.updateSize())
141+
this.observer.observe(this.containerDom)
138142
} else {
139143
requestAnimationFrame(() => this.updateSize())
140144
}
@@ -182,6 +186,11 @@ export class List<T, VH extends ViewHolder<T>> implements ClassComponent<ListAtt
182186
)
183187
}
184188

189+
onremove(): any {
190+
this.observer?.disconnect()
191+
this.observer = null
192+
}
193+
185194
private createSwipeHandler() {
186195
return new ListSwipeHandler<T, VH>(this.containerDom!, {
187196
width: () => this.width,

0 commit comments

Comments
 (0)