Skip to content

Commit 79ea0bd

Browse files
authored
Merge pull request sveltejs#1822 from aphitiel/sveltejsgh-1743
move resize handler from _beforecreate to _after.. (fixes sveltejs#1743)
2 parents 585abd9 + 4d49839 commit 79ea0bd

File tree

5 files changed

+29
-2
lines changed

5 files changed

+29
-2
lines changed

src/compile/render-dom/wrappers/Element/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ export default class ElementWrapper extends Wrapper {
529529
renderer.hasComplexBindings = true;
530530

531531
block.builders.hydrate.addLine(
532-
`#component.root._beforecreate.push(${handler});`
532+
`#component.root._aftercreate.push(${handler});`
533533
);
534534
}
535535
});

test/helpers.js

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export function tryToReadFile(file) {
4848
export const virtualConsole = new jsdom.VirtualConsole();
4949
const { window } = new jsdom.JSDOM('<main></main>', {virtualConsole});
5050
global.document = window.document;
51+
global.getComputedStyle = window.getComputedStyle;
52+
global.navigator = {userAgent: 'fake'};
5153

5254
export function env() {
5355
window._svelteTransitionManager = null;

test/js/samples/bind-width-height/expected.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function create_main_fragment(component, ctx) {
1212
c() {
1313
div = createElement("div");
1414
div.textContent = "some content";
15-
component.root._beforecreate.push(div_resize_handler);
15+
component.root._aftercreate.push(div_resize_handler);
1616
},
1717

1818
m(target, anchor) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export default {
2+
'skip-ssr': true,
3+
4+
test(assert, component, target) {
5+
assert.ok(component.onstateRanBeforeOncreate);
6+
assert.ok(!component.onupdateRanBeforeOncreate);
7+
}
8+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<div bind:offsetWidth=width></div>
2+
<script>
3+
export default {
4+
onstate() {
5+
this.onstateRan = true;
6+
},
7+
8+
onupdate() {
9+
this.onupdateRan = true;
10+
},
11+
12+
oncreate() {
13+
this.onstateRanBeforeOncreate = this.onstateRan;
14+
this.onupdateRanBeforeOncreate = this.onupdateRan;
15+
}
16+
};
17+
</script>

0 commit comments

Comments
 (0)