Skip to content

fix(core): prevent SSR crash when head/body projected through a headless Slot#8668

Merged
Varixo merged 3 commits into
build/v2from
v2-fix-slot-head-body-placeholder
May 28, 2026
Merged

fix(core): prevent SSR crash when head/body projected through a headless Slot#8668
Varixo merged 3 commits into
build/v2from
v2-fix-slot-head-body-placeholder

Conversation

@maiieul
Copy link
Copy Markdown
Member

@maiieul maiieul commented May 27, 2026

What is it?

  • Bug

Description

SSR crashed with Code(Q12): SsrError(tag) when <head>/<body> were projected through a headless component (e.g. a Provider that renders only <Slot/>, like a root context provider).

Such a component gets a useOn placeholder <script> injected to anchor a document/window handler. When it wraps <head>/<body>, that placeholder ended up as a direct child of <html> — invalid HTML, which threw. It now defers into <head>, mirroring how $appendStyle$ already routes root-level styles into additionalHeadNodes instead of emitting them inline at the <html> frame.

Mostly hit in dev, since HMR injects such a handler into every component — so any <Slot/>-wrapped head/body broke even with no useOn in app code.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 27, 2026

🦋 Changeset detected

Latest commit: 6cd4a33

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

This PR includes changesets to release 5 packages
Name Type
@qwik.dev/core Patch
eslint-plugin-qwik Patch
@qwik.dev/react Patch
@qwik.dev/router Patch
create-qwik Patch

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

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

@maiieul maiieul self-assigned this May 27, 2026
@maiieul maiieul moved this to Waiting For Review in Qwik Development May 27, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 27, 2026

Open in StackBlitz

@qwik.dev/core

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/core@8668

@qwik.dev/router

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/router@8668

eslint-plugin-qwik

npm i https://pkg.pr.new/QwikDev/qwik/eslint-plugin-qwik@8668

create-qwik

npm i https://pkg.pr.new/QwikDev/qwik/create-qwik@8668

@qwik.dev/optimizer

npm i https://pkg.pr.new/QwikDev/qwik/@qwik.dev/optimizer@8668

commit: 6cd4a33

@maiieul maiieul force-pushed the v2-fix-slot-head-body-placeholder branch from e41a012 to f7b9492 Compare May 27, 2026 11:53
@maiieul maiieul requested a review from a team as a code owner May 27, 2026 11:53
…ess Slot

A headless component (renders only <Slot/>) that projects the document
root gets a useOn placeholder <script> injected to anchor a document/window
handler. When it wraps <head>/<body>, that placeholder landed as a direct
child of <html> — invalid HTML that throws Code(Q12): SsrError(tag). It now
defers into <head> via additionalHeadNodes. Mostly hit in dev, since HMR
injects such a handler into every component.
@maiieul maiieul force-pushed the v2-fix-slot-head-body-placeholder branch from f7b9492 to 5fd7174 Compare May 27, 2026 12:01
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 27, 2026

built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
qwik-docs ✅ Ready (View Log) Visit Preview 6cd4a33

Comment thread packages/qwik/src/core/client/dom-container.ts Outdated
Comment thread packages/qwik/src/core/shared/component-execution.ts
Comment thread packages/qwik/src/core/shared/component-execution.ts Outdated
Comment thread packages/qwik/src/core/tests/slot-head-body.spec.tsx Outdated
Comment thread packages/qwik/src/server/ssr-container.ts Outdated
Comment thread packages/qwik/src/core/shared/shared-container.ts Outdated
Comment thread packages/qwik/src/core/shared/types.ts Outdated
Comment thread packages/qwik/src/core/tests/projection.spec.tsx Outdated
@maiieul maiieul force-pushed the v2-fix-slot-head-body-placeholder branch from 1f2eeca to 11efadb Compare May 27, 2026 13:24
@maiieul maiieul force-pushed the v2-fix-slot-head-body-placeholder branch from 11efadb to 3c0c064 Compare May 27, 2026 13:27
Comment thread packages/qwik/src/core/shared/component-execution.ts Outdated
Comment thread packages/qwik/src/core/shared/types.ts Outdated
Move $deferRootPlaceholder$ from the Container interface to the SSRContainer
interface and cast at the call site (avoids an optional field on Container).
Copy link
Copy Markdown
Member

@Varixo Varixo left a comment

Choose a reason for hiding this comment

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

LGTM

@Varixo Varixo merged commit 08f3433 into build/v2 May 28, 2026
31 checks passed
@github-project-automation github-project-automation Bot moved this from Waiting For Review to Done in Qwik Development May 28, 2026
@Varixo Varixo deleted the v2-fix-slot-head-body-placeholder branch May 28, 2026 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants