Skip to content

Commit fbfce9e

Browse files
committed
Fix updating to capture values on server rendering as well as client rendering
1 parent 0cb0dde commit fbfce9e

10 files changed

Lines changed: 47 additions & 37 deletions

File tree

Site/src/components/Navbar.svelte

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
let { user } = $derived(data)
1111
1212
let nav1: [string, string, string][] = $state([])
13-
$effect(() => {
13+
function updNav1() {
1414
nav1 = [
1515
// ["Home", "/", "fa-house-chimney"],
1616
["Games", "/games", "fa-mountain-sun"],
@@ -23,12 +23,13 @@
2323
if (data.pages.includes("Groups"))
2424
nav1.push(["Groups", "/groups", "fa-people-group"])
2525
})
26-
})
26+
}
27+
updNav1()
28+
$effect(updNav1)
2729
2830
// sing, sing, sing (https://www.youtube.com/watch?v=c0pJzW8pxWU)
2931
let usernav: [string, string, string][] = $state([])
30-
31-
$effect(() => {
32+
function updUsernav() {
3233
usernav = [
3334
["fa-money-bill-transfer", "Economy", "/economy"],
3435
["fa-user-group", "Friends", "/requests"],
@@ -42,7 +43,9 @@
4243
if (user && user.permissionLevel >= 4)
4344
usernav.unshift(["fa-diamond-half-stroke", "Admin", "/admin"])
4445
})
45-
})
46+
}
47+
updUsernav()
48+
$effect(updUsernav)
4649
</script>
4750

4851
<nav class="py-0 justify-start z-11">

Site/src/components/Pagination.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717
type Page = number | null
1818
1919
let pages: Page[] = $state([])
20-
21-
$effect(() => {
20+
function updPages() {
2221
pages = []
2322
untrack(() => {
2423
pages.push(1)
@@ -28,7 +27,9 @@
2827
if (currentPage + 1 < totalPages) pages.push(0)
2928
if (totalPages > 1) pages.push(totalPages)
3029
})
31-
})
30+
}
31+
updPages()
32+
$effect(updPages)
3233
3334
const disabled = "opacity-50 pointer-events-none"
3435
</script>

Site/src/components/Search.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@
2222
const searchResults: HTMLElement[] = $state([])
2323
2424
let searchCategories: [string, string][] = $state([])
25-
$effect(() => {
25+
function updSearchCategories() {
2626
searchCategories = [
27-
["Games", "games"],
2827
["Users", "users"],
2928
["Places", "places"],
3029
["Catalog", "assets"]
@@ -33,7 +32,9 @@
3332
if (pages.includes("Groups"))
3433
searchCategories.push(["Groups", "groups"])
3534
})
36-
})
35+
}
36+
updSearchCategories()
37+
$effect(updSearchCategories)
3738
3839
function keydown(
3940
e: KeyboardEvent & {

Site/src/components/forms/Input.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
formData: import("sveltekit-superforms").SuperForm<any>
2929
} & HTMLInputAttributes = $props()
3030
31-
const { errors } = formData
31+
let { errors } = $derived(formData)
3232
</script>
3333

3434
<div class="flex flex-wrap {inline ? 'flex-1' : 'pb-8'}">

Site/src/components/forms/Select.svelte

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -27,24 +27,26 @@
2727
formData: import("sveltekit-superforms").SuperForm<any>
2828
} = $props()
2929
30-
const { form, errors, constraints } = formData
30+
let { form, errors, constraints } = $derived(formData)
3131
3232
let trigger = $state<HTMLElement>()
33-
let dropdown = $state<HTMLElement>()
33+
// let dropdown = $state<HTMLElement>()
3434
35-
const select = new Select<string>({
36-
value: selected,
37-
onValueChange: val => {
38-
$form[name] = val
39-
}
35+
let select = $derived(
36+
new Select<string>({
37+
value: selected,
38+
onValueChange: val => {
39+
$form[name] = val
40+
}
4041
41-
// floatingConfig: {
42-
// onCompute: a => {
43-
// console.log(a)
44-
// a.floatingApply(dropdown)
45-
// }
46-
// }
47-
})
42+
// floatingConfig: {
43+
// onCompute: a => {
44+
// console.log(a)
45+
// a.floatingApply(dropdown)
46+
// }
47+
// }
48+
})
49+
)
4850
</script>
4951

5052
<div class="flex flex-wrap pb-8">

Site/src/components/forms/SubInput.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
type: HTMLInputTypeAttribute
1818
formData: import("sveltekit-superforms").SuperForm<any>
1919
} & HTMLInputAttributes = $props()
20-
const { form, errors, constraints } = formData
20+
21+
let { form, errors, constraints } = $derived(formData)
2122
</script>
2223

2324
{#if type === "checkbox"}

Site/src/components/forms/Textarea.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
formData: import("sveltekit-superforms").SuperForm<any>
2323
} & HTMLTextareaAttributes = $props()
2424
25-
const { form, errors, constraints } = formData
25+
let { form, errors, constraints } = $derived(formData)
2626
2727
// TODO: prevent tabs in textarea caused by... the formatter....
2828
$effect(() => {

Site/src/routes/(main)/develop/create/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
1010
const { data } = $props()
1111
12-
const formData = superForm(data.form)
12+
let formData = $derived(superForm(data.form))
1313
export const snapshot = formData
1414
15-
const [, c1, c2] = beautifyCurrency(data.price)
15+
let [, c1, c2] = $derived(beautifyCurrency(data.price))
1616
1717
const assets: { [_: number]: string } = Object.freeze({
1818
2: "T-Shirt",

Site/src/routes/(main)/home/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
const { data } = $props()
1212
1313
let { user } = $derived(data)
14-
const formData = superForm(data.form)
14+
let formData = $derived(superForm(data.form))
1515
export const snapshot = formData
1616
</script>
1717

Site/src/routes/(main)/place/[id=asset]/[name]/Autopilot.svelte

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
1616
let filepath = $state("")
1717
18-
const host = beginJoining(
19-
() =>
20-
// TODO: fix hosting and map opening with correct URI scheme
21-
`${scheme}1+launchmode:ide+script:http://${domain}/game/host?ticket=${serverTicket}&autopilot=${btoa(
22-
filepath
23-
)}`
18+
let host = $derived(
19+
beginJoining(
20+
() =>
21+
// TODO: fix hosting and map opening with correct URI scheme
22+
`${scheme}1+launchmode:ide+script:http://${domain}/game/host?ticket=${serverTicket}&autopilot=${btoa(
23+
filepath
24+
)}`
25+
)
2426
)
2527
</script>
2628

0 commit comments

Comments
 (0)