Skip to content

Conversation

@mdroidian
Copy link
Collaborator

@mdroidian mdroidian commented Nov 11, 2025

Requested vby Michael S. via slack

Summary by CodeRabbit

  • Bug Fixes

    • Improved clipboard copy behavior with asynchronous handling, better error handling, and a reliable fallback for more consistent copy operations.
  • Chores

    • Patch release bumped to v1.12.1.

…th a fallback for browsers that do not support it, such as Safari.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 11, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

Bumps 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

Cohort / File(s) Summary
Version Update
package.json
Incremented package version from 1.12.0 to 1.12.1.
Async Clipboard Handler
src/utils/core.ts
Converted CLIPBOARDCOPY command handler from synchronous (text = "") => { ... } to asynchronous async (text = "") => { ... }; added async clipboard copy with fallback/error handling and a defensive guard for nodeProps construction to avoid undefined.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Review the async signature change to handler in src/utils/core.ts and ensure callers tolerate async handlers.
  • Verify clipboard fallback/error handling covers expected failure modes.
  • Confirm the new defensive guard for nodeProps preserves intended behavior and types.

Poem

🐇 I hopped to copy, found async light,
A fallback pocket safe and bright,
One-dot-one-two now sings anew,
Clipboard hops — quick, calm, and true 🥕📋

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add Safari clipboard support' directly describes the main change: adding clipboard support specifically for Safari, which aligns with the CLIPBOARDCOPY handler becoming async with improved clipboard handling logic.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 52bec1d and 0a1eb64.

📒 Files selected for processing (1)
  • src/utils/core.ts (2 hunks)

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📥 Commits

Reviewing files that changed from the base of the PR and between a9579bb and 52bec1d.

⛔ Files ignored due to path filters (1)
  • package-lock.json is 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 execCommand for 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 supports Promise<CommandOutput>, and both invocation sites properly handle async results. No code assumes synchronous behavior.

@mdroidian mdroidian merged commit c2d2b23 into main Nov 11, 2025
1 of 3 checks passed
@mdroidian mdroidian deleted the safari-clipboard branch November 11, 2025 04:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants