Skip to content

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

Closed

Description

@Ardnived

Summary

#92 stopped the widget rendering blank on a host page whose fragment it declined to take. On
such a page (#respond, #comment-123 — routine on WordPress) mountRoute returns
{ router: 'memory' } (src/lib/shape/hash.ts:69) and Widget.tsx:171 mounts a
MemoryRouter, so the widget never writes the URL. That was the right call, and it left two
consequences the implementing agent deliberately deferred — both already written down in
.claude/rules/components.md → "Widget / embedding constraints", and neither addressed:

  1. ShareView and RegistrationView fall back to window.location.href. In memory mode
    that string is the host page URL — it identifies nothing about the event, so the copy
    field, the native share sheet and the registration confirmation all hand out a link that
    lands on the host page's article, not the meditation.
  2. <Link> hrefs resolve against the host origin. A route string like /gb/london is not
    a widget location in memory mode; nothing in the code says so, so components can't ask.

The fix is to give WidgetMode a linkable axis, so a view asks whether its route can be
put in front of a human rather than inferring it. Today WidgetMode carries standalone and
hasMap (src/config/mode.ts:13-16) — this is a third runtime axis of exactly the same kind.

Current behavior

  • src/config/mode.ts:13-16 — WidgetMode = { standalone: boolean; hasMap: boolean }; context
    default { standalone: false, hasMap: true }.
  • src/Widget.tsx:168-171 — mount.current.router === 'hash' ? <HashRouter…> : <MemoryRouter initialEntries={[mount.current.path]}>. The router choice is made once at mount and is not
    surfaced to the tree.
  • src/views/ShareView/ShareView.tsx:40 — url={event.webUrl ?? window.location.href}
  • src/views/RegistrationView/RegistrationView.tsx:91 — eventUrl={event.webUrl ?? window.location.href}

The fallback is not hypothetical: event.webUrl is null for an unpublished or
publication-gated event, which is exactly when the fallback fires. Note the fallback is correct
in the other two modes — standalone (BrowserRouter) and embedded-hash both put an identifying
route in window.location.href — so this is specifically a memory-mode defect, and the fix must
not regress the two working cases.

Proposed changes

  • Add linkable: boolean to WidgetMode (src/config/mode.ts), documented in the same
    comment block as standalone / hasMap: whether the current route can be handed to someone
    else — true for the standalone build and for embedded hash routing, false in memory mode.

    Default it to true in the context default (the standalone/dev path), so the falsy case is
    opt-in and a component that forgets the axis behaves as it does today.
  • Thread it from Widget.tsx, derived from the single existing decision
    (mount.current.router === 'hash'). Do not re-derive it from window.location anywhere else —
    mountRoute is the one place that answers this, and a second reading is how the two drift.
  • ShareView and RegistrationView consult it instead of reaching for window.location.href:
    • event.webUrl when present — unchanged, and still preferred in every mode.
    • linkable → window.location.href, as today.
    • !linkable → decide one documented behaviour and apply it to both views. The preferred
      shape is to omit the URL rather than ship a wrong one (ShareContent / RegistrationForm
      degrade to label-only sharing and a confirmation with no link), because a host-page URL is
      actively misleading in a share sheet. If a URL is genuinely required by a downstream prop
      contract, say so in the report and make the prop optional instead of passing a lie.
  • Document the <Link> consequence on the mode axis (a comment in mode.ts and the
    existing bullet in .claude/rules/components.md), so the next component that needs it has
    something to read. Do not change the Link atom in this ticket — that file is owned by the
    sibling anchor-predicate ticket in this batch.

Acceptance criteria

  • WidgetMode carries linkable, defaulting to true, documented alongside standalone
    and hasMap
  • Widget.tsx derives it from the mountRoute result only; grep finds no second
    window.location.hash reading introduced for this
  • Neither ShareView.tsx nor RegistrationView.tsx references window.location.href
    unconditionally; both branch on linkable
  • On a host page with a foreign anchor, opening Share for an event with a null webUrl
    produces no host-page URL in the copy field or the native share payload
  • No regression in the two working modes: standalone and embedded-hash still produce the
    identifying URL they do today (this is the load-bearing check — cover both)
  • Unit coverage in the node lane for the mode-to-URL decision (a pure helper preferred over a
    component test, per .claude/rules/tests.md); ShareView.stories.tsx still renders
  • .claude/rules/components.md → "Widget / embedding constraints" updated: the consequences
    bullet now points at linkable as the way to ask, and states which consequence remains
    unaddressed (<Link> href resolution)
  • Lint + typecheck + pnpm test:run pass
  • Verified in the running widget against a page carrying a #respond-style anchor
  • Implementation report written to
    .claude/reports/<this-issue-number>-linkable-mode-axis.md in the main checkout at
    /Users/devindra/Documents/Projects/SahajAtlasWeb (.claude/reports/.gitignore is *, so a
    worktree copy would be discarded)

Parallel implementation

This ticket owns these files; no other ticket in this batch touches them:

  • src/config/mode.ts
  • src/Widget.tsx
  • src/views/ShareView/ShareView.tsx (+ its stories)
  • src/views/RegistrationView/RegistrationView.tsx
  • .claude/rules/components.md
  • whatever molecule prop contracts the URL decision requires (ShareContent, RegistrationForm)
    — if that reaches beyond these files, note it in the report

Do not edit src/lib/shape/hash.ts (its decision is correct and pinned by hash.test.ts /
hash.router.test.tsx), src/components/atoms/Link/, src/components/atoms/Button/, or
src/lib/shape/href.ts — those belong to the sibling anchor-predicate ticket.

Files affected

  • src/config/mode.ts (:13-16)
  • src/Widget.tsx (:168-171)
  • src/views/ShareView/ShareView.tsx (:40)
  • src/views/RegistrationView/RegistrationView.tsx (:91)
  • .claude/rules/components.md

References

Activity

  1. added a commit that references this issue on Aug 11, 2026
    3f2a4ef
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Hold Until

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions