-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
{@html ...}
tag is populated too late
#7341
Comments
fixed <div bind:clientHeight={h} /><main>{@html html}{''}</main> |
+1 this is easily my geatest desire for Svelte. I would love to be able to turn off repair mode |
This is a bit more than annoyance, it actually broke my code. I've created a REPL to replicate my issue: The "display" is shifted right and down compared to the cursor, but aligns perfectly in 3.46.3: |
@Herdubreid That doesn't seem related to this issue, but to #6990 instead. Svelte's behavior was changed because it didn't respect whitespace inside |
That makes sense @mrkishi, changing |
This fix is quite simple. Change: <div>
<textarea bind:value={text} style:height={height} spellcheck="false" />
<pre>
<code id="display">
{@html code}
</code>
</pre>
</div> To: <div>
<textarea bind:value={text} style:height={height} spellcheck="false" />
<pre><code id="display">{@html code}</code></pre>
</div> Basically remove unwanted whitespaces within the Thanks for pointing me in the right direction @mrkishi (this has been doing my head in for days)! |
…nstead of deopt to claiming every nodes (#7426) Related: #7341, #7226 For purely static HTML, instead of walking the node tree and claiming every node/text etc, hydration now uses the same innerHTML optimization technique for hydration compared to normal create. It uses a new data-svelte-h attribute which is added upon server side rendering containing a hash (computed at build time), and then comparing that hash in the client to ensure it's the same node. If the hash is the same, the whole child content is expected to be the same. If the hash is different, the whole child content is replaced with innerHTML. --------- Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com> Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com> Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>
Describe the bug
Bear with me, this is a bit of an edge case.
If you have code like this...
it will compile with
hydratable: true
to this:Between
main_nodes.forEach(detach)
andmain.innerHTML = html
, the addition of the resize listener causes a reflow that, long story short, results in you losing your scroll position if you were previously scrolled to#foo
and there's not much content on the page other than the contents of{@html ...}
. This is currently visible on the SvelteKit docs: sveltejs/kit#4216. (Only on Chrome, not Firefox.)Removing the
bind:clientHeight
(or placing it below the{@html ...}
) prevents the bug, as would using aResizeObserver
instead of the resize listener hack. But the biggest mystery is why we're waiting until the mount phase (m
) to doinnerHTML = html
instead of the claim phase (l
).(Aside: it would be nice if there was a way to say 'you don't need to replace me, I promise my contents won't have changed since SSR' —
{@html:leavemealone post.html}
or whatever.)Reproduction
Open this StackBlitz repro and go to the standalone version: https://sveltejs-kit-template-default-pm2sdq--3000.local.webcontainer.io/
Logs
No response
System Info
Severity
annoyance
The text was updated successfully, but these errors were encountered: