Skip to content

πŸ› fix(ui): make click-to-copy work on insecure contexts and fix tooltip feedback (#472) - #481

Merged
scttbnsn merged 4 commits into
mainfrom
fix/472-clipboard-insecure-context
Jul 6, 2026
Merged

scttbnsn merged 4 commits into
mainfrom
fix/472-clipboard-insecure-context

Conversation

@scttbnsn

@scttbnsn scttbnsn commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #472.

Click-to-copy did nothing (and logged a TypeError) on deployments served over plain HTTP, which is the common self-hosted LAN setup, because navigator.clipboard only exists in secure contexts. Three commits:

  • execCommand fallback β€” useClipboard now falls back to the legacy document.execCommand('copy') textarea technique when the Clipboard API is missing or rejects. The log viewer's Copy button goes through the same path, and when no copy mechanism works at all the UI shows an explicit "Copy failed" state instead of failing silently. The temp textarea teardown is wrapped in try/finally with a parentNode guard so a mid-copy DOM error can't leave it behind or skip focus restore.
  • Live tooltip updates β€” an open tooltip whose text changed (like the "Copied" confirmation) stayed stuck on the old text until you moved the mouse away and back, and the click itself hid the tooltip so the feedback never appeared. The tooltip directive now updates the shared tooltip element in place when its content changes, repositions it for the new text, and re-shows immediately if the pointer never left the anchor.
  • De-duplicated tooltips on CopyableTag β€” three call sites (the containers table digest-delta cell and two spots in the dashboard recent-updates widget) bound a second v-tooltip directly on <CopyableTag>, which falls through to the same root element as the component's own copy-state tooltip and clobbered its directive state. Those sites now pass their text through a new idleTooltip prop so one tooltip carries both the informative text and the copy feedback. Swept every CopyableTag usage in ui/src β€” no other double bindings.

Gate: full UI suite green at 100% coverage, build/typecheck/biome clean, e2e + playwright via pre-push hook. Manually QA'd on a LAN IP (insecure context) to exercise the fallback path.

πŸ› Fixed

  • Added a clipboard fallback using document.execCommand('copy') so click-to-copy works when navigator.clipboard is missing or rejects (e.g., insecure/plain HTTP contexts).
  • Made AppLogViewer’s toolbar copy button use the same copy helper and surface explicit failure UI (β€œCopy failed”) when no copy method succeeds.
  • Improved copy feedback timing: clears any pending copy-feedback reset timer before scheduling a new one to prevent rapid re-copy indicator glitches.

πŸ”§ Changed

  • useClipboard() now tracks both success (isCopied) and failure (isFailed) via copiedKey/failedKey, and copyToClipboard() returns Promise<boolean>.
  • Introduced exported writeToClipboard(text): Promise<boolean> that tries navigator.clipboard.writeText first, then falls back to the execCommand('copy') textarea path with hardened cleanup + focus restoration.
  • Tooltip directive now live-updates while open: when bound text changes it remeasures/repositions, and if the pointer is still over the anchor it re-shows immediately (bypassing the initial delay).
  • CopyableTag now supports an optional idleTooltip prop to prevent duplicate/staked tooltip bindings and preserve correct copy-state tooltip precedence.
  • Updated affected CopyableTag call sites to pass idleTooltip for digest/version displays.
  • Added i18n strings for sharedComponents.copyableTag.clickToCopy and sharedComponents.copyableTag.failed.

✨ Added

  • New/expanded tests for:
    • clipboard fallback success/failure, including missing navigator.clipboard and failing/throwing document.execCommand
    • DOM cleanup edge cases in the fallback path (append/select/throw scenarios)
    • rapid double-copy behavior and correct reset timing
    • tooltip directive dynamic update/re-show behavior
    • CopyableTag idleTooltip precedence and failure styling regression.

scttbnsn added 3 commits July 5, 2026 22:03
…e contexts (#472)

- πŸ› fix(ui): stop CopyableTag's failed-state color from being clobbered by parent style fallthrough β€” move the danger color onto an inner span so it survives Vue 3's parent-wins style merge at real call sites (ContainerFullPageTabContent, ContainerSideTabContent, ContainerFullPageOverviewTab, DashboardRecentUpdatesWidget)
- πŸ› fix(ui): harden useClipboard's execCommand fallback with try/finally so a throw during textarea append/select (e.g. a sandboxed iframe) can't leak the textarea or reject the copy promise instead of resolving false
- πŸ› fix(ui): give AppLogViewer's Copy button a real failed-copy state (reuses the CopyableTag "Copy failed" tooltip copy) instead of looking identical to idle when the write fails
- βœ… test(ui): add a real-mount CopyableTag spec covering the fallthrough regression (verified to fail pre-fix), success path, and execCommand fallback path; extend useClipboard and AppLogViewer specs for the new branches
…472)

- πŸ› the mousedown-hide + show-time-only text read meant state-driven
  tooltip text (like the copy button's "Copied"/"Copy failed"
  confirmations) never refreshed without a re-hover; now open tooltips
  live-update and reposition, and a content change while the pointer is
  still on the element re-shows immediately.
- βœ… test: directive coverage for live-update, post-click re-show,
  no-resurrection-on-unchanged-text, delay bypass.
πŸ› outer v-tooltip bindings on <CopyableTag> fell through to the same
root element as the component's own copy-state tooltip, clobbering
directive state at 3 sites (containers version cell digest-delta,
dashboard recent-updates widget x2); replaced with an idleTooltip prop
so one tooltip carries both the informative text and the copy feedback.
βœ… test: idleTooltip prop coverage + preserved digest-delta assertions.
@vercel

vercel Bot commented Jul 6, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
drydock-website Ready Ready Preview, Comment Jul 6, 2026 2:43am
drydockdemo-website Ready Ready Preview, Comment Jul 6, 2026 2:43am

@coderabbitai

coderabbitai Bot commented Jul 6, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. πŸŽ‰

ℹ️ Recent review info
βš™οΈ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: c639b4db-70a2-4166-8d9d-382285f0e088

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between b1c8b15 and 05c4e3e.

πŸ“’ Files selected for processing (3)
  • ui/src/components/AppLogViewer.vue
  • ui/tests/components/AppLogViewer.spec.ts
  • ui/tests/composables/useClipboard.spec.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • ui/src/components/AppLogViewer.vue
  • ui/tests/composables/useClipboard.spec.ts

πŸ“ Walkthrough

Walkthrough

Changes

Adds a legacy execCommand fallback and failure tracking to useClipboard, exposing writeToClipboard plus isFailed/failedKey. CopyableTag adds idleTooltip, failure styling, and updated tooltip messaging. AppLogViewer now uses the shared clipboard helper and shows copy success/failure states. The tooltip directive exports its binding types and refreshes visible tooltips on text changes. Views switch from v-tooltip to idle-tooltip. Tests were expanded for the composable, directive, and copy UI.

Sequence Diagram(s)

sequenceDiagram
  participant Component
  participant useClipboard
  participant writeToClipboard
  participant NavigatorClipboard
  participant execCommandFallback

  Component->>useClipboard: copyToClipboard(text, key)
  useClipboard->>writeToClipboard: writeToClipboard(text)
  writeToClipboard->>NavigatorClipboard: writeText(text)
  alt success
    NavigatorClipboard-->>writeToClipboard: resolved
  else unavailable or rejected
    writeToClipboard->>execCommandFallback: execCommand('copy')
    execCommandFallback-->>writeToClipboard: boolean success
  end
  writeToClipboard-->>useClipboard: boolean success
  useClipboard->>useClipboard: set copiedKey or failedKey
  useClipboard-->>Component: Promise<boolean>
Loading

Compact metadata

  • Type: Bug fix / UI behavior update
  • Scope: Clipboard handling, tooltip behavior, copyable UI
  • Estimated review effort: Medium-High

Related issues

  • #472: "Click to copy" doesn't work

Related PRs

  • None identified

Suggested labels

  • bug
  • ui
  • tests

Suggested reviewers

  • None specified

Poem
Copy now falls back, then shows the state,
fail or success within two seconds' gate.
Tooltips refresh as text changes by hand,
with idle text and danger color planned.

πŸš₯ Pre-merge checks | βœ… 2
βœ… Passed checks (2 passed)
Check name Status Explanation
Linked Issues check βœ… Passed Copy-to-copy now falls back in insecure contexts, reports success/failure, and preserves tooltip feedback, satisfying #472.
Out of Scope Changes check βœ… Passed No unrelated changes stand out; the tooltip and test updates support the copy-fix and tooltip-state objectives.
✨ Finishing Touches
πŸ“ Generate docstrings
  • Create stacked PR
  • Commit on current branch
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/472-clipboard-insecure-context

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
ui/tests/composables/useClipboard.spec.ts (1)

6-17: 🎯 Functional Correctness | 🟑 Minor | ⚑ Quick win

Await the reset copy before advancing fake timers. copyToClipboard('__reset__') is async, so vi.advanceTimersByTime(1500) runs before scheduleReset() registers the timeout. Make beforeEach async and await copyToClipboard('__reset__') so the shared clipboard state is cleared before each test.

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ui/tests/composables/useClipboard.spec.ts` around lines 6 - 17, The clipboard
state reset in beforeEach is racing the fake timers because
copyToClipboard('__reset__') is async, so the timeout may not be registered
before vi.advanceTimersByTime runs. Make the beforeEach callback async in
useClipboard.spec.ts, await the copyToClipboard('__reset__') call from
useClipboard() before advancing timers, and then clear writeTextMock so each
test starts from a fully reset shared state.
🧹 Nitpick comments (2)
ui/src/components/containers/ContainersGroupedViews.vue (1)

664-664: πŸ“ Maintainability & Code Quality | πŸ”΅ Trivial | πŸ’€ Low value

Hardcoded tooltip string bypasses i18n placeholders.

The digest-transition tooltip text is built as a raw JS template literal (`${c.currentTag} β€” ${...} β†’ ${...}`) rather than a locale entry with named placeholders (the convention used elsewhere, e.g. dataFilterBar.viewModeLabel). Not blocking since line 675 already does this, but worth aligning eventually for translatability.

πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ui/src/components/containers/ContainersGroupedViews.vue` at line 664, The
tooltip in CopyableTag for the container version tag is built with a hardcoded
template literal instead of using an i18n entry with named placeholders. Update
the tooltip construction in ContainersGroupedViews.vue to use the existing tt
translation helper with a locale key and placeholder values, following the same
pattern used by dataFilterBar.viewModeLabel, while keeping the digest values
from c.currentTag, c.currentDigest, and c.newDigest.
ui/src/components/CopyableTag.vue (1)

21-26: πŸ“ Maintainability & Code Quality | πŸ”΅ Trivial | πŸ’€ Low value

Extract tooltip ternary to a computed.

The nested ternary on line 24 mixes three states (failed/copied/idle) inline in the template. A computed (e.g. tooltipContent) would be easier to test and read.

♻️ Proposed refactor
-const { copyToClipboard, isCopied, isFailed } = useClipboard();
+const { copyToClipboard, isCopied, isFailed } = useClipboard();
+
+const tooltipContent = computed<BindingValue>(() => {
+  if (isFailed(props.tag)) return t('sharedComponents.copyableTag.failed');
+  if (isCopied(props.tag)) return t('sharedComponents.copyableTag.copied');
+  return props.idleTooltip ?? t('sharedComponents.copyableTag.clickToCopy');
+});
-    v-tooltip.top="isFailed(props.tag) ? t('sharedComponents.copyableTag.failed') : isCopied(props.tag) ? t('sharedComponents.copyableTag.copied') : (props.idleTooltip ?? t('sharedComponents.copyableTag.clickToCopy'))"
+    v-tooltip.top="tooltipContent"
πŸ€– Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@ui/src/components/CopyableTag.vue` around lines 21 - 26, Refactor the nested
tooltip ternary in CopyableTag.vue into a computed value named something like
tooltipContent so the template stays readable and easier to test. Move the
failed/copied/idle selection logic currently embedded in the v-tooltip.top
binding into that computed, using the existing isFailed, isCopied, and
props.idleTooltip logic, then bind the template to the computed result instead
of inline branching.
πŸ€– Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@ui/src/components/AppLogViewer.vue`:
- Around line 396-407: The copy feedback reset logic in AppLogViewer’s clipboard
handler is racing because each click schedules a new timeout without cancelling
the previous one. Update the same block that sets copySuccess and copyFailed to
track the pending reset timer, clear any existing timer before scheduling a new
one, and reuse the timer cleanup pattern already used in useClipboard.ts’s
scheduleReset so rapid same-outcome clicks keep the indicator visible for the
full duration.

---

Outside diff comments:
In `@ui/tests/composables/useClipboard.spec.ts`:
- Around line 6-17: The clipboard state reset in beforeEach is racing the fake
timers because copyToClipboard('__reset__') is async, so the timeout may not be
registered before vi.advanceTimersByTime runs. Make the beforeEach callback
async in useClipboard.spec.ts, await the copyToClipboard('__reset__') call from
useClipboard() before advancing timers, and then clear writeTextMock so each
test starts from a fully reset shared state.

---

Nitpick comments:
In `@ui/src/components/containers/ContainersGroupedViews.vue`:
- Line 664: The tooltip in CopyableTag for the container version tag is built
with a hardcoded template literal instead of using an i18n entry with named
placeholders. Update the tooltip construction in ContainersGroupedViews.vue to
use the existing tt translation helper with a locale key and placeholder values,
following the same pattern used by dataFilterBar.viewModeLabel, while keeping
the digest values from c.currentTag, c.currentDigest, and c.newDigest.

In `@ui/src/components/CopyableTag.vue`:
- Around line 21-26: Refactor the nested tooltip ternary in CopyableTag.vue into
a computed value named something like tooltipContent so the template stays
readable and easier to test. Move the failed/copied/idle selection logic
currently embedded in the v-tooltip.top binding into that computed, using the
existing isFailed, isCopied, and props.idleTooltip logic, then bind the template
to the computed result instead of inline branching.
πŸͺ„ Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
βš™οΈ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 75e47d80-aa60-4d16-8f3c-651f70c4688f

πŸ“₯ Commits

Reviewing files that changed from the base of the PR and between bec684e and b1c8b15.

β›” Files ignored due to path filters (1)
  • CHANGELOG.md is excluded by !CHANGELOG.md
πŸ“’ Files selected for processing (11)
  • ui/src/components/AppLogViewer.vue
  • ui/src/components/CopyableTag.vue
  • ui/src/components/containers/ContainersGroupedViews.vue
  • ui/src/composables/useClipboard.ts
  • ui/src/directives/tooltip.ts
  • ui/src/locales/en/sharedComponents.json
  • ui/src/views/dashboard/components/DashboardRecentUpdatesWidget.vue
  • ui/tests/components/AppLogViewer.spec.ts
  • ui/tests/components/CopyableTag.spec.ts
  • ui/tests/composables/useClipboard.spec.ts
  • ui/tests/directives/tooltip.spec.ts

Comment thread ui/src/components/AppLogViewer.vue Resolved
…472)

- πŸ› fix: track a single copy-feedback reset timer in AppLogViewer's copyLogs, clearing any pending timer before scheduling a new one, so a rapid second copy click no longer lets the first click's timer clear the indicator early
- βœ… test: cover the rapid-double-copy case with fake timers in AppLogViewer.spec.ts
- βœ… test: await the async clipboard reset before advancing fake timers in useClipboard.spec.ts's beforeEach
@scttbnsn

scttbnsn commented Jul 6, 2026

Copy link
Copy Markdown
Contributor Author

Fixed the reset-timer race in AppLogViewer and the un-awaited clipboard reset in the spec (05c4e3e). Skipping the i18n nitpick on the digest tooltip: it's the same raw-literal pattern this view already uses (line 675 and friends), and the UI literal sweep is queued with the v1.6 i18n gate work rather than piecemeal here.

@biggest-littlest biggest-littlest left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. execCommand fallback is properly guarded with try/finally, tooltip live-update covers the click path, and the double-binding cleanup closes the loop.

@ALARGECOMPANY ALARGECOMPANY left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving β€” full gate green at 100% coverage, QA'd on an insecure LAN context.

@scttbnsn
scttbnsn merged commit 41bcf97 into main Jul 6, 2026
24 checks passed
@scttbnsn
scttbnsn deleted the fix/472-clipboard-insecure-context branch July 6, 2026 03:01

This branch was successfully deployed

2 active deployments
Preview – drydock-website β€” 05c4e3e3 Deployed Jul 6, 2026 by vercel[bot]
Preview – drydockdemo-website β€” 05c4e3e3 Deployed Jul 6, 2026 by vercel[bot]
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.

"Click to copy" doesn't work

3 participants