Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: @html not updating #49

Open
elron opened this issue Jul 13, 2023 · 1 comment
Open

Bug: @html not updating #49

elron opened this issue Jul 13, 2023 · 1 comment
Labels
bug Something isn't working sveltekit

Comments

@elron
Copy link

elron commented Jul 13, 2023

When I use a writable with createLocalStorage and then update,
it updates the variable everywhere, but ignores the variable when used with @html

Please check out this repo (Check out +page.svelte):
https://www.sveltelab.dev/tfpbg025yxmqvpd

@elron elron changed the title @html not updating Bug: @html not updating Jul 13, 2023
@MacFJA MacFJA added bug Something isn't working sveltekit labels Jul 14, 2023
@MacFJA
Copy link
Owner

MacFJA commented Jul 14, 2023

Look like this is linked to this issue: sveltejs/svelte#8213

There is a strange behavior with SSR and Browser update, hydration of {@html} don't see to work (but later update are OK)

You can reproduce the error without my lib:

<script>
	import { writable } from 'svelte/store';
	// import { persist, createLocalStorage } from '@macfja/svelte-persistent-store';
	import { onMount } from 'svelte';
	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); //persist(writable(1), createLocalStorage(), 'postId');
	if (browser) $postId = 2

	$: currentPost = posts.find((post) => post.id === $postId);

	/*onMount(() => {
		$postId = 2;
	});*/
</script>

<h1>Post ID: {currentPost.id}</h1>
<h2>{@html currentPost.content}</h2>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working sveltekit
Projects
None yet
Development

No branches or pull requests

2 participants