Skip to content

Commit bf61286

Browse files
committed
refactor(test-app): make window props reactive to page
Update Svelte test app components to assign window properties reactively when $page.props changes, ensuring global props stay in sync with page state. This replaces static assignments with $effect blocks for better reactivity and correctness.
1 parent f39a609 commit bf61286

File tree

8 files changed

+54
-12
lines changed

8 files changed

+54
-12
lines changed

packages/svelte5/test-app/Layouts/NestedLayout.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@
66
77
onMount(() => {
88
window._inertia_nested_layout_id = crypto.randomUUID()
9-
window._inertia_nested_layout_props = page.props
109
createdAt = Date.now()
1110
})
11+
12+
// Update props reactively when page changes
13+
$effect(() => {
14+
if (typeof window !== 'undefined') {
15+
window._inertia_nested_layout_props = $page.props
16+
}
17+
})
1218
</script>
1319

1420
<div>

packages/svelte5/test-app/Layouts/SiteLayout.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@
66
77
onMount(() => {
88
window._inertia_layout_id = crypto.randomUUID()
9-
window._inertia_site_layout_props = page.props
109
createdAt = Date.now()
1110
})
11+
12+
// Update props reactively when page changes
13+
$effect(() => {
14+
if (typeof window !== 'undefined') {
15+
window._inertia_site_layout_props = $page.props
16+
}
17+
})
1218
</script>
1319

1420
<div>

packages/svelte5/test-app/Pages/Home.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,15 @@
2020
2121
onMount(() => {
2222
window._inertia_page_key = crypto.randomUUID()
23-
window._inertia_props = $page.props
2423
window._plugin_global_props = {}
2524
})
25+
26+
// Update props reactively when page changes
27+
$effect(() => {
28+
if (typeof window !== 'undefined') {
29+
window._inertia_props = $page.props
30+
}
31+
})
2632
</script>
2733

2834
<div>

packages/svelte5/test-app/Pages/PersistentLayouts/Shorthand/Nested/PageA.svelte

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
<script lang="ts">
99
import { inertia, page } from '@inertiajs/svelte5'
1010
11-
window._inertia_page_props = page.props
11+
// Update props reactively when page changes
12+
$effect(() => {
13+
if (typeof window !== 'undefined') {
14+
window._inertia_page_props = $page.props
15+
}
16+
})
1217
</script>
1318

1419
<div>

packages/svelte5/test-app/Pages/PersistentLayouts/Shorthand/Nested/PageB.svelte

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@
88
<script lang="ts">
99
import { inertia, page } from '@inertiajs/svelte5'
1010
11-
window._inertia_page_props = page.props
11+
// Update props reactively when page changes
12+
$effect(() => {
13+
if (typeof window !== 'undefined') {
14+
window._inertia_page_props = $page.props
15+
}
16+
})
1217
</script>
1318

1419
<div>

packages/svelte5/test-app/Pages/PersistentLayouts/Shorthand/Simple/PageA.svelte

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
<script lang="ts">
88
import { inertia, page } from '@inertiajs/svelte5'
99
10-
window._inertia_page_props = page.props
10+
// Update props reactively when page changes
11+
$effect(() => {
12+
if (typeof window !== 'undefined') {
13+
window._inertia_page_props = $page.props
14+
}
15+
})
1116
</script>
1217

1318
<div>

packages/svelte5/test-app/Pages/PersistentLayouts/Shorthand/Simple/PageB.svelte

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
<script lang="ts">
88
import { inertia, page } from '@inertiajs/svelte5'
99
10-
window._inertia_page_props = page.props
10+
// Update props reactively when page changes
11+
$effect(() => {
12+
if (typeof window !== 'undefined') {
13+
window._inertia_page_props = $page.props
14+
}
15+
})
1116
</script>
1217

1318
<div>

packages/svelte5/test-app/Pages/Visits/PartialReloads.svelte

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22
import { page, router } from '@inertiajs/svelte5'
33
import { onMount } from 'svelte'
44
5-
export let foo
6-
export let bar
7-
export let baz
8-
export let headers
5+
const { foo, bar, baz, headers } = $props()
96
107
onMount(() => {
11-
window._inertia_props = page.props
8+
// Other initialization if needed
9+
})
10+
11+
// Update props reactively when page changes
12+
$effect(() => {
13+
if (typeof window !== 'undefined') {
14+
window._inertia_props = $page.props
15+
}
1216
})
1317
1418
const partialReloadVisit = () => {

0 commit comments

Comments
 (0)