[Web] Leading, trailing, and consecutive spaces in <p> and <codeblock> are stripped by setContent on mount / setValue

オープン
#886 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

@pcbeingused333 がすでに取り組んでいます。

2026年11月27日 から。

  • #887 @pcbeingused333 による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
停滞
技術スタック
react, react-native, typescript
領域
frontend, web-dev

調査の方向性

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(...):

  1. Type leading spaces in a <codeblock> line (indentation) and at the beginning of a regular <p> paragraph.
  2. Read await ref.current.getHTML() → returns <html><codeblock><p> const x = 1;</p></codeblock><p> hello world</p></html>.
  3. Pass that HTML to another <EnrichedTextInput defaultValue={...} /> or call ref.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])
  1. Both onCreate (e.commands.setContent(tiptapContent ?? '')) and setValue (e.commands.setContent(prepareHtmlForTiptap(...))) in src/web/EnrichedTextInput.tsx call TipTap's setContent without parseOptions: { preserveWhitespace: 'full' } (or true).
  2. Because ProseMirror's DOMParser defaults to preserveWhitespace: 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.
  3. Even <codeblock> is affected because EnrichedCodeBlock (src/web/formats/EnrichedCodeBlock.ts) extends Blockquote (content: '(paragraph)+' rendered as <codeblock><p>...</p></codeblock>) without whitespace: '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, TipTap 3.31.3)
主要言語
C
スター
1.4k
フォーク
80
平均マージ
4日 19時間
マージ済み PR(30日)
21

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

software-mansion/react-native-enriched-html のほかの issue

software-mansion/react-native-enriched-html の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。