Skip to content

Commit 347225c

Browse files
Removed nested <a> elements to resolve hydration failure
1 parent 28c67d8 commit 347225c

File tree

2 files changed

+48
-29
lines changed

2 files changed

+48
-29
lines changed

src/components/card/Card.svelte

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,38 @@ A generic card element.
3131
Children are rendered on a colored card with rounded corners.
3232
-->
3333

34-
<a
35-
href={linkHref}
36-
onclick={async (e) => {
37-
if (link) {
38-
await goto(link.url);
39-
} else if (onclick) {
40-
onclick(e);
41-
}
42-
}}
43-
target={linkNewTab}
44-
>
34+
{#snippet content()}
4535
<div
4636
class="card"
4737
style:--base-color={baseColor}
4838
style:--hover-color={hoverColor}
4939
>
5040
{@render children()}
5141
</div>
52-
</a>
42+
{/snippet}
43+
44+
<!--
45+
HACK: Workaround for https://github.com/sveltejs/kit/issues/11057
46+
Very yucky, but I'll have to live with it since technically this is the only way to get valid HTML
47+
:(
48+
-->
49+
{#if link}
50+
<a
51+
href={linkHref}
52+
onclick={async (e) => {
53+
if (link) {
54+
await goto(link.url);
55+
} else if (onclick) {
56+
onclick(e);
57+
}
58+
}}
59+
target={linkNewTab}
60+
>
61+
{@render content()}
62+
</a>
63+
{:else}
64+
{@render content()}
65+
{/if}
5366

5467
<style>
5568
a {

src/components/card/ItemCard.svelte

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,26 @@
2727
);
2828
</script>
2929

30-
<Card
31-
link={editing ? undefined : { url: `/${groupId}/${itemId}`, newTab: false }}
32-
color={item.info.color}
33-
{onclick}
34-
>
30+
<Card color={item.info.color} {onclick}>
3531
<div class="card-outer">
36-
<div class:card-icon={item.info.icon} class:flex-grow={true}>
37-
{#if item.info.icon}
38-
<img
39-
src="/{groupId}/{itemId}/{item.info.icon}"
40-
alt="Icon for {item.info.name}"
41-
class="label-icon"
42-
/>
43-
{/if}
44-
<div>
45-
<h3>{item.info.name}</h3>
46-
<p>{item.info.description}</p>
32+
<a
33+
href={editing ? undefined : `/${groupId}/${itemId}`}
34+
class:flex-grow={true}
35+
>
36+
<div class:card-icon={item.info.icon}>
37+
{#if item.info.icon}
38+
<img
39+
src="/{groupId}/{itemId}/{item.info.icon}"
40+
alt="Icon for {item.info.name}"
41+
class="label-icon"
42+
/>
43+
{/if}
44+
<div>
45+
<h3>{item.info.name}</h3>
46+
<p>{item.info.description}</p>
47+
</div>
4748
</div>
48-
</div>
49+
</a>
4950
{#if !editing}
5051
<div>
5152
<ItemChipList
@@ -61,6 +62,11 @@
6162
</Card>
6263

6364
<style>
65+
a {
66+
color: black;
67+
text-decoration: none;
68+
}
69+
6470
h3 {
6571
margin-bottom: 0;
6672
}

0 commit comments

Comments
 (0)