-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
svelte:head tags outside __layout not included in SSR output #2142
Comments
I can't reproduce. All header tags (see potential new issue below) seem to be included in SSR as well as CSR. The order is correct as well, since you have the Also, Svelte doesn't filter out duplicate tags (EDIT: except One issue I do see is that the Edit: Yes, according to @Conduitry the I don't know if this is a good thing. Now it's not so clear which title is included. Handling the title like any other tag would be better IMO. And there is more chances for bugs. Edit: And indeed, here is the bug #2146 |
@vwkd I don't think so. I'm not worried about duplicate tags as I'm aware of that issue, but the Here's an example page: https://deploy-preview-32--keen-murdock-f65a9a.netlify.app/articles/coca-cola-vs-craft-soda-revolution View the raw source and search for "twitter:title". It's not present. Then view the DOM with web inspector and you'll see it there. |
(by the way I tried putting the |
I'm still failing to reproduce any lost tags (except a What I do see is that the SSR uses the page component title instead of the layout component title, and then client-side hydration changes it to the layout component title. I'm not sure why. I found this note on
Here is a screencast: title_change_on_hydration.mov |
@vwkd thanks for the repro project. I cloned it locally and I can see that the head is being set correctly from the custom "About" route component. It's very strange because this is the same structure as my real app. I'm trying to add things into the repro app now (eg. a (Aside: yes the <title> tag behaviour is very strange with SvelteKit. I've been confused by it in the past. Apparently there is some logic in svelte to deduplicate any <title> tags in the svelte:head but I'm not sure the ordering always makes sense.) |
@vwkd I also noticed this line from the svelte docs. I have no idea what it means though... |
I found the problem. It was an error in my code where I was wrapping a This was because I have a component called // src/components/PageMeta.svelte
<script>
let title;
let description;
</script>
<svelte:head>
<title>{title}</title>
<meta name="description" content={description} />
<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content={title} />
<meta name="twitter:description" content={description} />
</svelte:head>
// src/routes/some-route.svelte
<script>
import PageMeta from '../components/PageMeta.svelte';
</script>
// this is the problem:
<svelte:head>
<PageMeta title="Custom title" description="Some custom description" />
</svelte:head>
<!-- page content --> Removing the It's actually somewhat surprising that the client-side gracefully handles this situation and injects the tags at all! 😆 Many thanks for the quick repro app @vwkd! It was very helpful for me to realize my mistake ❤️ |
Describe the bug
The contents of
<svelte:head>
are only server-side rendered if they are defined inside__layout.svelte
For many very common reasons, I would like to define custom meta tags on a per-route basis. For example I'd like OpenGraph/twitter meta tags that correspond to the content on the page.
However, when specifying these tags inside
<svelte:head>
in a specific route, they are only injected into<head>
of the document on the client-side. This defeats the entire purpose of these tags which are fetched by social networks and search engine spiders which typically won't execute javascript to read the content of the meta tags to generate previews.This is happening on my production build on Netlify using the standard adapter-netlify adapter.
Reproduction
src/routes/__layout.svelte
src/routes/some-route.svelte
:/some-route
in browser<head>
<head>
Logs
No response
System Info
The text was updated successfully, but these errors were encountered: