- loader action used new Component() plus $destroy, both removed in Svelte 5 (component_api_invalid_new crashed every refresh click before the reload ran); rewritten on mount/unmount with a real action destroy for the leaked subscription - homecoming refresh moves off the legacy $: block, which never tracked the runes-backed router.location, onto the sanctioned onRouteLoaded callback with identical guard semantics; unused router import dropped so the check stays warning-free
30 lines
835 B
TypeScript
30 lines
835 B
TypeScript
import { mount, unmount } from 'svelte';
|
|
import Spinner from '../helperComponents/Spinner.svelte';
|
|
|
|
export default (node: any, loading: any) => {
|
|
let app: any;
|
|
const unsubscribe = loading.subscribe((isLoading: any) => {
|
|
if (isLoading && !app) {
|
|
app = mount(Spinner, {
|
|
target: node,
|
|
intro: true
|
|
});
|
|
} else if (!isLoading && app) {
|
|
const current = app;
|
|
app = undefined;
|
|
// Teardown must never break the caller.
|
|
void unmount(current).catch(() => {});
|
|
}
|
|
});
|
|
return {
|
|
destroy() {
|
|
unsubscribe();
|
|
if (app) {
|
|
const current = app;
|
|
app = undefined;
|
|
void unmount(current).catch(() => {});
|
|
}
|
|
}
|
|
};
|
|
}
|