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

オープン
#885 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 2 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
74/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
react, typescript
領域
frontend

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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)
主要言語
C
スター
1.4k
フォーク
80
平均マージ
4日 19時間
マージ済み PR(30日)
21

環境構築

  • Dockerfile・Docker Compose ファイルなし
  • プルリクエストのテンプレートあり
  • コントリビューションガイドなし

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

software-mansion/react-native-enriched-html のほかの issue

software-mansion/react-native-enriched-html の issue をすべて見る

似ている issue

C の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。