Skip to content

Commit 1058317

Browse files
fix(frontend): fix weird hydration mismatch
1 parent 80750ed commit 1058317

File tree

1 file changed

+41
-33
lines changed

1 file changed

+41
-33
lines changed

src/routes/package/[...package]/+page.svelte

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,42 +8,50 @@
88
let { data } = $props();
99
</script>
1010

11-
{#if navigating.to}
11+
{#snippet loading()}
1212
<span class="inline-flex items-center justify-center">
1313
<LoaderCircle class="mr-2 size-4 animate-spin" />
1414
Loading...
1515
</span>
16+
{/snippet}
17+
18+
{#if navigating.to}
19+
{@render loading()}
1620
{:else}
17-
<div class="my-8 *:last:mt-4">
18-
<h1 class="text-5xl font-semibold text-primary">{data.currentPackage.packageName}</h1>
19-
<h2 class="text-xl text-muted-foreground">
20-
{data.currentPackage.owner}/{data.currentPackage.repoName}
21-
</h2>
22-
<h3 class="italic">*insert description*</h3>
23-
</div>
24-
<div class="flex gap-8">
25-
<Accordion.Root
26-
type="multiple"
27-
value={data.releases
28-
// Only expand releases that are less than a week old
29-
.filter(({ created_at }) => {
30-
return new Date(created_at).getTime() > new Date().getTime() - 1000 * 60 * 60 * 24 * 7;
31-
})
32-
.map(({ id }) => id.toString())}
33-
class="w-full"
34-
>
35-
{#each data.releases as release (release.id)}
36-
<ReleaseCard
37-
packageName={data.currentPackage.packageName}
38-
repo={{ owner: data.currentPackage.owner, name: data.currentPackage.repoName }}
39-
{release}
40-
/>
41-
{/each}
42-
</Accordion.Root>
43-
<SidePanel
44-
packageName={data.currentPackage.packageName}
45-
allPackages={data.displayablePackages}
46-
class="h-fit w-2/5"
47-
/>
48-
</div>
21+
<!-- Required to avoid a layout shift/hydration mismatch for some reason -->
22+
{#await Promise.resolve()}
23+
{@render loading()}
24+
{:then}
25+
<div class="my-8">
26+
<h1 class="text-5xl font-semibold text-primary">{data.currentPackage.packageName}</h1>
27+
<h2 class="text-xl text-muted-foreground">
28+
{data.currentPackage.owner}/{data.currentPackage.repoName}
29+
</h2>
30+
</div>
31+
<div class="flex gap-8">
32+
<Accordion.Root
33+
type="multiple"
34+
value={data.releases
35+
// Only expand releases that are less than a week old
36+
.filter(({ created_at }) => {
37+
return new Date(created_at).getTime() > new Date().getTime() - 1000 * 60 * 60 * 24 * 7;
38+
})
39+
.map(({ id }) => id.toString())}
40+
class="w-full"
41+
>
42+
{#each data.releases as release (release.id)}
43+
<ReleaseCard
44+
packageName={data.currentPackage.packageName}
45+
repo={{ owner: data.currentPackage.owner, name: data.currentPackage.repoName }}
46+
{release}
47+
/>
48+
{/each}
49+
</Accordion.Root>
50+
<SidePanel
51+
packageName={data.currentPackage.packageName}
52+
allPackages={data.displayablePackages}
53+
class="h-fit w-2/5"
54+
/>
55+
</div>
56+
{/await}
4957
{/if}

0 commit comments

Comments
 (0)