inertiax-svelte 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inertiax-svelte",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "license": "MIT",
5
5
  "description": "The Svelte adapter for Inertia.js",
6
6
  "contributors": [
@@ -1,4 +1,5 @@
1
1
  import { router, setupProgress } from 'inertiax-core'
2
+ import escape from 'html-escape'
2
3
  import { render } from 'svelte/server';
3
4
  import App from './App.svelte'
4
5
  import store from './store'
@@ -16,47 +17,46 @@ export default async function createInertiaApp({ id = 'app', resolve, setup, pro
16
17
  })
17
18
  })
18
19
 
19
- if (!isServer) {
20
- router.init({
21
- initialPage,
22
- resolveComponent,
23
- swapComponent: async ({ component, page, preserveState }) => {
24
- const targetFrame = page.target
25
- if (targetFrame) store.update((current) => ({
26
- ...current,
27
- frames: { ...current.frames, [targetFrame]: {component, props: page.props} }
28
- }))
29
- else store.update((current) => ({
30
- component,
31
- page,
32
- frames: current.frames,
33
- key: preserveState ? current.key : Date.now(),
34
- }))
35
- },
36
- })
37
-
38
- if (progress) {
39
- setupProgress(progress)
40
- }
41
-
42
- return setup({
43
- el,
44
- App,
45
- props: {
46
- initialPage,
47
- resolveComponent,
48
- },
49
- })
50
- }
51
-
52
20
  if (isServer) {
53
21
  const { html, head } = render(App)
54
22
 
55
23
  return {
56
- body: html,
24
+ body: `<div data-server-rendered="true" data-page="${escape(JSON.stringify(initialPage))}">${html}</div>`,
57
25
  head: [
58
26
  head
59
27
  ],
60
28
  }
61
29
  }
30
+
31
+ router.init({
32
+ initialPage,
33
+ resolveComponent,
34
+ swapComponent: async ({ component, page, preserveState }) => {
35
+ const targetFrame = page.target
36
+ if (targetFrame) store.update((current) => ({
37
+ ...current,
38
+ frames: { ...current.frames, [targetFrame]: {component, props: page.props} }
39
+ }))
40
+ else store.update((current) => ({
41
+ component,
42
+ page,
43
+ frames: current.frames,
44
+ key: preserveState ? current.key : Date.now(),
45
+ }))
46
+ },
47
+ })
48
+
49
+ if (progress) {
50
+ setupProgress(progress)
51
+ }
52
+
53
+ return setup({
54
+ el,
55
+ App,
56
+ props: {
57
+ initialPage,
58
+ resolveComponent,
59
+ },
60
+ })
61
+
62
62
  }