[Web] Leading, trailing, and consecutive spaces in <p> and <codeblock> are stripped by setContent on mount / setValue
メンテナーはふだん 2 日以内に返信
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 25/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- react, react-native, typescript
調査の方向性
Start with src/web/EnrichedTextInput.tsx and inspect the setContent calls in onCreate and setValue, then read src/web/formats/EnrichedCodeBlock.ts and the htmlNormalizer.ts behavior described in the issue. Reproduce with the supplied defaultValue example and compare the resulting getHTML() output after mount and setValue. Done means the reported spaces survive both paths without turning layout newlines between blocks into extra content; pull request #887 is already open.
索引モデルが issue の本文から書いたものです。
説明
Description
On web, <EnrichedTextInput> renders .ProseMirror with white-space: pre-wrap; white-space: break-spaces, so leading, trailing, and consecutive spaces typed by the user are stored in ProseMirror and serialized into HTML by getHTML() / onChangeHtml (e.g. <codeblock><p> const x = 1;</p></codeblock> or <p> hello</p>).
However, when that same HTML is passed back via defaultValue (initial mount / reload) or ref.current.setValue(html), leading and trailing spaces are stripped and consecutive spaces are collapsed to a single space.
Minimal Reproduction
<EnrichedTextInput
defaultValue='<html><codeblock><p> const x = 1;</p></codeblock><p> hello world </p></html>'
/>
Or via ref.current.setValue(...):
- Type leading spaces in a
<codeblock>line (indentation) and at the beginning of a regular<p>paragraph. - Read
await ref.current.getHTML()→ returns<html><codeblock><p> const x = 1;</p></codeblock><p> hello world</p></html>. - Pass that HTML to another
<EnrichedTextInput defaultValue={...} />or callref.current.setValue(html).
Expected:
Leading indentation in <codeblock>, leading/trailing spaces in <p>, and consecutive spaces are preserved ( const x = 1; and hello world).
Actual:
ProseMirror strips leading and trailing spaces and collapses consecutive spaces into a single space (const x = 1; and hello world), even inside <codeblock>. Additionally, any subsequent edit silently overwrites the persisted HTML without those spaces.
Root Cause (in [email protected])
- Both
onCreate(e.commands.setContent(tiptapContent ?? '')) andsetValue(e.commands.setContent(prepareHtmlForTiptap(...))) insrc/web/EnrichedTextInput.tsxcall TipTap'ssetContentwithoutparseOptions: { preserveWhitespace: 'full' }(ortrue). - Because ProseMirror's
DOMParserdefaults topreserveWhitespace: false:addTextNode(prosemirror-model) collapses[ \t\r\n\u000c]+to' 'and slices off the leading whitespace at the start of every block (!nodeBefore),NodeContext.finish()strips trailing whitespace at the end of every block.
- Even
<codeblock>is affected becauseEnrichedCodeBlock(src/web/formats/EnrichedCodeBlock.ts) extendsBlockquote(content: '(paragraph)+'rendered as<codeblock><p>...</p></codeblock>) withoutwhitespace: 'pre', so its child<p>nodes use the same default HTML whitespace collapsing rules.
(Note: when useHtmlNormalizer is true, htmlNormalizer.ts already strips inter-block layout whitespace before setContent, whereas passing preserveWhitespace when useHtmlNormalizer is false would need care not to turn pretty-printed \n between blocks from native <html>\n<p>...</p>\n</html> into extra text/paragraphs. At minimum, <codeblock> and setContent handling should preserve indentation and user-entered spaces consistently with <EnrichedText> .et-view which uses white-space: pre-wrap.)
Environment
react-native-enriched-html:1.2.0- Platform: Web (
Chrome, TipTap3.31.3)
- 主要言語
- C
- スター
- 1.4k
- フォーク
- 80
- 平均マージ
- 4日 19時間
- マージ済み PR(30日)
- 21
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドなし
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
software-mansion/react-native-enriched-html のほかの issue
-
bug
難易度 3/5 1〜2日 初心者へのやさしさ 74/100
software-mansion/react-native-enriched-html#885 ·
メンテナーはふだん 2 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
software-mansion/react-native-enriched-html#881 · コメント 1 件 ·
メンテナーはふだん 2 日以内に返信
-
bug
難易度 3/5 1〜2日 初心者へのやさしさ 58/100
software-mansion/react-native-enriched-html#880 ·
メンテナーはふだん 2 日以内に返信
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
software-mansion/react-native-enriched-html#878 ·
メンテナーはふだん 2 日以内に返信
-
[Android] Leading and consecutive spaces are lost when HTML is parsed (iOS keeps them)対応中かも @szydlovsky が 1 日前に担当しました。 オープン
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
software-mansion/react-native-enriched-html#877 · コメント 1 件 · 担当者 1 名 ·
メンテナーはふだん 2 日以内に返信
software-mansion/react-native-enriched-html の issue をすべて見る
似ている issue
-
[Android Auto] MU1017 (MHI2Q_JP_AUG22_P1017) cluster map works with a pinned profile — values insideオープン
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
kamgurgul/mib2q-carplay#74 ·
-
Claude:NotNeeded GPT:NotABug triage
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
open5gs/open5gs#5195 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
FriendsofECCE/ECCE#1358 ·
-
documentation needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
X11Libre/xserver#4255 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 84/100
antoxa2584x/nfsu2-sw#52 ·