-
Notifications
You must be signed in to change notification settings - Fork 11
Add Safari clipboard support #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…th a fallback for browsers that do not support it, such as Safari.
|
Caution Review failedThe pull request is closed. WalkthroughBumps package version from 1.12.0 → 1.12.1 and converts the CLIPBOARDCOPY command handler in core utilities from a synchronous to an asynchronous function, adding async clipboard handling, fallback/error logic, and a defensive guard when constructing nodeProps. Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant CLIP_HANDLER as Handler
participant ClipboardAPI as Clipboard API
participant Fallback
rect rgb(240,248,255)
Note over User,CLIP_HANDLER: New async flow with fallback
User->>CLIP_HANDLER: trigger CLIPBOARDCOPY(text)
CLIP_HANDLER->>+ClipboardAPI: attempt async write(text)
ClipboardAPI-->>-CLIP_HANDLER: success / error
alt success
CLIP_HANDLER-->>User: resolve (done)
else error
CLIP_HANDLER->>Fallback: run fallback copy logic
Fallback-->>User: resolve (done)
end
end
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/utils/core.ts (1)
1745-1782: Consider notifying users when clipboard operations fail.Currently, clipboard failures are only logged to the console. Users may not realize the copy operation failed, especially in the Safari fallback scenario.
Consider using the existing toast notification system (already imported at line 52) to inform users:
} catch (e) { const error = e as Error; console.error("Failed to copy to clipboard:", error); + renderToast({ + id: "smartblocks-clipboard-error", + timeout: 3000, + content: "Failed to copy to clipboard. Please try again.", + position: "top", + intent: "danger", + }); } finally {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
package-lock.jsonis excluded by!**/package-lock.json
📒 Files selected for processing (2)
package.json(1 hunks)src/utils/core.ts(2 hunks)
🧰 Additional context used
🪛 Biome (2.1.2)
src/utils/core.ts
[error] 1780-1780: Unsafe usage of 'return'.
'return' in 'finally' overwrites the control flow statements inside 'try' and 'catch'.
(lint/correctness/noUnsafeFinally)
🔇 Additional comments (4)
package.json (1)
3-3: LGTM - appropriate patch version bump.The version increment from 1.12.0 to 1.12.1 is appropriate for this backward-compatible clipboard enhancement.
src/utils/core.ts (3)
1745-1782: Approve the async clipboard implementation with fallback.The approach of trying the modern Clipboard API first and falling back to
execCommandfor Safari is sound and follows best practices for cross-browser clipboard support.
2511-2513: Good defensive null check.The added guard
cur[0] ? { ...cur[0] } : ({} as InputTextNode)prevents potential undefined exposure when spreading properties, improving code robustness.
1745-1745: No issues found—async handler change is fully compatible.The CLIPBOARDCOPY handler's async change is safe. Handler invocation at src/utils/core.ts:2522 uses
Promise.resolve(handler(...args)).then(), a robust pattern that handles both synchronous and asynchronous returns. The CommandHandler type already supportsPromise<CommandOutput>, and both invocation sites properly handle async results. No code assumes synchronous behavior.
Requested vby Michael S. via slack
Summary by CodeRabbit
Bug Fixes
Chores