Skip to content

Commit

Permalink
[Svelte] Upgrade to Svelte 5. Drop Svelte 4 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesst20 committed Jan 6, 2025
1 parent 0766df1 commit bb1042b
Show file tree
Hide file tree
Showing 34 changed files with 371 additions and 260 deletions.
152 changes: 123 additions & 29 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"react": "^16.9.0 || ^17.0.0 || ^18.0.0 || ^19.0.0"
},
"dependencies": {
"@jamesst20/inertia-core": "2.0.0",
"@jamesst20/inertia-core": "file:../core",
"lodash.isequal": "^4.5.0"
}
}
8 changes: 4 additions & 4 deletions packages/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,23 @@
"!dist/**/*.spec.*"
],
"peerDependencies": {
"svelte": "^4.0.0 || ^5.0.0 || ^5.0.0-next.244"
"svelte": "^5.0.0"
},
"dependencies": {
"@jamesst20/inertia-core": "2.0.0",
"@jamesst20/inertia-core": "file:../core",
"html-escape": "^2.0.0",
"lodash": "^4.5.0"
},
"devDependencies": {
"@sveltejs/adapter-auto": "^3.2.0",
"@sveltejs/kit": "^2.5.26",
"@sveltejs/package": "^2.3.4",
"@sveltejs/vite-plugin-svelte": "^3.1.2",
"@sveltejs/vite-plugin-svelte": "^4.0.4",
"@types/html-escape": "^2.0.2",
"@types/lodash": "^4.17.7",
"axios": "^1.7.6",
"publint": "^0.2.10",
"svelte": "^4.2.16",
"svelte": "^5.16.2",
"svelte-check": "^4.0.0",
"tslib": "^2.7.0",
"typescript": "^5.5.4",
Expand Down
10 changes: 4 additions & 6 deletions packages/svelte/src/components/App.svelte
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<script context="module" lang="ts">
<script module lang="ts">
import type { ComponentResolver, ResolvedComponent } from '../types'
import { type Page } from '@jamesst20/inertia-core'
Expand All @@ -13,16 +13,14 @@
import type { LayoutType, LayoutResolver } from '../types'
import { router, type PageProps } from '@jamesst20/inertia-core'
import Render, { h, type RenderProps } from './Render.svelte'
import { setPage } from '../page'
import { setPage } from '../page.svelte'
export let initialComponent: InertiaAppProps['initialComponent']
export let initialPage: InertiaAppProps['initialPage']
export let resolveComponent: InertiaAppProps['resolveComponent']
let {initialComponent, initialPage, resolveComponent}: InertiaAppProps = $props()
let component = initialComponent
let key: number | null = null
let page = initialPage
let renderProps = resolveRenderProps(component, page, key)
let renderProps = $state(resolveRenderProps(component, page, key))
setPage(page)
Expand Down
33 changes: 19 additions & 14 deletions packages/svelte/src/components/Deferred.svelte
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}
Loading

0 comments on commit bb1042b

Please sign in to comment.