fix(share): copy absolute world and tool links - #6641
Merged
Conversation
`webappUrl` is a bare `/` on the webapp (it is absolute only in the extension), so the world and tool share buttons put `/world/<user>` and `/tools/<slug>` on the clipboard, which is a dead link once pasted. Add `getAbsoluteWebappUrl(path)` to lib/links. It resolves the path against `location.origin`, the approach `agentShareLink` already took, and leaves an absolute `webappUrl` untouched. Use it for the world share, the tool page share, `agentShareLink`, and the source share fallback, which copied `/` when a source had no permalink and threw in `addLogQueryParams` once a cid was attached. The world and tool links now carry `share_world` and `share_tool` campaign ids through `useShareOrCopyLink`, like the other share buttons, so they get the referral `userid`/`cid` params and the shortener. The join page maps both to the generic referral screen.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
webappUrlisprocess.env.NEXT_PUBLIC_WEBAPP_URL, which is a bare/on the webapp and absolute only in the extension. The world share button and the tool page share button built their links as${webappUrl}world/...and${webappUrl}tools/..., so the clipboard got/world/<user>and/tools/<slug>, which is a dead link once pasted.Fix
getAbsoluteWebappUrl(path)inpackages/shared/src/lib/links.ts. It resolves the path againstlocation.originand leaves an absolutewebappUrl(the extension) untouched. This is the approachagentShareLinkalready used and the one feat(snapshot): snapshot an expanded highlight on Happening Now #6570 adds for Happening Now, pulled into one helper.WorldShare, the tool page share, andagentShareLink(which no longer carries its own copy).useShareOrCopyLink/useCopyLink/navigator.clipboardcall sites: the rest copy backend permalinks,location.href, or origin-built URLs. The one other case wasuseSourceMenuProps, which fell back to a barewebappUrlwhen a source had no permalink. That copied/and threw inaddLogQueryParamsonce theshare_sourcecid was attached, so it now uses the helper too.cidthroughuseShareOrCopyLink(newshare_worldandshare_toolcampaign keys), like the other share buttons, so they get the referraluserid/cidparams and the shortener.pages/joinmaps both to the generic referral screen, anduseReferralConfigalready falls back to the default config.Relation to #6570
#6570 (still open) adds
getHighlightsShareUrl()with the same origin logic. Whichever PR merges second should switch it togetAbsoluteWebappUrl('highlights'). TheReferralCampaignKeyenum and the join page map both gain entries in both PRs, so expect a trivial conflict there.Tests
With
webappUrlat/(the webapp and shared jest setups):WorldShare.spec.tsx: the old assertions expected the relative/world/idoand have been changed to expect the absolute link. There is also a cid check, plus a test that goes through the real share pipeline and asserts the clipboard getshttp://localhost/world/ido?userid=...&cid=share_world.ToolPage.spec.tsx: clicking Share writeshttp://localhost/tools/docker?userid=...&cid=share_toolto the clipboard.links.spec.ts: the helper resolves against the origin, returns the home page when called with no path, and passes an absolutewebappUrlthrough.Checks run:
node ./scripts/typecheck-strict-changed.js, eslint on the changed files, the affected shared specs, the full webapp jest suite (86 suites, 692 tests), and the full webapp tsc (no errors in changed files).Preview domain
https://fix-absolute-share-links.preview.app.daily.dev