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

Đang mở
#886 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@pcbeingused333 đang làm issue này rồi.

Từ ngày 27/11/2026.

  • #887 của @pcbeingused333 — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
25/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
react, react-native, typescript
Lĩnh vực
frontend, web-dev

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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)
Ngôn ngữ chính
C
Star
1.4k
Fork
80
Merge trung bình
4 ngày 19 giờ
Pull request đã merge (30 ngày)
21

Chuẩn bị môi trường

  • Không có Dockerfile hay tệp Docker Compose
  • Có mẫu pull request
  • Không có hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của software-mansion/react-native-enriched-html

Tất cả issue của software-mansion/react-native-enriched-html

Issue tương tự

Thêm issue về C

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.