svelte: `@html` content in `` is duplicated

Describe the bug

simple json object of json-ld will be duplicated with injecting into the document with <svelte:head>. The tag will be rendered twice.

I use a function like this:

export const mkSchema = (thing: Schema) => {
	return `<script type="application/ld+json">${JSON.stringify(thing, null, 2)}</script>`;
};

And render like this:

<svelte:head>
    {@html mkSchema(orgSchema)}
</svelte:head>

Reproduction

https://github.com/winston0410/duplicate-head

Logs

No response

System Info

System:
    OS: macOS 11.4
    CPU: (8) arm64 Apple M1
    Memory: 123.59 MB / 8.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 17.8.0 - /opt/homebrew/bin/node
    Yarn: 1.22.17 - /opt/homebrew/bin/yarn
    npm: 8.5.5 - /opt/homebrew/bin/npm
  Browsers:
    Brave Browser: 99.1.36.119
    Safari: 14.1.1
  npmPackages:
    @sveltejs/adapter-auto: next => 1.0.0-next.34 
    @sveltejs/kit: next => 1.0.0-next.310 
    svelte: ^3.44.0 => 3.47.0

Severity

blocking all usage of SvelteKit

Additional Information

It will greatly affect the SEO of sveltekit as structured data cannot be used

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 13
  • Comments: 25 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Any update when this is going to be fixed? I have a project that depends on it, the workaround mensioned here doesn’t work in my use case.

A workaround for now is to add the json-ld in the body since it’s doesn’t make a difference for search engine bots.

@Conduitry using 3.52, the problem persists with latest kit

In a component i define some content in svelte.head. If i use this component multiple times on a page. It will add the content multiple times

There don’t seem to be any duplicates here: https://svelte.dev/repl/ffd783c9b8e54d97b6b7cac6eadace42?version=3.48.0

The duplication happens when you use SSR.

Let’s use this issue since the other one is closed. I think that issue was fixed, but some issues remain.

@hbirler you had looked at hydration stuff a decent amount earlier. I’m not sure if you’re still interested in these, but this might be an interesting case to take a look at. I confirmed that there’s a bug here