[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 小时
- 30 天内合并 PR
- 21
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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 一周以上 新手友好度 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 ·