Skip to content

Commit 8d2e90f

Browse files
feat: remove SvelteQueryDevTools from prod bundle (#519)
1 parent df63bba commit 8d2e90f

File tree

2 files changed

+29
-25
lines changed

2 files changed

+29
-25
lines changed

src/frontend/src/routes/+layout.svelte

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,38 +13,21 @@
1313
import type { LayoutData } from './$types';
1414
import { type Component, type Snippet } from 'svelte';
1515
import { MetaTags, deepMerge } from 'svelte-meta-tags';
16-
import { user_store } from '$lib/store/user.svelte';
17-
import { logout } from '$lib/remote/auth.remote';
18-
import { TOKEN_VALIDATE_URL } from '#consts/backend';
19-
import { browser } from '$app/environment';
20-
import { dev } from '$app/environment';
2116
2217
let { children, data }: { children: Snippet; data: LayoutData } = $props();
2318
24-
let SvelteQueryDevtools = $state<Component<any> | null>(null);
25-
if (dev) {
19+
async function loadDevtools() {
20+
if (!import.meta.env.DEV) return null;
21+
2622
const mod = await import('@tanstack/svelte-query-devtools');
27-
SvelteQueryDevtools = mod.SvelteQueryDevtools;
23+
return mod.SvelteQueryDevtools;
2824
}
2925
30-
if (browser) {
31-
$effect.pre(() => {
32-
if (!data.token) return;
26+
let SvelteQueryDevtools = $state<Component<any> | null>(null);
3327
34-
void fetch(TOKEN_VALIDATE_URL, {
35-
credentials: 'include'
36-
})
37-
.then((res) => {
38-
if (res.ok) {
39-
user_store.authenticate();
40-
} else {
41-
logout();
42-
}
43-
})
44-
.catch((_) => {
45-
console.log(`Error while fetching token data`);
46-
user_store.unauthenticate();
47-
});
28+
if (import.meta.env.DEV) {
29+
loadDevtools().then((c) => {
30+
SvelteQueryDevtools = c;
4831
});
4932
}
5033

src/frontend/src/routes/+layout.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1+
import { TOKEN_VALIDATE_URL } from '#consts/backend';
12
import { browser } from '$app/environment';
23
import image from '$lib/assets/opengraph.png?url';
4+
import { logout } from '$lib/remote/auth.remote';
5+
import { user_store } from '$lib/store/user.svelte';
36
import { QueryClient } from '@tanstack/svelte-query';
47
import { defineBaseMetaTags } from 'svelte-meta-tags';
58
import type { LayoutLoad } from './$types';
9+
610
export const trailingSlash = 'always';
711

812
export const load: LayoutLoad = async ({ data, url }) => {
@@ -38,5 +42,22 @@ export const load: LayoutLoad = async ({ data, url }) => {
3842
}
3943
});
4044

45+
if (data.token) {
46+
void fetch(TOKEN_VALIDATE_URL, {
47+
credentials: 'include'
48+
})
49+
.then((res) => {
50+
if (res.ok) {
51+
user_store.authenticate();
52+
} else {
53+
logout();
54+
}
55+
})
56+
.catch((_) => {
57+
console.log(`Error while fetching token data`);
58+
user_store.unauthenticate();
59+
});
60+
}
61+
4162
return { queryClient, ...baseTags, ...data };
4263
};

0 commit comments

Comments
 (0)