Skip to content

Commit 0a4e795

Browse files
authored
Merge pull request #921 from sveltejs/gh-917
check component exists after _bind before continuing
2 parents 75b1b05 + fb675fd commit 0a4e795

File tree

25 files changed

+174
-66
lines changed

25 files changed

+174
-66
lines changed

src/shared/index.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,12 @@ export function _set(newState) {
156156
this._state = assign({}, oldState, newState);
157157
this._recompute(changed, this._state);
158158
if (this._bind) this._bind(changed, this._state);
159-
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
160-
this._fragment.p(changed, this._state);
161-
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
159+
160+
if (this._fragment) {
161+
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
162+
this._fragment.p(changed, this._state);
163+
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
164+
}
162165
}
163166

164167
export function _setDev(newState) {

test/js/samples/collapses-text-around-comments/expected-bundle.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,12 @@ function _set(newState) {
157157
this._state = assign({}, oldState, newState);
158158
this._recompute(changed, this._state);
159159
if (this._bind) this._bind(changed, this._state);
160-
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
161-
this._fragment.p(changed, this._state);
162-
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
160+
161+
if (this._fragment) {
162+
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
163+
this._fragment.p(changed, this._state);
164+
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
165+
}
163166
}
164167

165168
function callAll(fns) {

test/js/samples/component-static/expected-bundle.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,12 @@ function _set(newState) {
133133
this._state = assign({}, oldState, newState);
134134
this._recompute(changed, this._state);
135135
if (this._bind) this._bind(changed, this._state);
136-
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
137-
this._fragment.p(changed, this._state);
138-
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
136+
137+
if (this._fragment) {
138+
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
139+
this._fragment.p(changed, this._state);
140+
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
141+
}
139142
}
140143

141144
function callAll(fns) {

test/js/samples/computed-collapsed-if/expected-bundle.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,12 @@ function _set(newState) {
133133
this._state = assign({}, oldState, newState);
134134
this._recompute(changed, this._state);
135135
if (this._bind) this._bind(changed, this._state);
136-
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
137-
this._fragment.p(changed, this._state);
138-
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
136+
137+
if (this._fragment) {
138+
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
139+
this._fragment.p(changed, this._state);
140+
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
141+
}
139142
}
140143

141144
function callAll(fns) {

test/js/samples/css-media-query/expected-bundle.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,12 @@ function _set(newState) {
153153
this._state = assign({}, oldState, newState);
154154
this._recompute(changed, this._state);
155155
if (this._bind) this._bind(changed, this._state);
156-
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
157-
this._fragment.p(changed, this._state);
158-
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
156+
157+
if (this._fragment) {
158+
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
159+
this._fragment.p(changed, this._state);
160+
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
161+
}
159162
}
160163

161164
function callAll(fns) {

test/js/samples/css-shadow-dom-keyframes/expected-bundle.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,12 @@ function _set(newState) {
145145
this._state = assign({}, oldState, newState);
146146
this._recompute(changed, this._state);
147147
if (this._bind) this._bind(changed, this._state);
148-
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
149-
this._fragment.p(changed, this._state);
150-
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
148+
149+
if (this._fragment) {
150+
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
151+
this._fragment.p(changed, this._state);
152+
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
153+
}
151154
}
152155

153156
function callAll(fns) {

test/js/samples/each-block-changed-check/expected-bundle.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,12 @@ function _set(newState) {
165165
this._state = assign({}, oldState, newState);
166166
this._recompute(changed, this._state);
167167
if (this._bind) this._bind(changed, this._state);
168-
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
169-
this._fragment.p(changed, this._state);
170-
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
168+
169+
if (this._fragment) {
170+
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
171+
this._fragment.p(changed, this._state);
172+
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
173+
}
171174
}
172175

173176
function callAll(fns) {

test/js/samples/event-handlers-custom/expected-bundle.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,12 @@ function _set(newState) {
145145
this._state = assign({}, oldState, newState);
146146
this._recompute(changed, this._state);
147147
if (this._bind) this._bind(changed, this._state);
148-
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
149-
this._fragment.p(changed, this._state);
150-
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
148+
149+
if (this._fragment) {
150+
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
151+
this._fragment.p(changed, this._state);
152+
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
153+
}
151154
}
152155

153156
function callAll(fns) {

test/js/samples/if-block-no-update/expected-bundle.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,12 @@ function _set(newState) {
149149
this._state = assign({}, oldState, newState);
150150
this._recompute(changed, this._state);
151151
if (this._bind) this._bind(changed, this._state);
152-
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
153-
this._fragment.p(changed, this._state);
154-
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
152+
153+
if (this._fragment) {
154+
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
155+
this._fragment.p(changed, this._state);
156+
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
157+
}
155158
}
156159

157160
function callAll(fns) {

test/js/samples/if-block-simple/expected-bundle.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,12 @@ function _set(newState) {
149149
this._state = assign({}, oldState, newState);
150150
this._recompute(changed, this._state);
151151
if (this._bind) this._bind(changed, this._state);
152-
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
153-
this._fragment.p(changed, this._state);
154-
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
152+
153+
if (this._fragment) {
154+
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
155+
this._fragment.p(changed, this._state);
156+
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
157+
}
155158
}
156159

157160
function callAll(fns) {

test/js/samples/inline-style-optimized-multiple/expected-bundle.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,12 @@ function _set(newState) {
149149
this._state = assign({}, oldState, newState);
150150
this._recompute(changed, this._state);
151151
if (this._bind) this._bind(changed, this._state);
152-
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
153-
this._fragment.p(changed, this._state);
154-
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
152+
153+
if (this._fragment) {
154+
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
155+
this._fragment.p(changed, this._state);
156+
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
157+
}
155158
}
156159

157160
function callAll(fns) {

test/js/samples/inline-style-optimized-url/expected-bundle.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,12 @@ function _set(newState) {
149149
this._state = assign({}, oldState, newState);
150150
this._recompute(changed, this._state);
151151
if (this._bind) this._bind(changed, this._state);
152-
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
153-
this._fragment.p(changed, this._state);
154-
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
152+
153+
if (this._fragment) {
154+
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
155+
this._fragment.p(changed, this._state);
156+
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
157+
}
155158
}
156159

157160
function callAll(fns) {

test/js/samples/inline-style-optimized/expected-bundle.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,12 @@ function _set(newState) {
149149
this._state = assign({}, oldState, newState);
150150
this._recompute(changed, this._state);
151151
if (this._bind) this._bind(changed, this._state);
152-
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
153-
this._fragment.p(changed, this._state);
154-
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
152+
153+
if (this._fragment) {
154+
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
155+
this._fragment.p(changed, this._state);
156+
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
157+
}
155158
}
156159

157160
function callAll(fns) {

test/js/samples/inline-style-unoptimized/expected-bundle.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,9 +149,12 @@ function _set(newState) {
149149
this._state = assign({}, oldState, newState);
150150
this._recompute(changed, this._state);
151151
if (this._bind) this._bind(changed, this._state);
152-
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
153-
this._fragment.p(changed, this._state);
154-
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
152+
153+
if (this._fragment) {
154+
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
155+
this._fragment.p(changed, this._state);
156+
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
157+
}
155158
}
156159

157160
function callAll(fns) {

test/js/samples/input-without-blowback-guard/expected-bundle.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,12 @@ function _set(newState) {
153153
this._state = assign({}, oldState, newState);
154154
this._recompute(changed, this._state);
155155
if (this._bind) this._bind(changed, this._state);
156-
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
157-
this._fragment.p(changed, this._state);
158-
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
156+
157+
if (this._fragment) {
158+
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
159+
this._fragment.p(changed, this._state);
160+
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
161+
}
159162
}
160163

161164
function callAll(fns) {

test/js/samples/legacy-input-type/expected-bundle.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,9 +151,12 @@ function _set(newState) {
151151
this._state = assign({}, oldState, newState);
152152
this._recompute(changed, this._state);
153153
if (this._bind) this._bind(changed, this._state);
154-
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
155-
this._fragment.p(changed, this._state);
156-
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
154+
155+
if (this._fragment) {
156+
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
157+
this._fragment.p(changed, this._state);
158+
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
159+
}
157160
}
158161

159162
function callAll(fns) {

test/js/samples/legacy-quote-class/expected-bundle.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,12 @@ function _set(newState) {
168168
this._state = assign({}, oldState, newState);
169169
this._recompute(changed, this._state);
170170
if (this._bind) this._bind(changed, this._state);
171-
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
172-
this._fragment.p(changed, this._state);
173-
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
171+
172+
if (this._fragment) {
173+
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
174+
this._fragment.p(changed, this._state);
175+
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
176+
}
174177
}
175178

176179
function callAll(fns) {

test/js/samples/media-bindings/expected-bundle.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,12 @@ function _set(newState) {
161161
this._state = assign({}, oldState, newState);
162162
this._recompute(changed, this._state);
163163
if (this._bind) this._bind(changed, this._state);
164-
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
165-
this._fragment.p(changed, this._state);
166-
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
164+
165+
if (this._fragment) {
166+
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
167+
this._fragment.p(changed, this._state);
168+
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
169+
}
167170
}
168171

169172
function callAll(fns) {

test/js/samples/non-imported-component/expected-bundle.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,12 @@ function _set(newState) {
147147
this._state = assign({}, oldState, newState);
148148
this._recompute(changed, this._state);
149149
if (this._bind) this._bind(changed, this._state);
150-
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
151-
this._fragment.p(changed, this._state);
152-
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
150+
151+
if (this._fragment) {
152+
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
153+
this._fragment.p(changed, this._state);
154+
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
155+
}
153156
}
154157

155158
function callAll(fns) {

test/js/samples/onrender-onteardown-rewritten/expected-bundle.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,12 @@ function _set(newState) {
133133
this._state = assign({}, oldState, newState);
134134
this._recompute(changed, this._state);
135135
if (this._bind) this._bind(changed, this._state);
136-
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
137-
this._fragment.p(changed, this._state);
138-
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
136+
137+
if (this._fragment) {
138+
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
139+
this._fragment.p(changed, this._state);
140+
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
141+
}
139142
}
140143

141144
function callAll(fns) {

test/js/samples/setup-method/expected-bundle.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,12 @@ function _set(newState) {
133133
this._state = assign({}, oldState, newState);
134134
this._recompute(changed, this._state);
135135
if (this._bind) this._bind(changed, this._state);
136-
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
137-
this._fragment.p(changed, this._state);
138-
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
136+
137+
if (this._fragment) {
138+
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
139+
this._fragment.p(changed, this._state);
140+
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
141+
}
139142
}
140143

141144
function callAll(fns) {

test/js/samples/use-elements-as-anchors/expected-bundle.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,12 @@ function _set(newState) {
157157
this._state = assign({}, oldState, newState);
158158
this._recompute(changed, this._state);
159159
if (this._bind) this._bind(changed, this._state);
160-
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
161-
this._fragment.p(changed, this._state);
162-
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
160+
161+
if (this._fragment) {
162+
dispatchObservers(this, this._observers.pre, changed, this._state, oldState);
163+
this._fragment.p(changed, this._state);
164+
dispatchObservers(this, this._observers.post, changed, this._state, oldState);
165+
}
163166
}
164167

165168
function callAll(fns) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<button on:click="set({show:false})">Hide</button>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export default {
2+
data: {
3+
show: true
4+
},
5+
6+
html: `
7+
<button>Hide</button>
8+
`,
9+
10+
test(assert, component, target, window) {
11+
const click = new window.MouseEvent('click');
12+
13+
target.querySelector('button').dispatchEvent(click);
14+
15+
assert.equal(component.get('show'), false);
16+
assert.htmlEqual(target.innerHTML, `
17+
<button>Show</button>
18+
`);
19+
20+
target.querySelector('button').dispatchEvent(click);
21+
22+
assert.equal(component.get('show'), true);
23+
assert.htmlEqual(target.innerHTML, `
24+
<button>Hide</button>
25+
`);
26+
}
27+
};
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{{#if show}}
2+
<Nested bind:show/>
3+
{{else}}
4+
<button on:click="set({show:true})">Show</button>
5+
{{/if}}
6+
7+
<script>
8+
import Nested from './Nested.html';
9+
export default {
10+
components: {
11+
Nested
12+
}
13+
};
14+
</script>

0 commit comments

Comments
 (0)