Skip to content

Commit 3642a55

Browse files
committed
fixes async svelte issue
1 parent 37b4f15 commit 3642a55

7 files changed

Lines changed: 26 additions & 21 deletions

File tree

src/lib/zero.svelte.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,24 @@ async function get_z_options() {
3737

3838
return {
3939
userID,
40-
kvStore: 'mem',
40+
kvStore: 'mem' as const,
4141
server: PUBLIC_SERVER,
4242
schema,
4343
mutators,
4444
context,
45-
jwt: jwt || undefined
46-
} as const;
45+
auth: jwt || undefined
46+
};
4747
}
4848

49+
// Top-level await to initialize Z with proper auth context
50+
// This works correctly when experimental.async is DISABLED
4951
export const z = new Z(await get_z_options());
5052

53+
// Function to reinitialize Z with fresh JWT (call after login)
54+
export async function reinitializeZ() {
55+
const options = await get_z_options();
56+
z.build(options);
57+
}
58+
5159
// Re-export queries and mutators for convenient access
5260
export { queries, mutators };

src/routes/(style)/(admin)/+layout.svelte

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<script lang="ts">
2-
import { page } from '$app/stores';
2+
import { page } from '$app/state';
33
import Bread from '$lib/ui/Bread.svelte';
44
import { queries } from '$lib/queries';
55
import { z } from '$lib/zero.svelte';
6-
import type { Snippet } from 'svelte';
76
8-
const { children }: { children: Snippet } = $props();
7+
const { children } = $props();
98
109
const user = z.createQuery(queries.user.current());
1110
@@ -73,7 +72,7 @@
7372
{#each links as link}
7473
<a
7574
href={link.href}
76-
aria-current={$page.url.pathname === link.href ? 'page' : undefined}
75+
aria-current={page.url.pathname === link.href ? 'page' : undefined}
7776
>{link.label}</a
7877
>
7978
{/each}

src/routes/(style)/(admin)/admin/hax/+page.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,5 @@
4040

4141
<div class="stack" style:--gap="40px;">
4242
<h1>Hax</h1>
43-
4443
<Table data={hax.data} {columns} />
4544
</div>

src/routes/(style)/(admin)/admin/targets/+page.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,5 @@
4949
<div class="actions">
5050
<a href="/admin/targets/init" class="button go_button">Create Target</a>
5151
</div>
52-
5352
<Table data={targets.data} {columns} />
5453
</div>

src/routes/(style)/(menu)/+layout.svelte

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { page } from '$app/stores';
2+
import { page } from '$app/state';
33
import { queries } from '$lib/queries';
44
import { z } from '$lib/zero.svelte';
55
@@ -62,24 +62,23 @@
6262
<nav class="sidebar-nav">
6363
<a
6464
href="/dashboard"
65-
aria-current={$page.url.pathname === '/dashboard'
66-
? 'page'
67-
: undefined}>Battles</a
65+
aria-current={page.url.pathname === '/dashboard' ? 'page' : undefined}
66+
>Battles</a
6867
>
6968
<a
7069
href="/history"
71-
aria-current={$page.url.pathname === '/history' ? 'page' : undefined}
70+
aria-current={page.url.pathname === '/history' ? 'page' : undefined}
7271
>History</a
7372
>
7473
<a
7574
href="/settings"
76-
aria-current={$page.url.pathname === '/settings' ? 'page' : undefined}
75+
aria-current={page.url.pathname === '/settings' ? 'page' : undefined}
7776
>Settings</a
7877
>
7978
{#if user.data?.role === 'syntax'}
8079
<a
8180
href="/admin/"
82-
aria-current={$page.url.pathname.startsWith('/admin')
81+
aria-current={page.url.pathname.startsWith('/admin')
8382
? 'page'
8483
: undefined}>Admin</a
8584
>

svelte.config.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ const config = {
66
// Consult https://svelte.dev/docs/kit/integrations
77
// for more information about preprocessors
88
preprocess: vitePreprocess(),
9-
compilerOptions: {
10-
experimental: {
11-
async: true
12-
}
13-
},
9+
// Disabled: experimental.async breaks SvelteKit client-side navigation
10+
// compilerOptions: {
11+
// experimental: {
12+
// async: true
13+
// }
14+
// },
1415

1516
kit: {
1617
adapter: adapter(),

zero.db-wal

101 KB
Binary file not shown.

0 commit comments

Comments
 (0)