[RENDERER]: a line break at the start of a <textarea> differs between toString() and a client render
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 58/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript
- 領域
- frontend
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- JavaScript
- スター
- 30
- フォーク
- 5
- 平均マージ
- 1時間 57分
- マージ済み PR(30日)
- 10
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
webtides/element-js のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
webtides/element-js#201 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
webtides/element-js#198 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
webtides/element-js#194 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
webtides/element-js#193 ·
メンテナーはふだん 1 日以内に返信
-
[RENDERER]: only the first raw text element with interpolations is handled, a line break inside one breaks it too対応中かも @eddyloewen が 28 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
webtides/element-js#185 ·
メンテナーはふだん 1 日以内に返信
webtides/element-js の issue をすべて見る
似ている issue
-
area:testing bug effort:low model:light plan planner:gpt-6-2-sol tests
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
enhancement good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
Agent360dk/browser-mcp#124 ·
メンテナーはふだん 2 日以内に返信
-
area:site feature good first issue help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
pacocartones/free-llm-api-hub#829 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 1/5 1〜3時間 初心者へのやさしさ 78/100
Jason-Vaughan/TangleClaw#3270 ·
メンテナーはふだん 1 日以内に返信