Skip to content

feat(widget): make memory-mode routing linkable where it matters - #142

Merged
Ardnived merged 4 commits into
mainfrom
feat/linkable-memory-mode
Aug 11, 2026
Merged

Ardnived merged 4 commits into
mainfrom
feat/linkable-memory-mode

Conversation

@Ardnived

@Ardnived Ardnived commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

Summary

  • On a host page whose anchor the widget declined to take (#respond, #comment-123 — routine on WordPress), fix(widget): survive foreign hashes and harden the mount path #92 mounts a MemoryRouter and never writes the URL. ShareView, the registration confirmation and the .ics export were all still falling back to window.location.href, which there is the host page's URL — it names their comment form, not the meditation. All three now offer no URL rather than a wrong one.
  • WidgetMode gains a linkable axis (default true), derived from the single mountRoute decision in Widget.tsx and threaded through App. Views ask instead of inferring.
  • One pure helper, shareableUrl (src/lib/url.ts), answers the question for every surface, so the share block and the calendar entry can't disagree about what an event's link is.

The judgement, since the ticket asked for it

The canonical wins in every mode — that is a preference, not a fallback order. event.webUrl is the event's page on the main site: indexable, unfurls with a title/description/image, and outlives the widget session that produced it. A widget URL is none of those even where it works. #105's add-to-calendar and #106's canonicals already lean on it; this makes the rule explicit and shared.

When there is no canonical, the address bar is a second-rate stand-in even where it is correct. Worth stating plainly, because it is the argument against investing in making memory mode produce a widget URL: ShareView renders at <event-path>/share and RegistrationView at <event-path>/register, so the fallback shares the drawer you are standing in, and the .ics URL: line points at the registration form. Pre-existing, out of scope here, and noted below as the follow-up worth having.

So the honest answer with no canonical and no route in the URL is nothing. Not a degraded share block: CopyField, navigator.share and every react-share target each require a URL, and the only string in reach belongs to somebody else. ShareContent.url therefore stays required — a share block is a URL plus ways to send it — while RegistrationForm.eventUrl becomes optional, because the confirmation screen is a screen with an optional block on it. Each caller then decides what to show instead: ShareView says so, the confirmation just drops the block.

Rejected: constructing origin + pathname + '#!' + route in memory mode. It would work — mountRoute reads that fragment as ours — but it hands every recipient a URL that overrides the host's own anchor, and there is no browser this wave to prove it against.

Changes

  • src/config/mode.ts — linkable + DEFAULT_WIDGET_MODE; documents that the <Link> href consequence of memory mode remains unaddressed, and that this flag is what a fix would consult.
  • src/lib/url.ts — shareableUrl(canonical, currentHref, linkable), reusing the existing validateWebUrl http(s) guard on both candidates.
  • src/hooks/use-share-url.ts — feeds it the mode axis + window.location.href, so neither view reads the location any more.
  • src/components/molecules/Fallbacks/Fallbacks.tsx — a share-unavailable policy row (outside the ticket's stated file list; see notes).
  • .claude/rules/components.md, .claude/rules/i18n-and-state.md, CLAUDE.md.

Verification

  • Lint: ✓ (pnpm lint)
  • Types: ✓ (pnpm typecheck)
  • Tests: ✓ 967 passing (pnpm test:run) — shareableUrl covered in the node lane across all three modes, incl. the load-bearing no-regression case for standalone + embedded-hash; useShareUrl covered for the context wiring and the no-provider default
  • Ladle: ✓ (pnpm ladle:build)

Manual verification — NOT run this wave

No dev backend and no browser were available. In rough priority:

  1. The actual case. Load demo.html with a #respond anchor, open an event whose webUrl is null, press Share. Expect the neutral panel and no URL anywhere — not in a copy field, not in the OS share sheet.
  2. No regression, embedded-hash. Same page without the anchor: Share still shows the copy field with …#/!/… and the grid.
  3. No regression, standalone. pnpm dev, same check with the pathname URL.
  4. The canonical still wins. An event with a webUrl, in all three of the above — the copy field shows the main-site URL, never the address bar.
  5. Registration confirmation. Submit for a webUrl-less event in memory mode: "Invite a friend" and its grid are absent, add-to-calendar still renders, and the downloaded .ics has no URL: line.
  6. Ladle: Views → Share, Share-link control set to none; Molecules → Fallbacks, the two share-unavailable cases; Organisms → Registration Form, "Confirmation · nothing to link to".

Notes for reviewer

One file outside the ticket's stated ownership: Fallbacks.tsx. The first pass reused ERROR_POLICY.unavailable with the message override. /code-review was right that this is wrong twice over: that row grants onward, so with no organiser phone the screen answered "there is no link to share" with "see events in Cambridgeshire" — walking the viewer away from the class they were trying to pass on; and message is documented as reserved for unavailable's CMS-resolved status table, so the sentence escaped the en-parity test. The repo's own rule (FallbackValues) is that a state needing a different sentence gets a different row, so it got one. Copy moved from events to common, where ERROR_POLICY keys live and the test can see it.

Security review finding NOT fixed here — and I'd like a call on it. The address-bar fallback passes the host page's query string through to the clipboard, navigator.share and every third-party share intent. The repo has ruled the other way three times for telemetry (hostPageUrl, the refused Sentry HttpContext, Fathom's auto: false), all citing reset tokens and OAuth params. It is pre-existing — this PR narrows the exposure from three modes to two — and it is not a free fix: in hash mode the widget's whole route is in the fragment, so stripping the query is safe for us but breaks the link on a host that routes by query, which is WordPress's default permalink shape (/?p=123) and therefore exactly this feature's audience. Leak a host param, or break the share link on a query-routed host — that is a product call, not a refactor. Argued in the shareableUrl docblock and pinned by a fixture that now carries a query, so the next person sees it rather than rediscovering it.

Follow-ups, both out of scope:

  • shareableUrl should build the event's route rather than reflect the current one, so a share doesn't hand over the share drawer and the .ics doesn't point at the registration form. That wants the hrefFor(path) resolver the reviewer proposed, which is also what the <Link> middle-click bug needs — a boolean can't serve it.
  • The Share CTA still renders for an event that can only reach the "no link" panel. linkable is now in context and could gate it.

Closes #115

🤖 Generated with Claude Code

Ardnived and others added 4 commits August 7, 2026 21:18
On a host page carrying its own anchor (#respond) the widget mounts a
MemoryRouter and never writes the URL, so window.location.href names the
host's article and nothing about the event. ShareView, the registration
confirmation and the ICS export all handed that string out.

WidgetMode gains `linkable`, derived once from the mountRoute decision in
Widget.tsx and threaded through App. `shareableUrl` (lib/url.ts) resolves
the one question both surfaces ask: the canonical webUrl in every mode,
the address bar only where the route is in it, undefined otherwise.

Closes #115

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
A Share link axis on ShareView's story previews the degraded screen, and a
node-lane spec walks the whole chain — WidgetMode context through useShareUrl
— including the no-provider default, which is what keeps the axis opt-out.

Documents the axis in .claude/rules/components.md, including the one memory-mode
consequence still unaddressed (<Link> href resolution).

Closes #115

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- export DEFAULT_WIDGET_MODE so the context default has one spelling
- ViewHarnessProps.mode is Partial: a story overrides the axis it is about
  rather than restating the shape. The ShareView story had silently flipped
  `standalone`, changing what EventSummary renders on the screen it previews.
- drop the two hook tests that restated lib/url.test.ts
- story for the newly-optional confirmation branch

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
/code-review found the borrowed `unavailable` row answering "there is no
link to share" with "see events in Cambridgeshire" — walking the viewer
away from the class they were trying to pass on — and the sentence
escaping the en-parity test, since `message` is the one override reserved
for `unavailable`'s CMS-resolved status table.

`share-unavailable` is that row minus `onward`, with its copy in `common`
where ERROR_POLICY keys live, so the test pins it word-for-word.

The security review's finding is NOT fixed here, deliberately: the host
page's query string still rides the address-bar fallback in hash mode.
Stripping it would break the share link on a query-routed host, which is
WordPress's default permalink shape. Argued in the docblock and pinned by
a fixture that now carries a query.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying sahajatlas-design with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3587b6d
Status: ✅  Deploy successful!
Preview URL: https://7a880ffb.sahajatlas-design.pages.dev
Branch Preview URL: https://feat-linkable-memory-mode.sahajatlas-design.pages.dev

View logs

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying sahajatlas with  Cloudflare Pages  Cloudflare Pages

Latest commit: 3587b6d
Status: ✅  Deploy successful!
Preview URL: https://ed587095.sahajatlas.pages.dev
Branch Preview URL: https://feat-linkable-memory-mode.sahajatlas.pages.dev

View logs

@Ardnived
Ardnived merged commit 3f2a4ef into main Aug 11, 2026
5 checks passed
@Ardnived
Ardnived deleted the feat/linkable-memory-mode branch August 11, 2026 16:16
Ardnived added a commit that referenced this pull request Aug 18, 2026
#155)

* feat(widget)!: route through a query parameter and remove hash routing

The widget's route moves from the URL fragment to a query parameter on the
host's own page:

  before   your-site.example/classes#!/gb/london
  now      your-site.example/classes?atlas=/gb/london

This is the change the rest of the SEO programme rests on. No search engine has
ever treated a fragment as a distinct URL — `#!` was deprecated in 2015 and
dropped in 2018 — so every event on every embed was the same URL to a crawler.
A query string is indexable and needs no server configuration from the host,
which is why it works identically on WordPress, Wix, Weebly and Joomla.

It removes a class of bug rather than adding a mode. The widget no longer reads
or writes the fragment at all, so the three-way ours/free/foreign decision, the
blank-widget failure of #92, the two spellings react-router normalised between,
and the whole foreign-anchor branch are simply gone.

Engine: a hand-written `History` behind react-router's stable `Router` +
`Navigator` (`src/lib/atlas-history.ts`, `src/router.tsx`). `encodeLocation` is
deliberately omitted — the obvious implementation returns the host's pathname
and poisons every derived route. Two traps the implementation exists to avoid,
both silent: `Router` returns null on a basename miss (#92's blank widget), and
it defaults `location.key` to a constant, which would collapse every
`rememberCamera` snapshot into one bucket with every test green.

Also fixed, because the URL is now real:

- `<Link>` hrefs are absolute host-origin URLs, so middle-click, "copy link
  address" and open-in-new-tab work. That is the consequence #92 recorded and
  #142 left open, closed by `createHref` rather than by a special case.
- `useShareUrl` resolves the EVENT's route instead of `window.location.href`,
  so sharing from the share or registration drawer no longer hands over the
  drawer. Report 115's finding 3, unfixable while the route was a fragment.
- Sentry gains an `atlas.route` tag. The route used to be lost because it lived
  in the fragment; it now lives in the query, which `hostPageUrl` also strips —
  so the loss became total. It is ours, not the host's, which is why it may be
  sent when their query may not.

Scope: query + memory only. `routing=path` is accepted, warns through
`reportIntegrationWarning` and falls back to query — its prefix comes from the
client record, which arrives after the router must exist, so it lands with the
canonical work. No back-compat for `#!` links, deliberately: the legacy origins
still serve every live client until #148 Part 2, so no real link is at risk.

Verified in a browser on a cross-origin host page carrying its own `#respond`
anchor and `?p=123`: the fragment is untouched, the host parameter survives,
boot writes nothing, and `routing=path` logs its warning by name. The jsdom
spec that replaces `hash.router.test.tsx` drives the real router for the ten
agreements a pure spec cannot attest.

Closes #154

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

* docs(widget): correct an overstated risk in the routing history

Two fixes, both about accuracy rather than behaviour.

The `Router`-returns-null-on-a-basename-miss trap was listed as one the query
history exists to avoid. It is not reachable: query routing passes no
`basename`, so `stripBasename` is never called. It was a real hazard for the
PLANNED path mode, which mounts under a prefix, and it becomes live again if
that ships — but claiming it here made the implementation look riskier than it
is and pointed a future reader at the wrong thing. The one trap that IS real
stays, and is asserted: `Router` defaults `location.key` to a constant, which
would collapse every `rememberCamera` snapshot into one bucket.

Also reads our history state once on popstate instead of twice. `currentState()`
MINTS a key when the entry has none — a host-created entry, or one predating the
widget — so calling it twice minted two and used only the first. Harmless today,
and exactly the kind of thing that stops being harmless the moment someone
trusts `idx`.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>

---------

Co-authored-by: Claude Opus 4.8 (1M context) <[email protected]>
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.

feat(widget): make memory-mode routing linkable where it matters

1 participant