Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c03ea47

Browse filesBrowse files
authored
chore: simplify <pre> cleaning (#15980)
1 parent 4e72b7d commit c03ea47
Copy full SHA for c03ea47

File tree

Expand file treeCollapse file tree

2 files changed

+10
-12
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+10
-12
lines changed

‎.changeset/fifty-llamas-know.md

Copy file name to clipboard
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
chore: simplify `<pre>` cleaning

‎packages/svelte/src/compiler/phases/3-transform/utils.js

Copy file name to clipboardExpand all lines: packages/svelte/src/compiler/phases/3-transform/utils.js
+5-12Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -271,19 +271,12 @@ export function clean_nodes(
271271

272272
var first = trimmed[0];
273273

274-
// initial newline inside a `<pre>` is disregarded, if not followed by another newline
274+
// if first text node inside a <pre> is a single newline, discard it, because otherwise
275+
// the browser will do it for us which could break hydration
275276
if (parent.type === 'RegularElement' && parent.name === 'pre' && first?.type === 'Text') {
276-
const text = first.data.replace(regex_starts_with_newline, '');
277-
if (text !== first.data) {
278-
const tmp = text.replace(regex_starts_with_newline, '');
279-
if (text === tmp) {
280-
first.data = text;
281-
first.raw = first.raw.replace(regex_starts_with_newline, '');
282-
if (first.data === '') {
283-
trimmed.shift();
284-
first = trimmed[0];
285-
}
286-
}
277+
if (first.data === '\n' || first.data === '\r\n') {
278+
trimmed.shift();
279+
first = trimmed[0];
287280
}
288281
}
289282

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.