Repository navigation
fix(h5): handle clipboard copy failures and clean up temporary textareas - #19548
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
WalkthroughH5 的 ChangesH5 剪贴板复制
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Low Merge Risk: ⚪ Minimal · up to
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #19548 +/- ##
==========================================
+ Coverage 56.43% 56.56% +0.12%
==========================================
Files 467 467
Lines 25680 25686 +6
Branches 6452 6433 -19
==========================================
+ Hits 14493 14529 +36
+ Misses 9304 9169 -135
- Partials 1883 1988 +105
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
|
建议继续使用 另外,当前 |
|
@Single-Dancer 感谢指出这两个边界场景,已在 688575d 中跟进:
这里确实可能部分成功:系统复制与 localStorage 写入无法原子更新或回滚。本次没有吞掉存储异常,也没有将缓存写入移回复制前;若要改成系统复制成功即 API 成功,还需进一步约定缓存写入失败后的读取策略,避免随后读取旧缓存。 另外补充一点兼容性信息:核对 MDN Browser Compatibility Data 的 验证: |
688575d to
b279896
Compare
|
还发现一个问题,execCommand('copy') 可能同步触发全局 copy 监听器,而监听器会在复制结果确认前更新 taro_clipboard。如果复制随后失败,系统剪贴板未更新,但 getClipboardData() 已经会读到新内容,造成缓存与真实剪贴板不一致。建议复制期间跳过监听器的缓存写入,统一由成功路径更新;同时注意 setStorageSync 的同步异常无法被后续 .catch() 捕获。 |
b279896 to
3c56a55
Compare
|
@Single-Dancer 这个问题确实存在,已在 e07be5c 中修复并推送:
保留此前约定:系统复制成功后,如果显式缓存写入失败,API 仍返回失败。 验证: |
这个 PR 做了什么?
H5
setClipboardDatacurrently reports success and displays the copy-success toast even whendocument.execCommand('copy')returnsfalse. If selecting or copying throws, its temporary textarea remains attached to the document.Check the command result and route failures through
MethodHandler.fail. Remove the temporary textarea infinally, and move the explicit cache update after a successful copy. Preserve successful multiline copying and thehideDefaultMessageoption.Closes #19547
这个 PR 是什么类型?
这个 PR 涉及以下平台:
验证
execCommand, cached content, and successful copies with/without the default toast. Six cases fail against the original implementation.pnpm --filter @tarojs/taro-h5 test:ci --watchman=false: 26 suites, 187 tests passed.git -c core.whitespace=cr-at-eol diff --checkpassed; the source file retains its existing CRLF line endings.pnpm --filter @tarojs/taro-h5 build: passed with exit code 0 outside the restricted execution sandbox; warnings remain in unchanged files.Summary by CodeRabbit