Skip to content

feat: share an item from the meta row - #237

Merged
therealsama merged 1 commit into
mainfrom
feat/native-share-sheet
Oct 4, 2026
Merged

therealsama merged 1 commit into
mainfrom
feat/native-share-sheet

Conversation

@therealsama

@therealsama therealsama commented Aug 29, 2026 •

Copy link
Copy Markdown
Collaborator

Why

navigator.share was never wired up, so the only way to lift a link out of the
swipe feed was the iOS long-press callout — and that hands over the article or a
third-party URL, never this app's own link to the item. There was no in-app
route to that link on any platform.

What

  • A share control at the end of ItemArticle's meta row. ItemArticle is
    mounted by both ItemDetail (desktop) and FullScreenItem (mobile swipe), so
    one insertion covers both surfaces.
  • It shares this app's own link to the item, built from location.origin and
    BASE_URL so preview deploys and local runs share their own URL.
  • Where there is no share sheet — desktop Firefox has none — the URL goes to the
    clipboard. The share sheet is its own confirmation, but a copy is silent, so
    only that path reports back, via the label plus a live region.
  • Where neither route exists the control does not render, rather than presenting
    a button that cannot act.
  • The button keeps a fixed accessible name, so it does not appear to rename
    itself two seconds after being pressed.
  • A press while an earlier share is still pending also falls through to the
    clipboard. Browsers have left a dismissed share pending for good, and the
    rejection (InvalidStateError) comes before the click's activation is used,
    so the copy still works and the button never goes dead.
  • The long-press callout stays on the headline and prose links. The share
    control carries the item's own link, not the article the headline points to or
    the third-party URLs in .comment-content (the story body and every comment
    body), so on iOS the callout is still the only route to those.

The capability matrix lives in src/utils/share.ts rather than the component,
since it is most of the complexity and is worth testing without rendering.
Notably, a dismissed share sheet arrives as an AbortError, so it has to be told
apart from a real fault before the clipboard fallback kicks in — otherwise
backing out of the sheet would silently copy instead.

Known limitations

  • If a share fails after it has used the click's activation, the clipboard
    fallback can be refused in Firefox and Safari, which require activation to
    write. The button then stays silent rather than claim a copy.
  • "No share targets available" arrives as the same AbortError as a dismissal,
    so on such a system the button does nothing.
  • Shared /#/item/… links unfurl as the generic HackerTok card, since hash
    routes aren't crawlable. Recipients see the headline only where the target
    uses title.

Test plan

  • src/utils/share.test.ts — the full capability matrix: sheet preferred,
    dismissal distinguished from failure, fallthrough to clipboard on other errors,
    clipboard-only platforms, a refused copy reported as unavailable rather than
    claimed as success.
  • src/components/ShareButton.test.tsx — hidden without capabilities, stable
    accessible name, payload, a later press still copying when an earlier share
    never settles, silence after a successful share, visible and announced
    confirmation on copy, revert after 2s, no timer left past unmount.
  • e2e/share.spec.ts — both APIs installed as recorders before boot (the sheet
    is OS chrome Playwright cannot see, and clipboard access needs per-browser
    permission grants), asserting the exact shared URL on the desktop detail page
    and inside the swipe viewer, the copy path with its announcement, and that no
    control renders on a platform with neither route. The swipe test runs with a
    narrow viewport and hasTouch, so the viewer mounts in the desktop projects
    too. 16 tests across all four projects.

Commands run locally:

npm run typecheck
npx eslint src/utils/share.ts src/utils/share.test.ts src/components/ShareButton.tsx src/components/ShareButton.test.tsx src/components/ItemArticle.tsx e2e/share.spec.ts
npx vitest run src/utils/share.test.ts src/components/ShareButton.test.tsx
npx playwright test e2e/share.spec.ts e2e/touch-feel.spec.ts e2e/accessibility.spec.ts

The full lint, unit and e2e suites run in CI.

@therealsama
therealsama requested a review from kplachkov as a code owner August 29, 2026 10:57
@therealsama
therealsama force-pushed the feat/mobile-touch-feel branch from 5b0eb92 to eb15585 Compare August 29, 2026 12:16
@therealsama
therealsama force-pushed the feat/native-share-sheet branch from a25b1ea to 5c97d92 Compare August 29, 2026 12:19
@therealsama
therealsama force-pushed the feat/mobile-touch-feel branch from ebfd1bc to f7d80bb Compare August 29, 2026 13:13
@therealsama
therealsama force-pushed the feat/native-share-sheet branch from 5c97d92 to 3fca45e Compare August 29, 2026 13:17
@therealsama
therealsama force-pushed the feat/mobile-touch-feel branch from f7d80bb to c52938b Compare August 29, 2026 13:27
@therealsama
therealsama force-pushed the feat/native-share-sheet branch from 3fca45e to 1a47010 Compare August 29, 2026 13:27
@therealsama
therealsama force-pushed the feat/mobile-touch-feel branch from c52938b to 5c1ad50 Compare August 29, 2026 13:45
@therealsama
therealsama force-pushed the feat/native-share-sheet branch from 1a47010 to 67dd732 Compare August 29, 2026 13:47
@therealsama
therealsama force-pushed the feat/mobile-touch-feel branch from 5c1ad50 to a160b4a Compare August 29, 2026 14:05
@therealsama
therealsama force-pushed the feat/native-share-sheet branch from 67dd732 to a50ba63 Compare August 29, 2026 14:05
@therealsama
therealsama force-pushed the feat/mobile-touch-feel branch from a160b4a to b04e134 Compare August 29, 2026 18:11
@therealsama
therealsama force-pushed the feat/native-share-sheet branch from a50ba63 to 2ef5a32 Compare August 29, 2026 18:12
@therealsama
therealsama force-pushed the feat/mobile-touch-feel branch from b04e134 to bb8e7fe Compare August 29, 2026 20:03
@therealsama
therealsama force-pushed the feat/native-share-sheet branch from 2ef5a32 to a20ba97 Compare August 29, 2026 20:13
@therealsama
therealsama force-pushed the feat/mobile-touch-feel branch from bb8e7fe to 7026195 Compare September 1, 2026 23:12
@therealsama
therealsama force-pushed the feat/native-share-sheet branch from a20ba97 to 84d014b Compare September 1, 2026 23:13
@therealsama
therealsama force-pushed the feat/mobile-touch-feel branch from 7026195 to f37041f Compare September 2, 2026 04:22
@therealsama
therealsama force-pushed the feat/native-share-sheet branch from 84d014b to ad78bb4 Compare September 2, 2026 04:22
@therealsama
therealsama force-pushed the feat/mobile-touch-feel branch from f37041f to 4d30236 Compare September 2, 2026 04:45
@therealsama
therealsama force-pushed the feat/native-share-sheet branch from ad78bb4 to 8a26914 Compare September 2, 2026 04:47
Base automatically changed from feat/mobile-touch-feel to main September 2, 2026 07:32
@therealsama
therealsama force-pushed the feat/native-share-sheet branch from 8a26914 to ae4e063 Compare September 6, 2026 13:19
@therealsama
therealsama force-pushed the feat/native-share-sheet branch 2 times, most recently from 7129006 to 3d5ae33 Compare October 3, 2026 23:47
`navigator.share` was unused, so the only way to lift a link out of the swipe
feed was the iOS long-press callout, which hands over the article or a
third-party URL and never this app's own link to the item.

A share control in ItemArticle's meta row covers both the desktop detail page
and the mobile panel from one insertion. Where there is no share sheet (desktop
Firefox), the URL goes to the clipboard instead, and because a silent copy has
no system confirmation the label reports it. A press while an earlier share is
still pending falls through to the clipboard too, since browsers have left a
dismissed share pending for good.

The long-press callout stays on the headline and prose links: the share control
carries the item's own link, not the article or the third-party URLs in the
text.
@therealsama
therealsama force-pushed the feat/native-share-sheet branch from 51bd9b0 to 78e5fd2 Compare October 3, 2026 23:52
@therealsama
therealsama enabled auto-merge October 4, 2026 02:08
@therealsama
therealsama merged commit 8c255ed into main Oct 4, 2026
4 checks passed
@therealsama
therealsama deleted the feat/native-share-sheet branch October 4, 2026 02:12
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.

2 participants