[Web] Manual <a href="URL">URL</a> links adjacent to non-whitespace characters are stripped on initial mount / setValue

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

I maintainer di solito rispondono entro 2 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
74/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
react, typescript
Ambito
frontend

Direzione di ricerca

Start with src/web/formats/EnrichedLink.ts and src/web/pmPlugins/AutolinkPlugin/index.ts, then trace how setContent triggers the plugin on initial mount. Check the link parsing and autolink transaction behavior for URL links adjacent to other text. Done means the manual link remains in the editor HTML after remount or setValue, including the punctuation and adjacent word cases in the issue.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug
Description

On web, when <EnrichedTextInput> loads HTML containing a link whose text matches its href (for example inserted manually via ref.current.setLink(...) without surrounding spaces, or wrapped in punctuation like (https://example.com)), the <a> mark is silently stripped on initial mount / setContent.

Minimal Reproduction
<EnrichedTextInput
  defaultValue='<html><p>foo<a href="https://example.com">https://example.com</a>bar</p></html>'
/>

Or programmatically / via toolbar:

  1. Place cursor inside existing word foobar (between foo and bar).
  2. Insert link via editor.setLink(start, end, "https://example.com", "https://example.com").
    • Before reload, getHTML() preserves <p>foo<a href="https://example.com">https://example.com</a>bar</p>.
  3. Remount <EnrichedTextInput> with that saved HTML in defaultValue (or call setValue(...)).

Expected:
The <a href="https://example.com">https://example.com</a> link is preserved.

Actual:
The link mark is stripped and only plain text foohttps://example.combar remains in the editor DOM.

Root Cause (in [email protected])
  1. EnrichedLink (src/web/formats/EnrichedLink.ts, addAttributes().auto.parseHTML) classifies any parsed <a href="X">X</a> as auto: true whenever href === el.textContent and isFullLinkMatch(href, linkRegex) is true (unless linkRegex === null). Because renderHTML does not persist whether a link was manual or auto, manually created URL links come back as auto: true on reload.
  2. Immediately on onCreate → editor.commands.setContent(...) (src/web/EnrichedTextInput.tsx), AutolinkPlugin (src/web/pmPlugins/AutolinkPlugin/index.ts) runs appendTransaction:
    • It splits block runs by whitespace (/\S+/g), yielding the full token "foohttps://example.combar".
    • It requires a full-word match (r.start === 0 && r.endExclusive === word.length), which is false.
    • removeAutoLinksInRange then removes every link mark with attrs.auto === true.

The same happens for cases like (<a href="https://example.com">https://example.com</a>) or any URL-labeled link touching non-whitespace characters on either side.

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.