Open MathiasWP opened 1 year ago
Transferred to the svelte
repo
Seems like this issue is still going on.
Here's another (very minimalistic) way to reproduce the issue: https://www.sveltelab.dev/iziz4nvzfq2g6l9
Just one file: +page.svelte
<script>
import { writable } from 'svelte/store';
import { browser } from '$app/environment';
const posts = [
{
id: 1,
content: '<span style="color:red;">Post One</span>'
},
{
id: 2,
content: '<span style="color:blue;">Post Two</span>'
}
];
const postId = writable(1);
if (browser) $postId = 2
$: currentPost = posts.find((post) => post.id === $postId);
</script>
<h1>Post ID: {currentPost.id}</h1>
<h2>{@html currentPost.content}</h2>
(Thanks @MacFJA)
When I wrap {@html ...}
with {#key browser}
, I could bypass this bug.
Describe the bug
There is some weird behaviour with the {@html} tag when:
ssr
istrue
I have created a minimal repro (see below). Here's code that causes the weird behaviour:
I tried to reproduce the bug in a svelte REPL, but with no luck. This makes me feel that the bug is a hydration and/or initialization problem, but i don't know enough of svelte-kit's inner behaviour to know for sure.
Reproduction
Link to minimal repro: https://github.com/MathiasWP/svelte-kit-at-html-bug Link to Stackblitz: https://stackblitz.com/edit/sveltejs-kit-template-default-qdzjsc
Logs
No response
System Info
Severity
serious, but I can work around it
Additional Information
No response