[Web] Leading, trailing, and consecutive spaces in <p> and <codeblock> are stripped by setContent on mount / setValue
Maintainer thường phản hồi trong vòng 2 ngày
Đá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
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(...):
- 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)
- 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
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của software-mansion/react-native-enriched-html
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 74/100
software-mansion/react-native-enriched-html#885 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
software-mansion/react-native-enriched-html#881 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
bug
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 58/100
software-mansion/react-native-enriched-html#880 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
software-mansion/react-native-enriched-html#878 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
[Android] Leading and consecutive spaces are lost when HTML is parsed (iOS keeps them)Có thể đã có người làm @szydlovsky đã nhận 1 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
software-mansion/react-native-enriched-html#877 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của software-mansion/react-native-enriched-html
Issue tương tự
-
[Android Auto] MU1017 (MHI2Q_JP_AUG22_P1017) cluster map works with a pinned profile — values insideĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
kamgurgul/mib2q-carplay#74 ·
-
Claude:NotNeeded GPT:NotABug triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
open5gs/open5gs#5195 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
FriendsofECCE/ECCE#1358 ·
-
documentation needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
X11Libre/xserver#4255 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 84/100
antoxa2584x/nfsu2-sw#52 ·