diff --git a/src/compile/dom/index.ts b/src/compile/dom/index.ts index d66b54ec14..3e201c1a74 100644 --- a/src/compile/dom/index.ts +++ b/src/compile/dom/index.ts @@ -224,11 +224,12 @@ export default function dom( ${compiler.slots.size && `this.slots = {};`} + ${templateProperties.onstate && `%onstate.call(this, { changed: @assignTrue({}, this._state), current: this._state });`} + this._fragment = @create_main_fragment(this, this._state); ${hasInitHooks && deindent` this.root._oncreate.push(() => { - ${templateProperties.onstate && `%onstate.call(this, { changed: @assignTrue({}, this._state), current: this._state });`} ${templateProperties.oncreate && `%oncreate.call(this);`} this.fire("update", { changed: @assignTrue({}, this._state), current: this._state }); }); diff --git a/test/runtime/samples/onstate-before-render/_config.js b/test/runtime/samples/onstate-before-render/_config.js new file mode 100644 index 0000000000..97c3af5083 --- /dev/null +++ b/test/runtime/samples/onstate-before-render/_config.js @@ -0,0 +1,16 @@ +import order from './order.js'; + +export default { + 'skip-ssr': true, + + test(assert, component, target) { + assert.deepEqual(order, [ + 'onstate', + 'render', + 'oncreate', + 'onupdate' + ]); + + order.length = 0; + } +}; diff --git a/test/runtime/samples/onstate-before-render/main.html b/test/runtime/samples/onstate-before-render/main.html new file mode 100644 index 0000000000..572275268c --- /dev/null +++ b/test/runtime/samples/onstate-before-render/main.html @@ -0,0 +1,26 @@ +{identity(42)} + + \ No newline at end of file diff --git a/test/runtime/samples/onstate-before-render/order.js b/test/runtime/samples/onstate-before-render/order.js new file mode 100644 index 0000000000..109fa8b38c --- /dev/null +++ b/test/runtime/samples/onstate-before-render/order.js @@ -0,0 +1 @@ +export default []; \ No newline at end of file