Repository navigation
fix(session-ui): fall back when copying code blocks on insecure origins - #51035
myagizmaktav wants to merge 3 commits into
Conversation
|
Thanks for your contribution! This PR doesn't have a linked issue. All PRs must reference an existing issue. Please:
See CONTRIBUTING.md for details. |
|
The following comment was made by an LLM, it may be inaccurate: |
|
Checked this against #50988, fix looks correct to me. The old setupCodeCopy just bailed when navigator.clipboard was missing, which is always the case on plain HTTP. Routing it through writeClipboard makes sense, and moving it to clipboard.ts to avoid the cycle with message-content is the right call. Test covering the click path with clipboard hidden helps. Two things I noticed while reading:
But for the reported issue, this fixes it. Thanks for picking it up. |
|
Thanks @ChristopheAwad — both findings were valid and are fixed in d58edc0: ToolErrorCard now uses the shared fallback, and legacy copy is guarded with guaranteed textarea cleanup before falling through. Copied feedback remains conditional on success. Regression tests fail before the fix (6 helper failures; 11 browser failures) and pass afterward: 265 unit tests, 12 real ToolErrorCard click-path browser cases, package typecheck, and repository lint/typecheck. The full 146-case component suite also passes on an isolated Storybook port. Current dev was merged without rewriting history in 20ec936, preserving both sides. #50988 is already linked; no duplicate issue was needed. |
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
Issue for this PR
Fixes #50988
Type of change
What does this PR do?
The copy button on markdown code blocks read
navigator.clipboardand returned if it was missing. On a plain-HTTP, non-localhost origin (e.g.opencode serve --hostname 0.0.0.0opened from another device), the Clipboard API is always missing, so the button did nothing.The message and tool copy buttons in
session-uialready usewriteClipboard, which tries a hidden-textareaexecCommand("copy")first and falls back tonavigator.clipboard. The code-block button now uses the same helper and only shows "copied" when the copy actually succeeded.markdown.tsxcan't import frommessage-content.tsxbecausemessage-content.tsximportsMarkdown. SowriteClipboardmoves unchanged intocomponents/clipboard.ts, and its two existing callers import it from there. To test the real click path, the code-copy handler and its button-state helpers move out ofmarkdown.tsxintocomponents/markdown-code-copy.tsunchanged. Only the clipboard call inside the handler differs.How did you verify your code works?
New
packages/session-ui/src/components/clipboard.test.ts(happy-dom,navigator.clipboardremoved,execCommandstubbed):writeClipboardcopies through theexecCommandpath and returns truedata-copied="true"Commands:
cd packages/session-ui && bun test src: 195 pass, 0 failcd packages/session-ui && bun run typecheck: cleanoxlint+bun turbo typecheck): 0 lint errors, 35/35 typecheck tasksnavigator.clipboard-only handler, the code-block test fails (1 pass, 1 fail)Screenshots / recordings
No visual change. The existing copy button now works on insecure origins.
Checklist
Review follow-up
devin20ec936ad134f7f5c9461bc654282333c7f55ce6, preserving upstream Markdown link handling and message text pacing alongside the clipboard extraction. No history rewrite.d58edc01828819cfcda72f2c6d33f6e0cf8b23b3guards missingexecCommand, cleans up the temporary textarea infinally, falls through after legacy-copy exceptions, and routes ToolErrorCard copy through the same helper without showing copied state on failure.bun test srcexits 0 (265 pass); package typecheck exits 0; ToolErrorCard browser matrix exits 0 (12 pass); the standard pre-pushbun run checkexits 0 (36/36 typecheck tasks; lint has advisory warnings, no errors).