question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Treat layout pages like components when using named slots

See original GitHub issue

Let’s say I have a _layout.svelte like the following:

<slot name="layout-pre"></slot>

<div id="intermediate">Some other intermediate stuff.</div>

<slot></slot>

And now I have a child view (let’s call it homepage.svelte which inherits that layout, which puts some stuff into the named slot, and the rest into the default slot:

<h1 slot="layout-pre">This should come before #intermediate.</h1>

<!-- When rendered, the div from above should get inserted here from the layout:
<div id="intermediate">Some other intermediate stuff.</div>
-->

<main>Since this doesn't use a named slot, it'll just get inserted into the unnamed slot above.</main>

Right now this is not allowed, and the following error is thrown: Element with a slot='...' attribute must be a descendant of a component or custom element. Are there technical or usage reasons why we wouldn’t want to treat a layout like any other component with respect to slots?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:198
  • Comments:44 (14 by maintainers)

github_iconTop GitHub Comments

50reactions
NickantXcommented, Nov 1, 2021

Any updates on this? This is still quite the annoyance.

24reactions
stalkergcommented, May 1, 2021

I agree, without this feature any dynamic sidebar becoming a disaster.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Using templates and slots - Web Components | MDN
Slots are identified by their name attribute, and allow you to define placeholders in your template that can be filled with any markup...
Read more >
Slots - Vue.js
When a component accepts both a default slot and named slots, all top-level non- <template> nodes are implicitly treated as content for the...
Read more >
A comprehensive guide to Svelte components with slots
Take a deep dive into Svelte components with slots by learning how they work and how to use them to supercharge your Svelte...
Read more >
Shadow DOM slots, composition
Let's see how slots work on a simple example. ... In the shadow DOM, <slot name="X"> defines an “insertion point”, a place where...
Read more >
Vue layout with named slots - Stack Overflow
The default slot works, but "header" slot doesn't display itself (unless using MyLayout as standard component). vue.js · slot · Share.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found