Skip to content

Commit

Permalink
QA: Move the if server up
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesst20 committed Jul 31, 2024
1 parent ede5f25 commit 12b689a
Showing 1 changed file with 29 additions and 31 deletions.
60 changes: 29 additions & 31 deletions packages/svelte/src/lib/createInertiaApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,37 +49,6 @@ export default async function createInertiaApp({
})
})

if (!isServer) {
if (!el) {
throw new Error(`Element with ID "${id}" not found.`)
}

router.init({
initialPage,
resolveComponent,
swapComponent: async ({ component, page, preserveState }) => {
store.update((current) => ({
component: component as ResolvedComponent,
page,
key: preserveState ? current.key : Date.now(),
}))
},
})

if (progress) {
setupProgress(progress)
}

setup({
el,
App,
props: {
initialPage,
resolveComponent,
},
})
}

if (isServer) {
const { html, head, css } = (SSR as SSRComponent).render({ id, initialPage })

Expand All @@ -88,4 +57,33 @@ export default async function createInertiaApp({
head: [head, `<style data-vite-css>${css.code}</style>`],
}
}

if (!el) {
throw new Error(`Element with ID "${id}" not found.`)
}

router.init({
initialPage,
resolveComponent,
swapComponent: async ({ component, page, preserveState }) => {
store.update((current) => ({
component: component as ResolvedComponent,
page,
key: preserveState ? current.key : Date.now(),
}))
},
})

if (progress) {
setupProgress(progress)
}

setup({
el,
App,
props: {
initialPage,
resolveComponent,
},
})
}

0 comments on commit 12b689a

Please sign in to comment.