[Web] Leading, trailing, and consecutive spaces in <p> and <codeblock> are stripped by setContent on mount / setValue
I maintainer di solito rispondono entro 2 giorni
Valutazione
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Idoneità per principianti
- 25/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- react, react-native, typescript
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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)
- Lingua principale
- C
- Stelle
- 1.4k
- Fork
- 80
- Merge medio
- 4g 19h
- PR unite (30g)
- 21
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di software-mansion/react-native-enriched-html
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 74/100
software-mansion/react-native-enriched-html#885 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 35/100
software-mansion/react-native-enriched-html#881 · 1 commento ·
I maintainer di solito rispondono entro 2 giorni
-
bug
Difficoltà 3/5 1-2 giorni Idoneità per principianti 58/100
software-mansion/react-native-enriched-html#880 ·
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
software-mansion/react-native-enriched-html#878 ·
I maintainer di solito rispondono entro 2 giorni
-
[Android] Leading and consecutive spaces are lost when HTML is parsed (iOS keeps them)Forse già presa @szydlovsky l’ha presa 1 giorno fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
software-mansion/react-native-enriched-html#877 · 1 commento · 1 assegnatario ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di software-mansion/react-native-enriched-html
Issue simili
-
[Android Auto] MU1017 (MHI2Q_JP_AUG22_P1017) cluster map works with a pinned profile — values insideAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
kamgurgul/mib2q-carplay#74 ·
-
Claude:NotNeeded GPT:NotABug triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
open5gs/open5gs#5195 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
FriendsofECCE/ECCE#1358 ·
-
documentation needs-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
X11Libre/xserver#4255 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 84/100
antoxa2584x/nfsu2-sw#52 ·