Skip to content

Conversation

@Rich-Harris
Copy link
Member

was looking into how we can make fewer things in #15538 need to be aware of the templating mode (which will make everything more robust) and ran into this <pre> logic. Took me a while to wrap my head round it but it turns out we way overcomplicated things in #14922 — the essence of this logic is that if the first node inside a <pre> is a single newline, we need to strip it because otherwise hydration breaks:

document.body.innerHTML = `<pre>
<div>...</div>
</pre>`;

document.body.querySelector('pre').firstChild; // DIV, not the newline

Instead of doing a convoluted song and dance we can just express that directly. For #15538, we do want to strip any remaining leading newline, but that should happen in template_to_functions, not here

@changeset-bot
Copy link

changeset-bot bot commented May 21, 2025

🦋 Changeset detected

Latest commit: b709136

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.

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

@svelte-docs-bot
Copy link

@github-actions
Copy link
Contributor

Playground

pnpm add https://pkg.pr.new/svelte@15980

@Rich-Harris
Copy link
Member Author

self-merging to unblock further work on #15538

@Rich-Harris Rich-Harris merged commit c03ea47 into main May 21, 2025
13 checks passed
@Rich-Harris Rich-Harris deleted the simplify-pre-cleaning branch May 21, 2025 19:09
@github-actions github-actions bot mentioned this pull request May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants