mirror of https://github.com/sveltejs/svelte
[fix] call `on_destroy` if unmounted called immediately before `on_mount` (#7860)
* call on_destroy if unmounted called immediately before on_mount * feat: review changespull/7819/head
parent
57541e6abc
commit
81d4dbad99
@ -0,0 +1,39 @@
|
|||||||
|
/**
|
||||||
|
* INTERNAL, DO NOT USE. Code may change at any time.
|
||||||
|
*/
|
||||||
|
export interface Fragment {
|
||||||
|
key: string | null;
|
||||||
|
first: null;
|
||||||
|
/* create */ c: () => void;
|
||||||
|
/* claim */ l: (nodes: any) => void;
|
||||||
|
/* hydrate */ h: () => void;
|
||||||
|
/* mount */ m: (target: HTMLElement, anchor: any) => void;
|
||||||
|
/* update */ p: (ctx: T$$['ctx'], dirty: T$$['dirty']) => void;
|
||||||
|
/* measure */ r: () => void;
|
||||||
|
/* fix */ f: () => void;
|
||||||
|
/* animate */ a: () => void;
|
||||||
|
/* intro */ i: (local: any) => void;
|
||||||
|
/* outro */ o: (local: any) => void;
|
||||||
|
/* destroy */ d: (detaching: 0 | 1) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type FragmentFactory = (ctx: any) => Fragment;
|
||||||
|
|
||||||
|
export interface T$$ {
|
||||||
|
dirty: number[];
|
||||||
|
ctx: any[];
|
||||||
|
bound: any;
|
||||||
|
update: () => void;
|
||||||
|
callbacks: any;
|
||||||
|
after_update: any[];
|
||||||
|
props: Record<string, 0 | string>;
|
||||||
|
fragment: null | false | Fragment;
|
||||||
|
not_equal: any;
|
||||||
|
before_update: any[];
|
||||||
|
context: Map<any, any>;
|
||||||
|
on_mount: any[];
|
||||||
|
on_destroy: any[];
|
||||||
|
skip_bound: boolean;
|
||||||
|
on_disconnect: any[];
|
||||||
|
root:Element | ShadowRoot
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
<script>
|
||||||
|
import { onMount } from 'svelte';
|
||||||
|
export let logs;
|
||||||
|
export let state;
|
||||||
|
onMount(() => {
|
||||||
|
logs.push(`mount ${state}`);
|
||||||
|
return () => {
|
||||||
|
logs.push(`unmount ${state}`);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{state}
|
@ -0,0 +1,9 @@
|
|||||||
|
export default {
|
||||||
|
html: 'Loading...',
|
||||||
|
async test({ assert, component, target }) {
|
||||||
|
await component.test();
|
||||||
|
|
||||||
|
assert.htmlEqual(target.innerHTML, '1');
|
||||||
|
assert.deepEqual(component.logs, ['mount 0', 'unmount 0', 'mount 1']);
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,36 @@
|
|||||||
|
<script>
|
||||||
|
import { tick } from 'svelte';
|
||||||
|
import Component from './Component.svelte';
|
||||||
|
|
||||||
|
let promise;
|
||||||
|
let resolve;
|
||||||
|
let value = 0;
|
||||||
|
export let logs = [];
|
||||||
|
|
||||||
|
async function new_promise() {
|
||||||
|
promise = new Promise(r => {
|
||||||
|
resolve = r;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function resolve_promise() {
|
||||||
|
await Promise.resolve();
|
||||||
|
resolve(value++);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function test() {
|
||||||
|
resolve_promise();
|
||||||
|
await Promise.resolve();
|
||||||
|
new_promise();
|
||||||
|
resolve_promise();
|
||||||
|
return tick();
|
||||||
|
}
|
||||||
|
|
||||||
|
new_promise();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
{#await promise}
|
||||||
|
Loading...
|
||||||
|
{:then state}
|
||||||
|
<Component {state} {logs} />
|
||||||
|
{/await}
|
Loading…
Reference in new issue