diff --git a/src/generators/dom/index.ts b/src/generators/dom/index.ts
index 55c6599cd7..09b54e896f 100644
--- a/src/generators/dom/index.ts
+++ b/src/generators/dom/index.ts
@@ -123,7 +123,8 @@ export default function dom(
${computations.length &&
`@recompute( this._state, newState, oldState, false )`}
@dispatchObservers( this, this._observers.pre, newState, oldState );
- ${block.hasUpdateMethod && `this._fragment.update( newState, this._state );`}
+
+ ${block.hasUpdateMethod && `withoutDomUpdate || this._fragment.update( newState, this._state );`}
@dispatchObservers( this, this._observers.post, newState, oldState );
${generator.hasComponents && `@callAll(this._oncreate);`}
${generator.hasComplexBindings && `@callAll(this._bindings);`}
@@ -213,6 +214,7 @@ export default function dom(
this._fragment = @create_main_fragment( this._state, this );
+ this._protectDomUpdate = false;
if ( options.target ) {
${generator.hydratable
? deindent`
@@ -225,10 +227,13 @@ export default function dom(
this._fragment.create();
`}
this._fragment.${block.hasIntroMethod ? 'intro' : 'mount'}( options.target, null );
+ } else {
+ this._protectDomUpdate = true;
}
${generator.hasComponents && `@callAll(this._oncreate);`}
${generator.hasComplexBindings && `@callAll(this._bindings);`}
+ this._protectDomUpdate = false;
${templateProperties.oncreate && deindent`
if ( options._root ) {
@@ -242,7 +247,7 @@ export default function dom(
@assign( ${prototypeBase}, ${proto});
- ${name}.prototype._set = function _set ( newState ) {
+ ${name}.prototype._set = function _set ( newState, withoutDomUpdate ) {
${_set}
};
diff --git a/src/generators/dom/visitors/shared/binding/getSetter.ts b/src/generators/dom/visitors/shared/binding/getSetter.ts
index 784e1d7302..cfbe59193e 100644
--- a/src/generators/dom/visitors/shared/binding/getSetter.ts
+++ b/src/generators/dom/visitors/shared/binding/getSetter.ts
@@ -29,10 +29,10 @@ export default function getSetter({
${computed
? `#component._set({ ${dependencies
.map((prop: string) => `${prop}: state.${prop}`)
- .join(', ')} });`
+ .join(', ')} }, #component._protectDomUpdate);`
: `#component._set({ ${dependencies
.map((prop: string) => `${prop}: #component.get( '${prop}' )`)
- .join(', ')} });`}
+ .join(', ')} }, #component._protectDomUpdate);`}
`;
}
@@ -42,11 +42,11 @@ export default function getSetter({
${snippet} = ${value};
#component._set({ ${dependencies
.map((prop: string) => `${prop}: state.${prop}`)
- .join(', ')} });
+ .join(', ')} }, #component._protectDomUpdate);
`;
}
- return `#component._set({ ${name}: ${value} });`;
+ return `#component._set({ ${name}: ${value} }, #component._protectDomUpdate);`;
}
function isComputed(node: Node) {
diff --git a/test/js/samples/collapses-text-around-comments/expected-bundle.js b/test/js/samples/collapses-text-around-comments/expected-bundle.js
index ea478745cd..b79a74aff5 100644
--- a/test/js/samples/collapses-text-around-comments/expected-bundle.js
+++ b/test/js/samples/collapses-text-around-comments/expected-bundle.js
@@ -197,19 +197,24 @@ function SvelteComponent ( options ) {
this._fragment = create_main_fragment( this._state, this );
+ this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
+ } else {
+ this._protectDomUpdate = true;
}
+ this._protectDomUpdate = false;
}
assign( SvelteComponent.prototype, proto );
-SvelteComponent.prototype._set = function _set ( newState ) {
+SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
- this._fragment.update( newState, this._state );
+
+ withoutDomUpdate || this._fragment.update( newState, this._state );
dispatchObservers( this, this._observers.post, newState, oldState );
};
diff --git a/test/js/samples/collapses-text-around-comments/expected.js b/test/js/samples/collapses-text-around-comments/expected.js
index 33931b121c..8282d6457e 100644
--- a/test/js/samples/collapses-text-around-comments/expected.js
+++ b/test/js/samples/collapses-text-around-comments/expected.js
@@ -67,19 +67,24 @@ function SvelteComponent ( options ) {
this._fragment = create_main_fragment( this._state, this );
+ this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
+ } else {
+ this._protectDomUpdate = true;
}
+ this._protectDomUpdate = false;
}
assign( SvelteComponent.prototype, proto );
-SvelteComponent.prototype._set = function _set ( newState ) {
+SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
- this._fragment.update( newState, this._state );
+
+ withoutDomUpdate || this._fragment.update( newState, this._state );
dispatchObservers( this, this._observers.post, newState, oldState );
};
diff --git a/test/js/samples/computed-collapsed-if/expected-bundle.js b/test/js/samples/computed-collapsed-if/expected-bundle.js
index 5cd719b372..2b72f42e5e 100644
--- a/test/js/samples/computed-collapsed-if/expected-bundle.js
+++ b/test/js/samples/computed-collapsed-if/expected-bundle.js
@@ -154,15 +154,19 @@ function SvelteComponent ( options ) {
this._fragment = create_main_fragment( this._state, this );
+ this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
+ } else {
+ this._protectDomUpdate = true;
}
+ this._protectDomUpdate = false;
}
assign( SvelteComponent.prototype, proto );
-SvelteComponent.prototype._set = function _set ( newState ) {
+SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
recompute( this._state, newState, oldState, false );
diff --git a/test/js/samples/computed-collapsed-if/expected.js b/test/js/samples/computed-collapsed-if/expected.js
index e16d023bfb..44e80a03d1 100644
--- a/test/js/samples/computed-collapsed-if/expected.js
+++ b/test/js/samples/computed-collapsed-if/expected.js
@@ -48,15 +48,19 @@ function SvelteComponent ( options ) {
this._fragment = create_main_fragment( this._state, this );
+ this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
+ } else {
+ this._protectDomUpdate = true;
}
+ this._protectDomUpdate = false;
}
assign( SvelteComponent.prototype, proto );
-SvelteComponent.prototype._set = function _set ( newState ) {
+SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
recompute( this._state, newState, oldState, false )
diff --git a/test/js/samples/each-block-changed-check/expected-bundle.js b/test/js/samples/each-block-changed-check/expected-bundle.js
index d98ac1db37..c83dd90475 100644
--- a/test/js/samples/each-block-changed-check/expected-bundle.js
+++ b/test/js/samples/each-block-changed-check/expected-bundle.js
@@ -300,19 +300,24 @@ function SvelteComponent ( options ) {
this._fragment = create_main_fragment( this._state, this );
+ this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
+ } else {
+ this._protectDomUpdate = true;
}
+ this._protectDomUpdate = false;
}
assign( SvelteComponent.prototype, proto );
-SvelteComponent.prototype._set = function _set ( newState ) {
+SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
- this._fragment.update( newState, this._state );
+
+ withoutDomUpdate || this._fragment.update( newState, this._state );
dispatchObservers( this, this._observers.post, newState, oldState );
};
diff --git a/test/js/samples/each-block-changed-check/expected.js b/test/js/samples/each-block-changed-check/expected.js
index 4fa7680a77..6f585d4f32 100644
--- a/test/js/samples/each-block-changed-check/expected.js
+++ b/test/js/samples/each-block-changed-check/expected.js
@@ -161,19 +161,24 @@ function SvelteComponent ( options ) {
this._fragment = create_main_fragment( this._state, this );
+ this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
+ } else {
+ this._protectDomUpdate = true;
}
+ this._protectDomUpdate = false;
}
assign( SvelteComponent.prototype, proto );
-SvelteComponent.prototype._set = function _set ( newState ) {
+SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
- this._fragment.update( newState, this._state );
+
+ withoutDomUpdate || this._fragment.update( newState, this._state );
dispatchObservers( this, this._observers.post, newState, oldState );
};
diff --git a/test/js/samples/event-handlers-custom/expected-bundle.js b/test/js/samples/event-handlers-custom/expected-bundle.js
index 3912710a15..abbc8874c0 100644
--- a/test/js/samples/event-handlers-custom/expected-bundle.js
+++ b/test/js/samples/event-handlers-custom/expected-bundle.js
@@ -189,15 +189,19 @@ function SvelteComponent ( options ) {
this._fragment = create_main_fragment( this._state, this );
+ this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
+ } else {
+ this._protectDomUpdate = true;
}
+ this._protectDomUpdate = false;
}
assign( SvelteComponent.prototype, template.methods, proto );
-SvelteComponent.prototype._set = function _set ( newState ) {
+SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
diff --git a/test/js/samples/event-handlers-custom/expected.js b/test/js/samples/event-handlers-custom/expected.js
index 882bc08e85..b06c74fc27 100644
--- a/test/js/samples/event-handlers-custom/expected.js
+++ b/test/js/samples/event-handlers-custom/expected.js
@@ -65,15 +65,19 @@ function SvelteComponent ( options ) {
this._fragment = create_main_fragment( this._state, this );
+ this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
+ } else {
+ this._protectDomUpdate = true;
}
+ this._protectDomUpdate = false;
}
assign( SvelteComponent.prototype, template.methods, proto );
-SvelteComponent.prototype._set = function _set ( newState ) {
+SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
diff --git a/test/js/samples/if-block-no-update/expected-bundle.js b/test/js/samples/if-block-no-update/expected-bundle.js
index f00e3816a9..e9764e3299 100644
--- a/test/js/samples/if-block-no-update/expected-bundle.js
+++ b/test/js/samples/if-block-no-update/expected-bundle.js
@@ -235,19 +235,24 @@ function SvelteComponent ( options ) {
this._fragment = create_main_fragment( this._state, this );
+ this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
+ } else {
+ this._protectDomUpdate = true;
}
+ this._protectDomUpdate = false;
}
assign( SvelteComponent.prototype, proto );
-SvelteComponent.prototype._set = function _set ( newState ) {
+SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
- this._fragment.update( newState, this._state );
+
+ withoutDomUpdate || this._fragment.update( newState, this._state );
dispatchObservers( this, this._observers.post, newState, oldState );
};
diff --git a/test/js/samples/if-block-no-update/expected.js b/test/js/samples/if-block-no-update/expected.js
index fdedd6e4a7..78f6b59ae4 100644
--- a/test/js/samples/if-block-no-update/expected.js
+++ b/test/js/samples/if-block-no-update/expected.js
@@ -105,19 +105,24 @@ function SvelteComponent ( options ) {
this._fragment = create_main_fragment( this._state, this );
+ this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
+ } else {
+ this._protectDomUpdate = true;
}
+ this._protectDomUpdate = false;
}
assign( SvelteComponent.prototype, proto );
-SvelteComponent.prototype._set = function _set ( newState ) {
+SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
- this._fragment.update( newState, this._state );
+
+ withoutDomUpdate || this._fragment.update( newState, this._state );
dispatchObservers( this, this._observers.post, newState, oldState );
};
diff --git a/test/js/samples/if-block-simple/expected-bundle.js b/test/js/samples/if-block-simple/expected-bundle.js
index 2e2e7e7c09..f724e3939a 100644
--- a/test/js/samples/if-block-simple/expected-bundle.js
+++ b/test/js/samples/if-block-simple/expected-bundle.js
@@ -211,19 +211,24 @@ function SvelteComponent ( options ) {
this._fragment = create_main_fragment( this._state, this );
+ this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
+ } else {
+ this._protectDomUpdate = true;
}
+ this._protectDomUpdate = false;
}
assign( SvelteComponent.prototype, proto );
-SvelteComponent.prototype._set = function _set ( newState ) {
+SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
- this._fragment.update( newState, this._state );
+
+ withoutDomUpdate || this._fragment.update( newState, this._state );
dispatchObservers( this, this._observers.post, newState, oldState );
};
diff --git a/test/js/samples/if-block-simple/expected.js b/test/js/samples/if-block-simple/expected.js
index 548938d59c..b8858ce52c 100644
--- a/test/js/samples/if-block-simple/expected.js
+++ b/test/js/samples/if-block-simple/expected.js
@@ -81,19 +81,24 @@ function SvelteComponent ( options ) {
this._fragment = create_main_fragment( this._state, this );
+ this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
+ } else {
+ this._protectDomUpdate = true;
}
+ this._protectDomUpdate = false;
}
assign( SvelteComponent.prototype, proto );
-SvelteComponent.prototype._set = function _set ( newState ) {
+SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
- this._fragment.update( newState, this._state );
+
+ withoutDomUpdate || this._fragment.update( newState, this._state );
dispatchObservers( this, this._observers.post, newState, oldState );
};
diff --git a/test/js/samples/non-imported-component/expected-bundle.js b/test/js/samples/non-imported-component/expected-bundle.js
index 878bdf223e..033608e3f2 100644
--- a/test/js/samples/non-imported-component/expected-bundle.js
+++ b/test/js/samples/non-imported-component/expected-bundle.js
@@ -182,17 +182,21 @@ function SvelteComponent ( options ) {
this._fragment = create_main_fragment( this._state, this );
+ this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
+ } else {
+ this._protectDomUpdate = true;
}
callAll(this._oncreate);
+ this._protectDomUpdate = false;
}
assign( SvelteComponent.prototype, proto );
-SvelteComponent.prototype._set = function _set ( newState ) {
+SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
diff --git a/test/js/samples/non-imported-component/expected.js b/test/js/samples/non-imported-component/expected.js
index c154930593..d38ca081ac 100644
--- a/test/js/samples/non-imported-component/expected.js
+++ b/test/js/samples/non-imported-component/expected.js
@@ -66,17 +66,21 @@ function SvelteComponent ( options ) {
this._fragment = create_main_fragment( this._state, this );
+ this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
+ } else {
+ this._protectDomUpdate = true;
}
callAll(this._oncreate);
+ this._protectDomUpdate = false;
}
assign( SvelteComponent.prototype, proto );
-SvelteComponent.prototype._set = function _set ( newState ) {
+SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
diff --git a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js
index e74522a945..c41a00a45c 100644
--- a/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js
+++ b/test/js/samples/onrender-onteardown-rewritten/expected-bundle.js
@@ -145,10 +145,14 @@ function SvelteComponent ( options ) {
this._fragment = create_main_fragment( this._state, this );
+ this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
+ } else {
+ this._protectDomUpdate = true;
}
+ this._protectDomUpdate = false;
if ( options._root ) {
options._root._oncreate.push( template.oncreate.bind( this ) );
@@ -159,7 +163,7 @@ function SvelteComponent ( options ) {
assign( SvelteComponent.prototype, proto );
-SvelteComponent.prototype._set = function _set ( newState ) {
+SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
diff --git a/test/js/samples/onrender-onteardown-rewritten/expected.js b/test/js/samples/onrender-onteardown-rewritten/expected.js
index 96aa37d766..b8935f5f0b 100644
--- a/test/js/samples/onrender-onteardown-rewritten/expected.js
+++ b/test/js/samples/onrender-onteardown-rewritten/expected.js
@@ -39,10 +39,14 @@ function SvelteComponent ( options ) {
this._fragment = create_main_fragment( this._state, this );
+ this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
+ } else {
+ this._protectDomUpdate = true;
}
+ this._protectDomUpdate = false;
if ( options._root ) {
options._root._oncreate.push( template.oncreate.bind( this ) );
@@ -53,7 +57,7 @@ function SvelteComponent ( options ) {
assign( SvelteComponent.prototype, proto );
-SvelteComponent.prototype._set = function _set ( newState ) {
+SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
diff --git a/test/js/samples/use-elements-as-anchors/expected-bundle.js b/test/js/samples/use-elements-as-anchors/expected-bundle.js
index 62a6ac86e0..6228aa8c2c 100644
--- a/test/js/samples/use-elements-as-anchors/expected-bundle.js
+++ b/test/js/samples/use-elements-as-anchors/expected-bundle.js
@@ -395,19 +395,24 @@ function SvelteComponent ( options ) {
this._fragment = create_main_fragment( this._state, this );
+ this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
+ } else {
+ this._protectDomUpdate = true;
}
+ this._protectDomUpdate = false;
}
assign( SvelteComponent.prototype, proto );
-SvelteComponent.prototype._set = function _set ( newState ) {
+SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
- this._fragment.update( newState, this._state );
+
+ withoutDomUpdate || this._fragment.update( newState, this._state );
dispatchObservers( this, this._observers.post, newState, oldState );
};
diff --git a/test/js/samples/use-elements-as-anchors/expected.js b/test/js/samples/use-elements-as-anchors/expected.js
index 524372861e..4195fa527c 100644
--- a/test/js/samples/use-elements-as-anchors/expected.js
+++ b/test/js/samples/use-elements-as-anchors/expected.js
@@ -265,19 +265,24 @@ function SvelteComponent ( options ) {
this._fragment = create_main_fragment( this._state, this );
+ this._protectDomUpdate = false;
if ( options.target ) {
this._fragment.create();
this._fragment.mount( options.target, null );
+ } else {
+ this._protectDomUpdate = true;
}
+ this._protectDomUpdate = false;
}
assign( SvelteComponent.prototype, proto );
-SvelteComponent.prototype._set = function _set ( newState ) {
+SvelteComponent.prototype._set = function _set ( newState, withoutDomUpdate ) {
var oldState = this._state;
this._state = assign( {}, oldState, newState );
dispatchObservers( this, this._observers.pre, newState, oldState );
- this._fragment.update( newState, this._state );
+
+ withoutDomUpdate || this._fragment.update( newState, this._state );
dispatchObservers( this, this._observers.post, newState, oldState );
};
diff --git a/test/runtime/samples/bindings-before-oncreate-change-dom/One.html b/test/runtime/samples/bindings-before-oncreate-change-dom/One.html
new file mode 100644
index 0000000000..f0f5b8a051
--- /dev/null
+++ b/test/runtime/samples/bindings-before-oncreate-change-dom/One.html
@@ -0,0 +1,20 @@
+