forked from inertiajs/inertia
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Svelte] Upgrade to Svelte 5. Drop Svelte 4 support.
- Loading branch information
Showing
34 changed files
with
371 additions
and
260 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,35 @@ | ||
<script module lang="ts"> | ||
import { Snippet } from 'svelte' | ||
type DeferedProps = { | ||
data: string | string[] | ||
children: Snippet | ||
fallback: Snippet | ||
} | ||
</script> | ||
<script lang="ts"> | ||
import { page } from '../index' | ||
import { onDestroy } from 'svelte' | ||
export let data: string | string[] | ||
let { data, children, fallback }: DeferedProps = $props() | ||
let currentPage = $derived(page.current) | ||
let keys = $derived(Array.isArray(data) ? data : [data]) | ||
let loaded = $state(false) | ||
const keys = Array.isArray(data) ? data : [data] | ||
let loaded = false | ||
const unsubscribe = page.subscribe(({ props }) => { | ||
$effect(() => { | ||
// Ensures the slot isn't loaded before the deferred props are available | ||
window.queueMicrotask(() => { | ||
loaded = keys.every((key) => typeof props[key] !== 'undefined') | ||
loaded = keys.every((key) => typeof currentPage?.props?.[key] !== 'undefined') | ||
}) | ||
}) | ||
onDestroy(() => { | ||
unsubscribe() | ||
}) | ||
if (!$$slots.fallback) { | ||
if (!fallback) { | ||
throw new Error('`<Deferred>` requires a `<svelte:fragment slot="fallback">` slot') | ||
} | ||
</script> | ||
|
||
{#if loaded} | ||
<slot /> | ||
{@render children?.()} | ||
{:else} | ||
<slot name="fallback" /> | ||
{@render fallback?.()} | ||
{/if} |
Oops, something went wrong.