Skip to content

<pre> tag does not respect newlines in custom components with slots #128

Description

@eltrevii

Astro Info

Astro                    v7.1.3
Node                     v24.16.0
System                   Windows (x64)
Package Manager          bun
Output                   static
Adapter                  none
Integrations             @sentry/astro
                         @spotlightjs/astro
                         astro-icon

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

i have a custom <details> wrapper which uses a <pre> inside because i want to include content with its line breaks intact, so i use a slot inside the <pre>, like this (the example includes some extra styling i use):

---
// src/components/Dropdown.astro
const { title } = Astro.props;
---
<details aria-label="details">
    <summary>{title}</summary>
<pre><slot /></pre></details>

so, when using this component and its slot in other files, like so:

<Dropdown title="Pre in custom component">
First line
Second line
</Dropdown>

the newlines are not respected:
Image

however, if the <pre> tag is removed from the component:

---
// src/components/DropdownNoPre.astro
const { title } = Astro.props;
---
<details aria-label="details">
    <summary>{title}</summary>
<slot /></details>

and the tag is provided to the component like this:

<DropdownNoPre title="Pre outside component (in slot)"><pre>
First line
Second line
</pre></DropdownNoPre>

then, it works as expected:
Image

What's the expected result?

the newlines are equally respected in both components, like so:

Image

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-48f6wvvv?file=src%2Fpages%2Findex.astro

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P3: minor bugAn edge case that only affects very specific usage (priority)needs triagetriage: failedTriage failed unexpectedly; can be retried up to 3 failed attempts

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions