fix: copy current session share URL#2324
Conversation
|
@AjTheSpidey is attempting to deploy a commit to the HyperDX Team on Vercel. A member of the Team first needs to authorize it. |
🦋 Changeset detectedLatest commit: 9cad879 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
Deep Review✅ No critical issues found. The change moves 🟡 P2 — recommended
🔵 P3 nitpicks (3)
Reviewers (9): correctness, testing, maintainability, project-standards, kieran-typescript, julik-frontend-races, reliability, agent-native, learnings-researcher. Testing gaps: loading-state UI prop transition is not pinned by any assertion; the duplicate-click guard reset on the rejection branch is only indirectly covered. |
130d313 to
b1fe133
Compare
016f943 to
a62b13e
Compare
a62b13e to
be021e5
Compare
karl-power
left a comment
There was a problem hiding this comment.
Thanks for the contribution! I have a few suggestions to simplify the fix.
| useEffect(() => { | ||
| // React 18 StrictMode runs cleanup before re-mounting this effect. | ||
| isMountedRef.current = true; | ||
|
|
||
| return () => { | ||
| isMountedRef.current = false; | ||
| }; | ||
| }, []); |
There was a problem hiding this comment.
I don't think we need this ref, I'm not sure what it's guarding against? The state update and call to notifications are ok without it
| try { | ||
| copied = await copyTextToClipboard(window.location.href); | ||
| } catch { | ||
| copied = false; |
There was a problem hiding this comment.
copyTextToClipboard already wraps both the navigator.clipboard.writeText path and the execCommand fallback in their own try/catch, so I don't think this is needed here.
| const handleShareSession = useCallback(async () => { | ||
| if (isSharingSessionRef.current) { | ||
| return; | ||
| } | ||
|
|
||
| isSharingSessionRef.current = true; | ||
| setIsSharingSession(true); | ||
| let copied = false; | ||
| try { | ||
| copied = await copyTextToClipboard(window.location.href); | ||
| } catch { | ||
| copied = false; | ||
| } finally { | ||
| isSharingSessionRef.current = false; | ||
| if (isMountedRef.current) { | ||
| setIsSharingSession(false); | ||
| } | ||
| } | ||
| if (!isMountedRef.current) { | ||
| return; | ||
| } | ||
| notifications.show({ | ||
| color: copied ? 'green' : 'red', | ||
| message: copied ? 'Copied link to clipboard' : CLIPBOARD_ERROR_MESSAGE, | ||
| }); | ||
| }, []); |
There was a problem hiding this comment.
This can be simplified to:
const handleShareSession = useCallback(async () => {
if (isSharingSessionRef.current) return;
isSharingSessionRef.current = true;
setIsSharingSession(true);
const copied = await copyTextToClipboard(window.location.href);
isSharingSessionRef.current = false;
setIsSharingSession(false);
notifications.show({
color: copied ? 'green' : 'red',
message: copied ? 'Copied link to clipboard' : CLIPBOARD_ERROR_MESSAGE,
});
}, []);|
I believe this is fixed with the (slightly) earlier PR #2318 |
Fixes #2313.
Found the share button could copy an older URL if the side panel rendered before the session params finished landing in the address bar.
Changed it so the button reads
window.location.hrefwhen you click it, not during render. I also kept the success/error toast behavior, blocked duplicate clicks while the copy is running, and added tests around the fresh URL + retry cases.Checked locally: