Skip to content

fix(signup): let useClipboardCopy own the Copy link timer - #1111

Open
dafeiyupola wants to merge 2 commits into
richshaw:mainfrom
dafeiyupola:fix/copy-link-uses-the-hook
Open

dafeiyupola wants to merge 2 commits into
richshaw:mainfrom
dafeiyupola:fix/copy-link-uses-the-hook

Conversation

@dafeiyupola

@dafeiyupola dafeiyupola commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

What

The success panel keeps two hand-written copies of what useClipboardCopy already does: shareCopied for "Save your link" and copyResult for "Copy link", each with a bare setTimeout(…, 2000) and no timer id. Copy, then copy again 1.2 s later, and the first timer clears the label 0.8 s after the second copy instead of 2 s.

Both are now the hook, as the issue outlines. Only one of the two buttons is on screen at a time, so one hook covers both.

-  const [shareCopied, setShareCopied] = useState(false);
-  const [copyResult, setCopyResult] = useState<'copied' | 'failed' | null>(null);
+  const linkCopy = useClipboardCopy();
+  const [copyFailed, setCopyFailed] = useState(false);

handleCopy is setCopyFailed(!(await linkCopy.copy(success.editUrl))), the share fallback awaits the same copy, and the status region reads from copyFailed / linkCopied. handleClose resets copyFailed only — the hook's copied can't be cleared from outside, and the panel is gone by then anyway.

Test

One new case in commit-dialog.test.tsx: copy, wait 1.2 s, copy again, then assert the label is still "Link copied" 1 s later — past the point where the first timer fired — and that it goes back to "Copy link" within 2 s of the second copy.

Checked both directions:

with the change     71 passed
against main's file  × keeps Link copied for 2 seconds after the second copy, not the first

Verification

tsc --noEmit     clean
eslint           clean (both files)
vitest run src/app/s/[slug]/commit-dialog.test.tsx   71 passed

I did not run the other 2,000-odd tests in the repo, only this file plus the type and lint checks — this touches one dialog's state, but saying "the suite passes" when I ran one file would be wrong.

Fixes #1087


Rebased twice while this sat; main moved under it both times, which is fair for a repository this busy. The count above is from the current head (df30e23b), on main as of 7649fbc5.

@richshaw richshaw left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for this.

Two things need fixing before this can go in:

  1. Formatting. CI fails pnpm format:check on commit-dialog.tsx because the <p role="status" …> tag should fit on one line. Running pnpm format fixes it. CI stopped at that step, so the tests, build and size checks haven't run yet.
  2. The German line in KEEP_IT_PRIVATE. The PR deletes de: 'gib den Link nicht weiter', from commit-dialog.test.tsx. That line has nothing to do with this fix, and deleting it breaks the "say to keep the link private in de" test. The file comes out at 68 passed and 1 failed. Please put the line back.

One smaller fix that would be good to include:

  1. Closing the dialog no longer clears "Link copied". handleClose used to reset both copy states, but now the hook's copied stays true for up to 2 seconds. The dialog stays mounted after Done, so someone who reopens it and signs up again within those 2 seconds sees "Link copied" on the new panel. Adding a reset() to the hook and calling it from handleClose would fix this.

Optional:

  • The new test waits on the real clock, which takes over 3 seconds. Fake timers would make it instant, and useClipboardCopy.test.ts already tests this with fake timers.
  • Nothing tests the "Save your link" fallback, where someone gave an email and the browser has no share sheet. A short test there would cover the new shared linkCopied logic.

@dafeiyupola
dafeiyupola force-pushed the fix/copy-link-uses-the-hook branch 3 times, most recently from e45105d to df30e23 Compare November 25, 2026 04:13
@dafeiyupola

Copy link
Copy Markdown
Contributor Author

Heads-up before this shows up as a red check: one test in commit-dialog.test.tsx already fails on main without this branch.

× says sign-ups have closed in plain words, not the server text
  Expected: "Reload the page to see what's still open."   (straight apostrophe)
  Received: "Reload the page to see what’s still open."   (curly)
    at commit-dialog.test.tsx:425

I checked it both ways so it is not my change: the same assertion fails on a pristine checkout of main (3ace3e51 touched that file yesterday). The copy now uses ’ and this one expectation still uses '.

Current state of this branch against main as of today: 70 passed, that one pre-existing failure. My own new test passes, and it is not in the failure's area — but I would rather point at the cause than let a red run be blamed on the clipboard change.

@dafeiyupola
dafeiyupola force-pushed the fix/copy-link-uses-the-hook branch from df30e23 to 4e137f4 Compare November 26, 2026 14:00
@richshaw

Copy link
Copy Markdown
Owner

Thanks for the update. The German line is back, and the end-to-end tests pass.

Two things from the review still need doing:

  1. Formatting. CI still fails pnpm format:check on commit-dialog.tsx: the <p role="status" …> tag should fit on one line. Running pnpm format fixes it. CI stops at that step, so the unit tests, type check and size checks haven't run yet.
  2. Clear "Link copied" when the dialog closes. handleClose resets copyFailed but not the hook's copied. The hook lives in CommitDialog, which stays mounted after Done, so someone who reopens it and signs up again within 2 seconds sees "Link copied" on the new panel. Please add a reset() to useClipboardCopy that clears the timer and sets copied to false, and call it from handleClose.

I checked the test you said already fails on main: it doesn't. 3ace3e5 made every English apostrophe straight, so the message in en.json and the test both use what's. I ran commit-dialog.test.tsx on this branch and all 71 tests pass, that one included.

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.

The sign-up dialog copies its link by hand twice instead of using useClipboardCopy, and a second copy's "Link copied" vanishes early

2 participants