Skip to content

Commit 8dacc27

Browse files
authored
fix: centerOnInit timing issue (#468)
1 parent 53e1d38 commit 8dacc27

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

src/core/instance.core.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,11 +176,22 @@ export class ZoomPanPinch {
176176
if (centerOnInit) {
177177
this.setCenter();
178178
this.observer = new ResizeObserver(() => {
179-
this.onInitCallbacks.forEach((callback) => callback(getContext(this)));
180-
this.setCenter();
181-
this.observer?.disconnect();
179+
const currentWidth = contentComponent.offsetWidth;
180+
const currentHeight = contentComponent.offsetHeight;
181+
182+
if (currentWidth > 0 || currentHeight > 0) {
183+
this.onInitCallbacks.forEach((callback) => callback(getContext(this)));
184+
this.setCenter();
185+
186+
this.observer?.disconnect();
187+
}
182188
});
183189

190+
// if nothing about the contentComponent has changed after 5 seconds, disconnect the observer
191+
setTimeout(() => {
192+
this.observer?.disconnect();
193+
}, 5000);
194+
184195
// Start observing the target node for configured mutations
185196
this.observer.observe(contentComponent);
186197
}

0 commit comments

Comments
 (0)