Skip to content

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

Merged
kodiakhq[bot] merged 4 commits into
hyperdxio:mainfrom
dewly-justice:claude/fix-share-session-stale-url
May 28, 2026
Merged

fix(app): copy correct session URL on first Share Session click#2318
kodiakhq[bot] merged 4 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: eeaa869

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 moves URL capture from render time to click time, the new tests directly exercise that contract, and the dependency is preserved (still used elsewhere). Remaining notes below are advisory.

🔵 P3 nitpicks (3)
  • packages/app/src/SessionSidePanel.tsx:137 — Reading window.location.href at click time narrows but does not close the nuqs throttle window (default ~50ms), so a click landing within that window after panel open can still read a stale URL.
    • Fix: Construct the share URL from the same React state nuqs reads (sessionId + sfrom/sto from dateRange) rather than from window.location.href.
    • julik-frontend-races
  • packages/app/src/SessionSidePanel.tsx:136 — Button has no re-entry guard while the awaited copy is in flight; rapid double-click fires two copyTextToClipboard calls and two notifications. Pre-existing in spirit (the prior CopyToClipboard wrapper was also unguarded), but the await-based flow makes it slightly more observable.
    • Fix: Disable the button or set a local isCopying ref while the promise is pending.
    • julik-frontend-races, correctness
  • packages/app/src/__tests__/SessionSidePanel.test.tsx:52 — Three as any casts on prop fixtures (traceSource, sessionSource, session) deviate from the documented "avoid as casts" code-style guidance, though the pattern is consistent with other test files in packages/app/src/__tests__/.
    • Fix: Narrow the fixtures with satisfies Partial<TTraceSource>/Partial<TSessionSource> or pull in a typed fixture helper.

Reviewers (6): correctness, testing, maintainability, kieran-typescript, julik-frontend-races, project-standards.

Testing gaps:

  • No test exercises a click landing inside the nuqs throttle window immediately after panel open — the exact race scenario the PR claims to fix is only approximated by manually mutating window.location between render and click.
  • No test covers rapid double-click behavior on Share Session.
  • Error-path test asserts that the red notification fires but does not explicitly assert the green notification did not (expect(mockedShow).not.toHaveBeenCalledWith({color: 'green', ...})).

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.
Copy link
Copy Markdown
Contributor

@pulpdrew pulpdrew left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the fix

@kodiakhq kodiakhq Bot merged commit b24cb88 into hyperdxio:main May 28, 2026
16 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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)

2 participants