[RENDERER]: a line break at the start of a <textarea> differs between toString() and a client render
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 58/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- javascript
- Ambito
- frontend
Direzione di ricerca
Start with parseRawText() in src/dom-parts/parseTemplate.js and the text writer in src/dom-parts/stringify.js, as named in the proposal. Reproduce both textarea cases from the issue and compare toString(), client render, and hydration values. Done means both cases preserve the specified value across all three paths, while style, script, and title output remains unchanged.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Goal
A <textarea> with interpolated content has the same value in markup from toString(), after a client render and after hydration, also when a line break stands at the start of its content.
Context
The HTML parser drops one line break that directly follows a <textarea> start tag, also when it is written as . textContent, which the client render writes, drops nothing. The renderer treats both the same, so the two sides disagree in two cases. Measured in Chromium with 1.3.1 and with #189 at 802e47a.
Case 1, the value starts with a line break:
const template = html`<textarea>${'\nMilk'}</textarea>`;
template.toString(); // …<textarea>\nMilk</textarea>…, the parser makes it "Milk"
template.renderInto(node); // "\nMilk"
Case 2, the literal has a line break after the start tag:
html`<textarea
id="input-${this.name}"
name="${this.name}"
rows="${this.rows}"
>
${this.value}</textarea>`;
textarea.value for each case (⏎ is the line break in the literal):
| Version | Literal | Value | Parsed from toString() |
Client render | After hydration |
|---|---|---|---|---|---|
| 1.3.1 and #189 | <textarea>${v}</textarea> |
"\nMilk" |
"Milk" |
"\nMilk" |
"\nMilk" |
| #189 | <textarea>⏎${v}</textarea> |
"Milk" |
"Milk" |
"\nMilk" |
"\nMilk" |
| #189 | <textarea>⏎${v}</textarea> |
"\nMilk" |
"\nMilk" |
"\n\nMilk" |
"\n\nMilk" |
In case 1 the server-rendered field has lost the first line break until the element hydrates, and for good without JavaScript: saving the form writes the text back without it.
In case 2 the server-rendered field is right, and hydration then puts an empty line in front of the text. Prettier (3.9.10) and Oxfmt both write exactly this literal once a <textarea> has enough attributes to wrap: the line break after the start tag is the one place where it does not change the content. In 1.3.1 that literal does not render at all (#185: the client throws ParseTemplateError, toString() writes the part markers into the textarea as text), so case 2 only shows with #189.
Seen in @webtides/element-library: el-textarea-field renders its value as the content of the textarea since webtides/element-library#93. A stored text that starts with an empty line loses it in server-rendered markup. Its template is kept away from the formatter with // oxfmt-ignore because of #185. With #189 that could go, but case 2 would take its place.
<pre> is not affected. The parser drops a leading line break there too, but the content is a node part that starts with a comment marker: html`<pre>${'\nMilk'}</pre>` gives "\nMilk" on the server, on the client and after hydration, in both versions.
Acceptance criteria
- For
html`<textarea>${value}</textarea>`and a value that starts with a line break, the textarea parsed fromtoString()has exactly that value, the same as after a client render. - One line break in the literal directly after the
<textarea …>start tag is not content: a literal written that way givesvalueon the server, on the client and after hydration. - Hydrating either markup leaves the value of the textarea as it is.
-
<style>,<script>and<title>are written as before. The parser drops nothing there.
Proposal (non-binding)
One rule for textarea, mirroring the parser on both sides:
- When the literal is parsed, drop one line break (
\nor\r\n) at the start of the first static string of a textarea's content. - When markup is written, put a line break after the start tag if the joined content starts with one. The parser then drops that one and leaves the content alone.
In #189 that is parseRawText() in src/dom-parts/parseTemplate.js and the text writer in src/dom-parts/stringify.js.
Out of scope
- 1.3.1 drops static text next to a single interpolation on the client:
html`<textarea>Dear ${'Ann'}</textarea>`rendersAnn, whiletoString()writesDear Ann. #189 fixes it, the client rendersDear Annthere. - A textarea without interpolations. Both sides parse the same markup, so they agree.
- Working around it in element-library by adding the line break in the component. The component cannot tell a server render from a client render, so the value would be wrong on one of the two.
- Lingua principale
- JavaScript
- Stelle
- 30
- Fork
- 5
- Merge medio
- 1h 57m
- PR unite (30g)
- 10
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di webtides/element-js
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
webtides/element-js#201 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
webtides/element-js#198 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
webtides/element-js#194 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
webtides/element-js#193 ·
I maintainer di solito rispondono entro 1 giorno
-
[RENDERER]: only the first raw text element with interpolations is handled, a line break inside one breaks it tooForse già presa @eddyloewen l’ha presa 28 giorni fa. Apertabug
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
webtides/element-js#185 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di webtides/element-js
Issue simili
-
area:testing bug effort:low model:light plan planner:gpt-6-2-sol tests
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
enhancement good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
Agent360dk/browser-mcp#124 ·
I maintainer di solito rispondono entro 2 giorni
-
area:site feature good first issue help wanted
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
pacocartones/free-llm-api-hub#829 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 1/5 1-3 ore Idoneità per principianti 78/100
Jason-Vaughan/TangleClaw#3270 ·
I maintainer di solito rispondono entro 1 giorno