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

Aperta
#886 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@pcbeingused333 ci sta già lavorando.

Dal 27/11/2026.

  • #887 di @pcbeingused333 — aperta

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
Ambito
frontend, web-dev

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

  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)
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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di software-mansion/react-native-enriched-html

Tutte le issue di software-mansion/react-native-enriched-html

Issue simili

Altre issue su C

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.