Skip to content

Conversation

@fabhari
Copy link
Contributor

@fabhari fabhari commented Dec 7, 2025

Before submitting the PR, please make sure you do the following

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • Prefix your PR title with feat:, fix:, chore:, or docs:.
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.
  • If this PR changes code within packages/svelte/src, add a changeset (npx changeset).

Tests and linting

  • Run the tests with pnpm test and lint the project with pnpm lint

this PR fixes 9163

fabhari and others added 3 commits December 5, 2025 16:45
- Fix server-side rendering (SSR) by creating a capture renderer in the head() function that only pushes head content to the parent renderer, discarding body output - Add collect_sync() public method to Renderer for synchronous content collection - Fix client-side rendering (CSR) by filtering non-head-specific elements after rendering in head blocks, moving body elements (div, span, etc.) to the body while keeping head-specific elements (script, meta, link, style, title, etc.) in the head This ensures that when a component with both <svelte:head> and body content is placed inside a parent <svelte:head>, only the nested component's head content appears in the document head, and body content correctly appears in the document body. Fixes: Components rendering inside svelte:head had body content leaking into head section
…re moved to body if the nested component has any
@changeset-bot
Copy link

changeset-bot bot commented Dec 7, 2025

🦋 Changeset detected

Latest commit: e8f6c10

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
svelte Patch

Not sure what this means? Click here to learn what changesets are.

tag">Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Dec 7, 2025

Playground

pnpm add https://pkg.pr.new/svelte@17324 
@fabhari
Copy link
Contributor Author

fabhari commented Dec 7, 2025

Playground with fix


block(() => render_fn(anchor), HEAD_EFFECT);

// After rendering, check if non-head elements were added and move them to body
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I very doubt this logic makes sense. Aside from "Why do you mix head and body elements?", these elements became un-cleanable in case the component/head is wrapped in #if or something else dynamic. And probably breaks other blocks like #each.

@Rich-Harris
Copy link
Member

Thanks but this isn't a useful feature. A component inside a <svelte:head> should not contain body content

@Rich-Harris Rich-Harris closed this Dec 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants