Skip to content

fix(app): copy correct session URL on first Share Session click#2318

Open
dewly-justice wants to merge 2 commits into
hyperdxio:mainfrom
dewly-justice:claude/fix-share-session-stale-url
Open

fix(app): copy correct session URL on first Share Session click#2318
dewly-justice wants to merge 2 commits into
hyperdxio:mainfrom
dewly-justice:claude/fix-share-session-stale-url

Conversation

@dewly-justice
Copy link
Copy Markdown

Summary

Fixes #2313.

On the Client Sessions page, clicking Share Session immediately after opening a session copied the previous URL (without sid/sfrom/sto). A reload was required for the button to copy the correct link.

Root cause: CopyToClipboard captured window.location.href into its text prop at render time. nuqs (setSelectedSessionQuery in SessionsPage.tsx:322) updates React state synchronously but flushes window.history asynchronously (batched via startTransition + throttleMs). SessionSidePanel rendered before the flush and froze the stale URL into the prop. After reload the URL already contained the params on initial render, which is why the bug "disappeared."

Fix: Replace CopyToClipboard with a plain onClick handler that reads window.location.href at click time — by then nuqs has flushed. Reuse the shared copyTextToClipboard util from packages/app/src/utils/clipboard.ts so we get the non-HTTPS <textarea> fallback and explicit error reporting for free.

Screenshots or video

Non-visual behavioral fix; no UI changes.

Before After
First click after opening a session copies URL without sid/sfrom/sto First click copies the full session URL

How to test on Vercel preview

Preview routes: /sessions

Steps:

  1. Open /sessions and ensure at least one session card is visible (use the demo data).
  2. Click any session card to open the side panel. The URL bar should update to include &sid=...&sfrom=...&sto=....
  3. Click Share Session in the side panel header.
  4. Paste the clipboard contents into the address bar or a text field.
  5. Verify the pasted URL contains sid, sfrom, and sto query params on the first click (no reload needed).

References

CopyToClipboard captured window.location.href into its text prop at
render time, but nuqs flushes sid/sfrom/sto into the URL asynchronously
(after startTransition + throttleMs). The panel rendered before the
flush and froze the stale URL, so the first click copied a link without
the session params. A reload "fixed" it only because the URL already
contained the params on initial render.

Replace CopyToClipboard with an onClick handler that reads
window.location.href at click time (after nuqs has flushed) and uses
the shared copyTextToClipboard util for the non-HTTPS textarea fallback
and error reporting.

Fixes hyperdxio#2313
@vercel
Copy link
Copy Markdown

vercel Bot commented May 20, 2026

@dewly-justice is attempting to deploy a commit to the HyperDX Team on Vercel.

A member of the Team first needs to authorize it.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 20, 2026

🦋 Changeset detected

Latest commit: f9128b0

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@hyperdx/app Patch
@hyperdx/api Patch
@hyperdx/otel-collector Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@dewly-justice dewly-justice marked this pull request as ready for review May 20, 2026 15:48
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 20, 2026

Deep Review

✅ No critical issues found. The fix correctly resolves the render-time URL capture by reading window.location.href inside the click handler, and the new test in packages/app/src/__tests__/SessionSidePanel.test.tsx:78 mutates window.location post-mount and pins that the click-time URL — including sid/sfrom/sto — is what gets copied. The failure branch is also covered, asserting the red CLIPBOARD_ERROR_MESSAGE toast fires when copyTextToClipboard resolves false. The prior deep-review's P2 testing gap is resolved.

🔵 P3 nitpicks (1)
  • packages/app/src/SessionSidePanel.tsx:131-149 — The Mantine Button is not disabled during the in-flight await copyTextToClipboard(...), so a rapid double-click now stacks two clipboard writes and two notifications.show toasts; the prior CopyToClipboard wrapper only fired a single toast per onCopy, so this is a marginal UX regression introduced by the rewrite.
    • Fix: Track a pending-copy ref, early-return when it is set, and clear it in a finally block around the await.

Reviewers (9): correctness, testing, maintainability, project-standards, agent-native, learnings, julik-frontend-races, kieran-typescript, previous-comments.

Address PR hyperdxio#2318 review comments:
- Add an RTL test that mutates window.location after mount and asserts
  copyTextToClipboard receives the post-mutation URL, plus a failure-branch
  test for the red CLIPBOARD_ERROR_MESSAGE toast.
- Add a changeset for @hyperdx/app.
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.

Share Session button copies stale URL on first click (missing sid/sfrom/sto)

1 participant