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
- [fix] Fix hydration duplicate `svelte:head` tag issue with `@html` expressions and nested components (#7745) * Fix hydration duplicate `svelte:head` tag issue with `@html` and nested components #7444... — committed to sveltejs/svelte by maxiruani 2 years ago
- attempting to fix the duplicate meta tags using a handle hook function, as provided by mihaon on 'https://github.com/sveltejs/svelte/issues/7444'. I also noticed that this is an SSR issue since when t... — committed to brightowltutoring/sveltekit by brightowltutoring 2 years ago
- Squashed commit of the following: commit c7dcfac883a34655421932258d3d5a3b0ee96362 Author: Theodore Brown <theodorejb@outlook.com> Date: Mon Mar 13 12:21:51 2023 -0500 fix: select option with s... — committed to hgiesel/svelte by hgiesel a year ago
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
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