Skip to content

Dev-time check for {@html ...} mismatch #12362

@Rich-Harris

Description

@Rich-Harris

Describe the problem

In a case like this...

<div>{browser ? 'browser' : 'server'}</div>

...Svelte will update the text node upon hydration. It does not update {@html ...} tags however:

<div>{@html browser ? 'browser' : 'server'}</div>

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions