Skip to content

feat(event): add-to-calendar on the registration confirmation - #127

Merged
Ardnived merged 5 commits into
mainfrom
feat/add-to-calendar
Aug 8, 2026
Merged

Ardnived merged 5 commits into
mainfrom
feat/add-to-calendar

Conversation

@Ardnived

@Ardnived Ardnived commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Closes #105

Reintroduces calendar export at the moment it is most wanted — right after a successful
registration — rather than back in the event action row PR #83 cut it from.

The two decisions worth your attention

1. No external library, decided on correctness rather than size

I measured every candidate by actually bundling it (esbuild, minified + gzipped), not by
dist.unpackedSize:

Candidate Bundled gz Deps Verdict
add-to-calendar-button — (5.35 MB unpacked) timezones-ical-library Full web component
ics 23.6 KiB yup, nanoid Heaviest, no TZID
calendar-link 4.9 KiB dayjs A second date library beside our luxon
datebook 3.3 KiB none Smallest library
hand-rolled (revived) ~2.1 KiB none (reuses luxon) Chosen

Size is the least interesting column. I probed the two real contenders with a weekly
19:00 Europe/London class and both emit DTSTART:20260907T180000Z — a bare UTC
instant with no TZID
. That preserves the instant, not the wall-clock time, so every
occurrence after the October DST change lands at 18:00 for a class that still meets at
19:00. It is the precise defect SahajCloud's own icsBuilder.ts was rewritten to avoid.
calendar-link also emits LOCATION:Community Hall, London with the comma unescaped —
an RFC 5545 violation.

A library that can't express recurrence in the event's own timezone isn't a smaller
version of this module, it's a wrong one.

2. icalRule is unusable — checked upstream rather than assumed

It's rrule-temporal's toString() (computeIcalRule, SahajCloud
src/lib/schedule/scheduleHooks.ts). Four disqualifiers:

  • a one-off is not null — non-recurring events are modelled as FREQ=DAILY;COUNT=1,
    so a single class would import as a series;
  • its EXDATE is UTC-stamped while its DTSTART is TZID-local, and a UTC EXDATE
    frequently fails to match a TZID-local instance, so the cancelled session still shows;
  • no DTEND (endTime is absent from it entirely);
  • no line folding.

SahajCloud's own builder rejects it for the same reasons. We rebuild from the structured
fields, which the full event doc carries (getEventDoc selects schedule: true) and
the trimmed feed deliberately does not.

Revived, not rewritten

The first commit restores src/lib/ics.ts + its spec byte-for-byte from 4f6b397^.
All 25 original tests passed unchanged — which is the evidence that #83's removal was
a four-action-maximum rebalance, not a technical defect. Extensions land in later commits
so they're reviewable as a diff against the known-good original.

Added on top: buildOutlookCalendarUrl (live + office hosts), buildYahooCalendarUrl,
icsFileName, and:

  • The anchor rule. Google and the .ics carry a real RRULE, so they stay on the
    series start — DTSTART is the instance COUNT/BYDAY are reckoned from, and
    re-anchoring an 8-session course on session five would hand the importer eight more
    sessions from there. Outlook, Office 365 and Yahoo have no recurrence parameter, so
    each gets one occurrence: the session the viewer registered for, else the next upcoming
    one. Never the series start — a class running since 2019 would otherwise put a 2019 date
    in someone's calendar.
  • A one-hour DTEND fallback. A bare DTSTART is RFC-legal but zero-length (§3.6.1),
    which calendars draw as a hairline. Matches SahajCloud's builder so the download and the
    confirmation email agree.

Bundle cost — eager payload unchanged

Graph Before After Δ Budget
standalone 379.7 KiB 379.7 KiB 0.0 395
embed 381.2 KiB 381.2 KiB 0.0 395

BUDGET_KIB untouched. The feature costs +2.1 KiB gz on the RegistrationView
chunk, which #96 already put behind a lazy seam. Verified mechanically: VCALENDAR
appears in exactly one built chunk, and that chunk is absent from dist/index.html's
entry + modulepreload list.

One deliberate deviation: I did not add a third import() hop inside
RegistrationView. It's already a second hop contributing zero to first load, and a
chunk fetched after a successful registration POST is a network request at the worst
possible moment — a failed fetch would replace "you're registered" with an error, for
2 KiB. Happy to add the seam if you'd rather.

Design notes

  • RegistrationForm stays event-decoupled — it takes a calendar prop of export
    primitives, never an Event, and renders nothing when absent. RegistrationView
    builds it, because it holds the full doc.
  • The anchor comes from mutation.variables, so the session the viewer actually
    registered for needs no extra state.
  • LOCATION is omitted for online events. whereLine there means "hosted from
    <city>" — where the class originates, not anywhere the viewer goes.
  • Not in the molecules barrel (that barrel is imported by eager views), and now named
    in index.test.ts's LEAF_PATH_ONLY so the rule is enforced rather than just stated.

One review finding I pushed back on: an altitude pass flagged the export's LOCATION
coming from whereLine, a display string. Sound in general, but that branch is reached
only for physical events, where whereLine is [street, city].join(', ') falling
back to region.name — pure address data, no translated prose. The translated form is
the online one, already excluded.

Review passes completed

  • ✅ /simplify — 4 agents. Caught a real duplicate DEFAULT_DURATION with a different
    condition (grid drew an hour, export emitted zero-length, for the same event), a dead
    recursive branch in the anchor helpers, the missing barrel guard, and a webUrl
    disagreement where the share block had a fallback and the calendar link didn't.
  • ⚠️ /code-review and /security-review — not run. The session hit an account quota
    mid-run and the coordinator directed no further review subagents. Per finalize-pr's
    path filter the security review was skippable anyway (no match on the api/auth layer,
    Widget.tsx, HTML sinks, deps, or env), but note this branch does add outbound URL
    construction from CMS-authored strings and a blob: download — worth a human eye.

No CSP change

Provider links are top-level target="_blank" navigations and the .ics is a blob:
download. The AC excludes both, and neither is a fetched cross-origin subresource — no
new origin is contacted.

Verify manually (the node lane can't)

  1. Register against the local seed; confirm the block renders above the share grid.
  2. Open each of the four provider links — check date, time, timezone.
  3. Download the .ics and import it into Apple Calendar and Google Calendar. Highest
    value check: a file that parses in a test and is rejected by a real client is the
    failure mode.
  4. A recurring event should import as a series with the cancelled week absent.
  5. An online event should carry no misleading location.

Browser verification was not authorised this wave (a sibling ticket owns the shared
browser).

Full write-up: .claude/reports/105-add-to-calendar.md.

🤖 Generated with Claude Code

Ardnived and others added 4 commits August 7, 2026 10:37
Restores src/lib/ics.ts and its spec byte-for-byte from 4f6b397^ — the
commit that dropped the Add to calendar action end to end (PR #83). That
removal was an action-row rebalance to a four-action maximum, not a
technical defect, and nothing it depended on has moved: scheduleStart,
scheduleTimeZone and withEndTime are all still exported from
lib/shape/event.ts, and EventSchedule still carries every field the
builder reads. All 25 original tests pass unchanged.

Committed as a pure revert so the extensions for issue #105 (the four
additional providers, the recurrence-less anchor rule, the DTEND
fallback) are reviewable as a diff against the known-good original.

Closes #105

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Extends the revived builder to the five providers issue #105 asks for.
Google and the .ics download already carried the real recurrence; the
three added here take no recurrence parameter, so each gets a single
occurrence and the whole question is WHICH one.

Never the series start. A weekly class running since 2019 would otherwise
drop a 2019 date into the viewer's calendar — so `occurrenceStart` anchors
them on the session the viewer registered for (`from`, new on the input),
falling back to the next upcoming occurrence. `exportStart` deliberately
ignores `from` for a recurring event: DTSTART is the instance the RRULE
counts from, so re-anchoring an 8-session course on session five would
hand the importer eight MORE sessions starting there.

Also gives an occurrence with no `endTime` a one-hour default rather than
omitting DTEND. A bare DTSTART is RFC-legal but means a zero-length event
(RFC 5545 §3.6.1) that calendars draw as a hairline, and the three new
provider APIs require an end anyway. The hour matches SahajCloud's own ICS
builder, so the download and the confirmation email agree.

The module docblock now records WHY this is hand-rolled, measured rather
than asserted: datebook (3.3 KiB gz) and calendar-link (4.9 KiB gz, pulls
dayjs beside our luxon) both emit a bare `DTSTART:...Z` with no TZID, which
drifts a weekly 19:00 London class to 18:00 after the October DST change.
It also records why the CMS's own `icalRule` is unusable — it emits
FREQ=DAILY;COUNT=1 for one-offs, and its UTC EXDATE does not match its
TZID-local DTSTART. SahajCloud's own builder rejects it for the same
reasons.

Closes #105

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Puts calendar export at the moment it is most wanted — right after a
successful registration — rather than back in the event action row the
four-action rebalance cut it from (PR #83).

The block renders five targets: Apple (an .ics Blob download, which is
also the escape hatch for Thunderbird/Proton/desktop Outlook), plus
link-outs to Google, Outlook.com, Office 365 and Yahoo. The four link-outs
are real anchors, so middle-click and long-press behave; only the .ics
path is a button, because it synthesises a file rather than navigating.

RegistrationForm stays event-decoupled. It takes a `calendar` prop of
export PRIMITIVES, never an Event, and renders nothing when absent.
RegistrationView builds that prop because it holds the FULL event doc —
`getEventDoc` selects the whole schedule group, so it has the exclusions /
untilDate / monthDay / weekdayOfMonth the trimmed feed deliberately omits.
Exporting from a feed event would silently ship a series missing its
cancelled sessions and its end date.

Two details worth the reviewer's eye:

- The anchor is the session the viewer actually registered for, read from
  `mutation.variables` so it needs no extra state. It only moves the
  recurrence-less providers; Google and the .ics keep the series anchor.
- LOCATION is omitted for ONLINE events. `whereLine` there reads "hosted
  from <somewhere>" — where the class originates, not anywhere the viewer
  goes — and as a calendar location it would send them to a city they have
  no business in.

AddToCalendar is not re-exported from the molecules barrel: that barrel is
imported by eager views, and the re-export edge alone would pull this and
its luxon-backed builder into every host page's first-load payload. Same
rule the barrel already states for ShareContent and ImageCarousel.

Restores `actions.add_calendar` / `actions.download_ics` across all ten
locales, recovered from 4f6b397^ rather than retranslated.

Closes #105

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Four cleanup agents over the branch diff; the findings two of them raised
independently were the real ones.

- `DEFAULT_DURATION` was defined twice — `shape/calendar.ts` already had it
  for the grid, and the ICS export added a second with a DIFFERENT
  condition (`?? null` vs `end > start`). So an `endTime` equal to the
  start time drew an hour-long block in the grid and exported a
  zero-length VEVENT. Lifted to `shape/event.ts` beside `withEndTime` (its
  stated home as the one parser of the wire format) and both now apply the
  same test.
- `exportStart` and `occurrenceStart` each carried a full copy of the
  anchor resolution, and `occurrenceStart`'s fallback re-entered
  `exportStart` — a branch reachable only when both were provably falsy,
  so it always resolved to `seriesStart`. `exportStart` is now the one line
  it always was: recurring → series anchor, else the occurrence rule.
- `AddToCalendar` was not in `molecules/index.test.ts`'s `LEAF_PATH_ONLY`.
  Its own index.ts asserts that rule in prose while nothing enforced it —
  and `pnpm size` is a weaker net here than for the Swiper/react-share
  cases, because luxon is already eager, so the leak would be `ics.ts`
  alone and would land inside the budget's slack.
- The `.ics` and share blocks disagreed about the event URL:
  `eventUrl={event.webUrl ?? window.location.href}` beside a raw
  `url: event.webUrl`. `webUrl` is `SafeUrlSchema` (`.catch(null)`), so
  events with a missing or non-http CMS url got a share link and no
  calendar link. One fallback now.
- The export anchors on the FILTERED upcoming dates, so it can't land on a
  session that already finished — the guard the date picker above it
  already needed, and the one thing `lib/ics.ts` can't re-derive alone.
- Dropped a redundant `rel` the Button atom already derives, matched
  ShareContent's `gap-3` (the two rows stack on one screen), derived the
  list key from the brand label, and added the missing molecule story.

Deliberately NOT taken: routing the confirmation through a render-prop
slot instead of the `calendar` prop (a larger change to a file a sibling
a11y ticket owns), and collapsing the four provider builders behind a
config table (the simplification pass argued against it — they vary on
anchor, stamp format and parameter names, and `grep startdt` landing in
the Outlook builder is worth more than the deduplication).

Also kept, against one finding: the export's LOCATION still comes from
`whereLine`. The concern was display copy leaking into export data, but
that branch is only reached for PHYSICAL events, where `whereLine` is
`street, city` falling back to the region name — address data, no
translated prose. The translated form is the online one, which is already
excluded.

Closes #105

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

cloudflare-workers-and-pages Bot commented Aug 7, 2026 •

Copy link
Copy Markdown

Deploying sahajatlas-design with  Cloudflare Pages  Cloudflare Pages

Latest commit: 452502b
Status: ✅  Deploy successful!
Preview URL: https://4ab20c3a.sahajatlas-design.pages.dev
Branch Preview URL: https://feat-add-to-calendar.sahajatlas-design.pages.dev

View logs

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying sahajatlas with  Cloudflare Pages  Cloudflare Pages

Latest commit: 420ec20
Status: ✅  Deploy successful!
Preview URL: https://afba37b4.sahajatlas.pages.dev
Branch Preview URL: https://feat-add-to-calendar.sahajatlas.pages.dev

View logs

@Ardnived

Ardnived commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

CI status

Green: Lint/Typecheck/Build · Smoke · Cloudflare Pages (app + design).

Red — Dependency Audit, pre-existing and not caused by this branch.

This branch changes no dependency files — git diff origin/main...HEAD -- package.json pnpm-lock.yaml scripts/audit-baseline.json is empty — so its dependency tree is byte-identical to main, and pnpm audit:check fails the same way when run against it locally.

Four newly-published high advisories:

Package Advisory Fix available
image-size GHSA-w3rx-r6r6-pgpr none (—)
image-size GHSA-5p2g-fcmc-qvqq none (—)
nanoid GHSA-28wg-ghj8-5hjv >=3.3.16
nanoid GHSA-2v37-7h3g-55p8 >=3.3.17

It's the advisory database that moved, not the code — #124's CI ran at 18:01Z and passed; #125, #126 and this PR ran between 23:48Z and 23:53Z and all three fail on exactly these four IDs.

Deliberately not fixed here. scripts/audit-baseline.json wants "the ticket that owns it", and that isn't #105 — attributing an unrelated image-size/nanoid waiver to the calendar-export ticket would put a wrong owner on a security waiver. It's also a shared file three concurrent PRs would each be editing, so three copies of the same four entries is a guaranteed conflict. Both image-size advisories have no fix, so a baseline entry is the only option there; nanoid is transitive and would need a pnpm.overrides bump.

Worth one ticket that owns all four, landing once — then #125/#126/#127 pick it up on rebase.

Ardnived added a commit that referenced this pull request Aug 8, 2026
Four high advisories published 2026-08-07 against the existing lockfile (image-size x2, nanoid x2) turned the audit gate red on every open PR, none of which touch either package. Both are verified absent from the shipped bundle by build + grep — payload is types-only so image-size never ships, postcss is build-time, and the one 'nanoid' string in dist/ is zod's .nanoid() validator name. image-size has no published fix; nanoid's is held back by postcss's own pin and arrives free under #101. Baselined against #101 with per-entry reasoning.

Unblocks #123, #125, #126, #127.
@Ardnived
Ardnived merged commit 19e6551 into main Aug 8, 2026
4 checks passed
@Ardnived
Ardnived deleted the feat/add-to-calendar branch August 8, 2026 00:10
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(event): add-to-calendar on the registration confirmation

1 participant