Table and HTML paste handlers both insert content for the same paste event
还没有人认领这个 Issue。
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 75/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- javascript, markdown
调研方向
阅读 src/index.ts,追踪 subscribe() 安装处理程序的顺序,然后检查 src/paste-markdown-table.ts 和 src/paste-markdown-html.ts 中它们对粘贴事件的处理行为。使用 issue 的最小示例重现重复插入,并检查每个处理程序如何处理已经被阻止的事件。完成标准是一次粘贴事件只插入一次内容;报告没有指出测试文件。
由索引模型根据 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 分钟
- 30 天内合并 PR
- 2
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 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
-
cdx-audit output written to a pipe is cut off at 64 KiB可能重新可做 关联的 PR 已关闭且未合并。 未关闭bug mode:cli
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
Build produces empty forge.min.js: package.json lists "forge" instead of "node-forge"可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 1/5 1 小时以内 新手友好度 92/100
-
难度 2/5 1-3 小时 新手友好度 70/100
Fei2411/DeepSeek-Bot#963 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 78/100
Miaotofu01/Study-Mate#244 ·
维护者通常 1 天内回复
-
test-reliability
难度 2/5 1-3 小时 新手友好度 78/100
Azure/azure-sdk-for-js#40672 · 1 个 reaction ·
维护者通常 1 天内回复