doc: document named slots in layouts via inline components#8600
doc: document named slots in layouts via inline components#8600
Conversation
|
Agent-Logs-Url: https://github.com/QwikDev/qwik/sessions/b0504be7-faa9-49e7-8ec8-b8c19bba1b70 Co-authored-by: wmertens <54934+wmertens@users.noreply.github.com>
|
@copilot also document the constraint that if you have nested layouts, that intermediate layouts have to be inline components too, rendering |
Agent-Logs-Url: https://github.com/QwikDev/qwik/sessions/10729b8c-8635-48e4-8095-0accfdc2db4f Co-authored-by: wmertens <54934+wmertens@users.noreply.github.com>
Added in 53e1ac6. The new "Nested layouts with named slots" subsection documents:
|
Removed example code for wrapping elements and clarified usage of component$ with Slot.
There was a problem hiding this comment.
Pull request overview
Documents the Qwik City “inline component” technique required for pages (and intermediate layouts) to target named <Slot name="..."/> areas in parent layouts, explaining why component$ pages create an opaque boundary for slot projection.
Changes:
- Adds a new “Named Slots in Layouts” section explaining the component boundary issue and the inline-default-export workaround.
- Provides examples for: named-slot layouts, inline pages targeting named slots, nested layouts propagation rules, and a hook-friendly pattern (inline shell +
component$child).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| ### Using hooks inside an inline page | ||
|
|
||
| Inline components cannot use Qwik hooks (`useSignal`, `useStore`, `useTask$`, etc.) directly. If your page needs reactive state, extract that part into a `component$` and render it inside the inline component: |
| export default ({ children }: any) => ( | ||
| <> | ||
| {/* contributes to the outer layout's "breadcrumb" slot */} |
| ) | ||
| ``` | ||
|
|
||
| You will either need to repeat the Slot structure, or move the wrapper div to the child component. |
| - mrhoodz | ||
| - aendel | ||
| - jemsco | ||
| - copilot |
commit: |
built with Refined Cloudflare Pages Action⚡ Cloudflare Pages Deployment
|
Qwik City layouts can define multiple named
<Slot name="..." />areas, but pages exported ascomponent$create an opaque component boundary — the router passes the page as a single child, soq:slotattributes inside its rendered output are invisible to the layout's slot system.The fix is to export the page as an inline component (plain function). Qwik's
flatVirtualChildren/splitProjectedChildren(inrender-ssr.ts) calls plain functions directly and flattens their JSX, makingq:slotattributes visible to the parent layout.Changes
packages/docs/src/routes/docs/(qwikcity)/layout/index.mdx— adds a new "Named Slots in Layouts" section covering:component$pages can't target layout named slots (Virtual node boundary)component$children inside the inline default export for pages that need hooks (useSignal,useStore, etc.){children}top-level inside a fragment (not wrapped in any HTML element), soq:slotattributes propagate all the way up to the outer layout's slot system{children}in an HTML element stops flattening) and thecomponent$+<Slot />alternative when a wrapper element is genuinely neededPattern
For reactive pages, wrap stateful parts in a
component$rendered inside the inline shell — hooks are unavailable in inline components directly.