Skip to content

Commit

Permalink
Merge pull request #36 from MaddyGuthridge/maddy-fix-card-hydration-i…
Browse files Browse the repository at this point in the history
…ssue

Removed nested <a> elements to prevent hydration failure
  • Loading branch information
MaddyGuthridge authored Nov 16, 2024
2 parents 28c67d8 + 2d59485 commit 02b9e32
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 32 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "minifolio",
"version": "0.6.2",
"version": "0.6.3",
"private": true,
"license": "GPL-3.0-only",
"scripts": {
Expand Down
37 changes: 25 additions & 12 deletions src/components/card/Card.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -31,25 +31,38 @@ A generic card element.
Children are rendered on a colored card with rounded corners.
-->

<a
href={linkHref}
onclick={async (e) => {
if (link) {
await goto(link.url);
} else if (onclick) {
onclick(e);
}
}}
target={linkNewTab}
>
{#snippet content()}
<div
class="card"
style:--base-color={baseColor}
style:--hover-color={hoverColor}
>
{@render children()}
</div>
</a>
{/snippet}

<!--
HACK: Workaround for https://github.com/sveltejs/kit/issues/11057
Very yucky, but I'll have to live with it since technically this is the only way to get valid HTML
:(
-->
{#if link}
<a
href={linkHref}
onclick={async (e) => {
if (link) {
await goto(link.url);
} else if (onclick) {
onclick(e);
}
}}
target={linkNewTab}
>
{@render content()}
</a>
{:else}
{@render content()}
{/if}

<style>
a {
Expand Down
40 changes: 23 additions & 17 deletions src/components/card/ItemCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,26 @@
);
</script>

<Card
link={editing ? undefined : { url: `/${groupId}/${itemId}`, newTab: false }}
color={item.info.color}
{onclick}
>
<Card color={item.info.color} {onclick}>
<div class="card-outer">
<div class:card-icon={item.info.icon} class:flex-grow={true}>
{#if item.info.icon}
<img
src="/{groupId}/{itemId}/{item.info.icon}"
alt="Icon for {item.info.name}"
class="label-icon"
/>
{/if}
<div>
<h3>{item.info.name}</h3>
<p>{item.info.description}</p>
<a
href={editing ? undefined : `/${groupId}/${itemId}`}
class:flex-grow={true}
>
<div class:card-icon={item.info.icon}>
{#if item.info.icon}
<img
src="/{groupId}/{itemId}/{item.info.icon}"
alt="Icon for {item.info.name}"
class="label-icon"
/>
{/if}
<div>
<h3>{item.info.name}</h3>
<p>{item.info.description}</p>
</div>
</div>
</div>
</a>
{#if !editing}
<div>
<ItemChipList
Expand All @@ -61,6 +62,11 @@
</Card>

<style>
a {
color: black;
text-decoration: none;
}
h3 {
margin-bottom: 0;
}
Expand Down

0 comments on commit 02b9e32

Please sign in to comment.