mirror of https://github.com/sveltejs/svelte
fix: compute store subscription blockers before function tracing, defer server store teardown past async work
parent
17db18f708
commit
ae4317de9c
@ -0,0 +1,18 @@
|
||||
import { test } from '../../test';
|
||||
import { counts, reset } from './store.js';
|
||||
|
||||
// A blocked store subscription is created after the synchronous part of the
|
||||
// render has finished, so the teardown must wait for the async work.
|
||||
export default test({
|
||||
mode: ['async-server'],
|
||||
|
||||
before_test() {
|
||||
reset();
|
||||
},
|
||||
|
||||
ssrHtml: '<p>hello</p>',
|
||||
|
||||
test_ssr({ assert }) {
|
||||
assert.deepEqual(counts, { subscribes: 1, unsubscribes: 1 });
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,11 @@
|
||||
<script>
|
||||
import { store } from './store.js';
|
||||
|
||||
async function get_store() {
|
||||
return store;
|
||||
}
|
||||
|
||||
const s = await get_store();
|
||||
</script>
|
||||
|
||||
<p>{$s}</p>
|
||||
@ -0,0 +1,23 @@
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
export const counts = { subscribes: 0, unsubscribes: 0 };
|
||||
|
||||
const inner = writable('hello');
|
||||
|
||||
export const store = {
|
||||
/** @param {(value: string) => void} fn */
|
||||
subscribe(fn) {
|
||||
counts.subscribes += 1;
|
||||
const unsubscribe = inner.subscribe(fn);
|
||||
|
||||
return () => {
|
||||
counts.unsubscribes += 1;
|
||||
unsubscribe();
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
export function reset() {
|
||||
counts.subscribes = 0;
|
||||
counts.unsubscribes = 0;
|
||||
}
|
||||
Loading…
Reference in new issue