-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Dev-time check for {@html ...}
mismatch
#12362
Comments
I'm hoping that we don't need to worry about browsers normalizing/messing with HTML when we do this? It will just be a simple string comparison (via hashes) of literally what the server sent and what the client thinks it should be? |
Exactly, yeah, the browser wouldn't be involved. Literally just hashing the |
This sounds really fun to work on...can i take a shot at it? In case the answer is yes should i use the native sha256 implementation from crypto to hash or something else that is faster/produces smaller hashes? |
You can use this — it just needs to be moved to a place where it can be imported by both compiler and runtime without a lot of svelte/packages/svelte/src/compiler/phases/2-analyze/utils.js Lines 7 to 14 in 6ac1ae8
|
Great i will take a shot at this likely this evening. |
Also just for clarification
At dev time i suppose means "on the server" here right? |
On the server it means |
Oh ok got it now! |
Also the output of this should just be a warning? |
yep. see |
Describe the problem
In a case like this...
...Svelte will update the text node upon hydration. It does not update
{@html ...}
tags however:This is deliberate — these often contain large chunks of HTML rendered from a CMS or a markdown file, and as such it's very rare that there's a discrepancy between server and client. It would be expensive to either a) check that everything matches or b) remove it and reinsert it.
We make a similar trade-off in the case of things like
src
attributes, since we don't want to reload iframes or kick off additional network requests. But in those cases we warn about the discrepancy at dev time. It would be nice to do the same thing for{@html ...}
tags.Describe the proposed solution
At dev time, hash the content and put the hash in the opening hydration boundary comment. In the browser, repeat, and check that the hashes match.
Importance
nice to have
The text was updated successfully, but these errors were encountered: