inertiax-svelte 1.1.3 → 2.0.0

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": "1.1.3",
3
+ "version": "2.0.0",
4
4
  "license": "MIT",
5
5
  "description": "The Svelte adapter for Inertia.js",
6
6
  "contributors": [
package/src/Render.svelte CHANGED
@@ -1,9 +1,10 @@
1
1
  <script context="module">
2
- export const h = (component, props, nested) => {
2
+
3
+ export const h = (component, props, children) => {
3
4
  return {
4
5
  component,
5
6
  ...(props ? { props } : {}),
6
- ...(nested ? { nested } : {}),
7
+ ...(children ? { children } : {}),
7
8
  }
8
9
  }
9
10
  </script>
@@ -11,13 +12,28 @@
11
12
  <script>
12
13
  import store from './store'
13
14
 
14
- const {component, props = {}, nested = []} = $props()
15
+ let {component, props = {}, children = []} = $props()
16
+
17
+ let key = $state(new Date().getTime())
18
+
19
+ let prev = component
20
+
21
+ function updateKey(component) {
22
+ if (prev !== component) {
23
+ prev = component
24
+ key = new Date().getTime()
25
+ }
26
+ }
27
+
28
+ $effect(() => updateKey(component))
15
29
  </script>
16
30
 
17
31
  {#if $store.component}
18
- <svelte:component this={component} {...props}>
19
- {#each nested as child, index (component && component.length === index ? $store.key : null)}
20
- <svelte:self {...child} />
21
- {/each}
22
- </svelte:component>
23
- {/if}
32
+ {#key key}
33
+ <svelte:component this={component} {...props}>
34
+ {#each children as child, index (component && component.length === index ? $store.key : null)}
35
+ <svelte:self {...child} />
36
+ {/each}
37
+ </svelte:component>
38
+ {/key}
39
+ {/if}
@@ -1,7 +1,6 @@
1
1
  import { router, setupProgress } from 'inertiax-core'
2
2
  import { render } from 'svelte/server';
3
3
  import App from './App.svelte'
4
- import SSR from './SSR.svelte'
5
4
  import store from './store'
6
5
 
7
6
  export default async function createInertiaApp({ id = 'app', resolve, setup, progress = {}, page }) {
@@ -51,7 +50,7 @@ export default async function createInertiaApp({ id = 'app', resolve, setup, pro
51
50
  }
52
51
 
53
52
  if (isServer) {
54
- const { html, head } = render(SSR, { props: {id, initialPage} })
53
+ const { html, head } = render(App)
55
54
 
56
55
  return {
57
56
  body: html,
package/src/SSR.svelte DELETED
@@ -1,8 +0,0 @@
1
- <script>
2
- import App from './App.svelte'
3
- const {id, initialPage} = $props()
4
- </script>
5
-
6
- <div data-server-rendered="true" {id} data-page={JSON.stringify(initialPage)}>
7
- <App />
8
- </div>