mirror of https://github.com/sveltejs/svelte
fix extraneous store subscription in SSR (#5929)
parent
0f3264e205
commit
6207596175
@ -0,0 +1,20 @@
|
||||
import { store } from './store.js';
|
||||
|
||||
export default {
|
||||
html: '<h1>0</h1>',
|
||||
before_test() {
|
||||
store.reset();
|
||||
},
|
||||
async test({ assert, target, component }) {
|
||||
store.set(42);
|
||||
|
||||
await Promise.resolve();
|
||||
|
||||
assert.htmlEqual(target.innerHTML, '<h1>42</h1>');
|
||||
|
||||
assert.equal(store.numberOfTimesSubscribeCalled(), 1);
|
||||
},
|
||||
test_ssr({ assert }) {
|
||||
assert.equal(store.numberOfTimesSubscribeCalled(), 1);
|
||||
}
|
||||
};
|
@ -0,0 +1,5 @@
|
||||
<script>
|
||||
import { store } from './store';
|
||||
</script>
|
||||
|
||||
<h1>{$store}</h1>
|
@ -0,0 +1,18 @@
|
||||
import { writable } from '../../../../store';
|
||||
const _store = writable(0);
|
||||
let count = 0;
|
||||
|
||||
export const store = {
|
||||
..._store,
|
||||
subscribe(fn) {
|
||||
count++;
|
||||
return _store.subscribe(fn);
|
||||
},
|
||||
reset() {
|
||||
count = 0;
|
||||
_store.set(0);
|
||||
},
|
||||
numberOfTimesSubscribeCalled() {
|
||||
return count;
|
||||
}
|
||||
};
|
Loading…
Reference in new issue