Skip to content

Commit

Permalink
Add inertiajs#1864 to the Svelte 5 adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesst20 committed May 12, 2024
1 parent 6cddfd3 commit f7ce3a3
Show file tree
Hide file tree
Showing 5 changed files with 748 additions and 7 deletions.
2 changes: 1 addition & 1 deletion packages/svelte5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "^2.0.0",
"@sveltejs/package": "^2.0.0",
"@sveltejs/vite-plugin-svelte": "^3.0.0",
"@sveltejs/vite-plugin-svelte": "^4.0.0-next.0",
"publint": "^0.1.9",
"svelte": "^5.0.0-next.1",
"svelte-check": "^3.6.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/svelte5/src/lib/createInertiaApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ export default async function createInertiaApp({
const isServer = typeof window === 'undefined'
const el = isServer ? null : document.getElementById(id)
const initialPage: Page = page || JSON.parse(el?.dataset?.page || '{}')
const resolveComponent = (name: string) => Promise.resolve(resolve(name))
const resolveComponent = (name: string, page: Page) => Promise.resolve(resolve(name, page))

await resolveComponent(initialPage.component).then((initialComponent) => {
await resolveComponent(initialPage.component, initialPage).then((initialComponent) => {
store.component = initialComponent as InertiaComponentType
store.page = initialPage
})
Expand Down
4 changes: 2 additions & 2 deletions packages/svelte5/src/lib/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { PageProps } from '@inertiajs/core'
import type { Page, PageProps } from '@inertiajs/core'
import type { ComponentType } from 'svelte'

export type ComponentResolver = (name: string) => ComponentType | Promise<ComponentType>
export type ComponentResolver = (name: string, page: Page) => ComponentType | Promise<ComponentType>

export interface InertiaComponentType extends ComponentType {
default: InertiaComponentType
Expand Down
4 changes: 2 additions & 2 deletions playgrounds/svelte5/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
"build": "vite build && vite build --ssr"
},
"devDependencies": {
"@inertiajs/svelte5": "file:../../packages/svelte5",
"@sveltejs/vite-plugin-svelte": "^3.1.0",
"@inertiajs/svelte5": "workspace:*",
"@sveltejs/vite-plugin-svelte": "^4.0.0-next.0",
"@tsconfig/svelte": "^5.0.4",
"autoprefixer": "^10.4.19",
"axios": "^1.6.8",
Expand Down
Loading

0 comments on commit f7ce3a3

Please sign in to comment.