Skip to content

Commit e5b0b62

Browse files
fix: ensure bind:offsetHeight updates (#8096)
fixes #4233 by calling the callback after the iframe loads, which may be asynchronous --------- Co-authored-by: Yuichiro Yamashita <[email protected]>
1 parent 709264a commit e5b0b62

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/runtime/internal/dom.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,10 @@ export function add_resize_listener(node: HTMLElement, fn: () => void) {
624624
iframe.src = 'about:blank';
625625
iframe.onload = () => {
626626
unsubscribe = listen(iframe.contentWindow, 'resize', fn);
627+
628+
// make sure an initial resize event is fired _after_ the iframe is loaded (which is asynchronous)
629+
// see https://github.com/sveltejs/svelte/issues/4233
630+
fn();
627631
};
628632
}
629633

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export default {
2+
async test({ assert, component }) {
3+
assert.equal(component.toggle, true);
4+
assert.equal(component.offsetHeight, 800);
5+
}
6+
};
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<script>
2+
export let offsetHeight;
3+
export let offsetWidth;
4+
export let toggle = false;
5+
$: if (offsetWidth) {
6+
toggle = true;
7+
}
8+
</script>
9+
10+
<div class:toggle>
11+
<div bind:offsetHeight bind:offsetWidth>{offsetHeight}</div>
12+
</div>
13+
14+
<style>
15+
.toggle > div {
16+
height: 800px;
17+
}
18+
</style>

0 commit comments

Comments
 (0)