Table and HTML paste handlers both insert content for the same paste event
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 75/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 活発
- 技術スタック
- javascript, markdown
調査の方向性
src/index.tsを読んで、subscribe()がハンドラーをインストールする順序をたどり、その後src/paste-markdown-table.tsとsrc/paste-markdown-html.tsを調べて、貼り付けイベントの動作を確認してください。issueの最小例で二重挿入を再現し、すでにキャンセルされたイベントを各ハンドラーがどう扱うかを確認してください。1回の貼り付けイベントでコンテンツが1回だけ挿入されれば完了です。報告にはテストファイル名が記載されていません。
索引モデルが issue の本文から書いたものです。
説明
Summary
A single paste event containing an HTML table and a link can insert the selection twice: once through the table handler and again through the HTML/link handler.
This was reported when copying from BlockNote to GitHub: https://github.com/TypeCellOS/BlockNote/issues/3305. However, the duplication can be reproduced with this package alone and with ordinary text/plain content—no BlockNote dependency or Markdown in the plain-text representation is necessary.
Verification
Reproduced in a browser using the published @github/[email protected] package:
- The table handler inserts its result and calls
preventDefault()andstopPropagation(). - The HTML handler subsequently runs on the same textarea with
event.defaultPrevented === trueand inserts another representation of the selection. - Skipping handlers when
event.defaultPreventedis already true prevents the second insertion.
Both handlers are registered by subscribe(), and the duplication also reproduces using subscribe() instead of installing the two handlers individually.
This verifies the published library's behavior; it is not a separate verification of GitHub.com's currently deployed bundle.
Minimal reproduction
Save the following as an HTML file and open it in a browser with network access. Click Run. The results show the unmodified behavior and a guarded control. The control wraps listener registration only to demonstrate the effect of checking defaultPrevented; it is not intended as the proposed implementation.
<!doctype html>
<meta charset="utf-8">
<button id="run">Run</button>
<pre id="results"></pre>
<script type="module">
import {installTable, installHTML} from 'https://esm.sh/@github/[email protected]?bundle';
function run(guard) {
const field = document.createElement('textarea');
document.body.append(field);
field.focus();
const calls = [];
const original = field.addEventListener;
field.addEventListener = function(type, listener, options) {
if (type !== 'paste') return original.call(this, type, listener, options);
return original.call(this, type, function(event) {
calls.push({defaultPreventedAtEntry: event.defaultPrevented, skipped: guard && event.defaultPrevented});
if (guard && event.defaultPrevented) return;
listener.call(this, event);
}, options);
};
installTable(field);
installHTML(field);
const data = new DataTransfer();
data.setData('text/html', '<p><a href="https://example.com/test">Test</a></p><table><tr><th>A</th><th>B</th></tr><tr><td>C</td><td>D</td></tr></table>');
// Ordinary plain text, deliberately NOT Markdown.
data.setData('text/plain', 'Test\nA\tB\nC\tD');
field.dispatchEvent(new ClipboardEvent('paste', {
clipboardData: data,
bubbles: true,
cancelable: true
}));
const result = {guard, calls, output: field.value};
field.remove();
return result;
}
document.querySelector('#run').addEventListener('click', function() {
document.querySelector('#results').textContent = JSON.stringify([run(false), run(true)], null, 2);
});
</script>
Actual result without guard
Handler entry states:
[
{"defaultPreventedAtEntry": false, "skipped": false},
{"defaultPreventedAtEntry": true, "skipped": false}
]
Textarea contents:
<p><a href="https://example.com/test">Test</a></p>
A | B
-- | --
C | D
[Test](https://example.com/test)
A B
C D
With the guard enabled, the second handler sees defaultPrevented === true and is skipped, removing the duplicate insertion.
Expected behavior
Only one handler should insert content for a paste event. Handlers should coordinate ownership of the event, for example by respecting event.defaultPrevented before processing an already-handled paste.
stopPropagation() does not stop other listeners on the same element, and preventDefault() does not prevent those listeners from running either.
Relevant source
At commit 86be75f8b746fcfc40cb1a9850f7124980c9253a:
Related but separate issues
- https://github.com/github/paste-markdown/issues/96 covers nested Markdown links when
text/plainalready contains Markdown. This report is specifically about duplicate insertion, which also occurs with unformatted plain text. - The table handler retaining surrounding HTML is another concern; preventing duplicate insertion alone does not fix that behavior.
- https://github.com/opf/openproject/pull/25964 documents a downstream workaround using
data-paste-markdown-skipon tables.
- 主要言語
- JavaScript
- スター
- 232
- フォーク
- 48
- 平均マージ
- 17分
- マージ済み PR(30日)
- 2
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
github/paste-markdown のほかの issue
-
Pasting a link whose text/html label is a shortened form of its URL plants a `[` inside the URL対応中かも @pranayshirolkar が 92 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
github/paste-markdown#118 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
github/paste-markdown#107 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 45/100
github/paste-markdown#104 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
github/paste-markdown#100 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 48/100
github/paste-markdown#96 · コメント 1 件 ·
github/paste-markdown の issue をすべて見る
似ている issue
-
test-reliability
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Azure/azure-sdk-for-js#40672 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
txn2/mcp-data-platform#2492 ·
メンテナーはふだん 1 日以内に返信
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
liberation-data/drivine#639 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
accessibility ux
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
prophet-technocracy/civilizational-emergency-protocol#59 ·
メンテナーはふだん 1 日以内に返信
-
type: bug
難易度 1/5 1〜3時間 初心者へのやさしさ 72/100
RocketChat/Rocket.Chat#43554 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信