Skip to content

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

Description

@dewly-justice

Summary

On the Client Sessions page, clicking a session card opens the side panel and updates the URL with sid, sfrom, and sto query params. However, clicking Share Session immediately after copies the previous URL (without those params). Reloading the page and clicking Share Session again produces the correct URL.

Steps to reproduce

  1. Go to the /sessions page (e.g. /sessions?sessionSource=<SOURCE_ID>&from=<FROM>&to=<TO>&where=&whereLanguage=lucene).
  2. Click any session card — the URL bar updates to include &sid=<SID>&sfrom=<SFROM>&sto=<STO>.
  3. Click Share Session.
  4. Paste the clipboard contents.

Expected

/sessions?sessionSource=<SOURCE_ID>&from=<FROM>&to=<TO>&where=&whereLanguage=lucene&sid=<SID>&sfrom=<SFROM>&sto=<STO>

Actual

/sessions?sessionSource=<SOURCE_ID>&from=<FROM>&to=<TO>&where=&whereLanguage=lucene

After a page reload, step 3 produces the expected URL.

Root cause

In packages/app/src/SessionSidePanel.tsx (around line 128):

<CopyToClipboard text={window.location.href} ...>
  • setSelectedSession in SessionsPage.tsx:322 calls nuqs' setSelectedSessionQuery, which updates the React state synchronously but flushes window.history asynchronously (batched via startTransition + throttleMs).
  • SessionSidePanel renders immediately when selectedSession != null, so window.location.href is read before nuqs has flushed sid/sfrom/sto into the URL.
  • CopyToClipboard captures that stale value into its text prop. The panel does not re-render after the URL flush, so the stale value persists on click.
  • On reload, the URL already contains sid/sfrom/sto, so the first render captures the correct URL.

Proposed fix

Either:

  1. Read URL at click time using copyTextToClipboard from packages/app/src/utils/clipboard.ts inside an onClick handler — by the time the user clicks Share, nuqs has flushed.
  2. Build the URL from props (sessionId, dateRange) with useMemo — deterministic, no dependency on URL flush timing.

Option 1 is preferred — simpler, reuses existing clipboard util (which also handles non-HTTPS fallback), and is future-proof against new params.

Affected file

packages/app/src/SessionSidePanel.tsx:128-145

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions