Skip to content

fix(i18n): production hygiene for logging, locales, storage and third-party flows - #120

Merged
Ardnived merged 6 commits into
mainfrom
fix/i18n-hygiene
Aug 7, 2026
Merged

Ardnived merged 6 commits into
mainfrom
fix/i18n-hygiene

Conversation

@Ardnived

@Ardnived Ardnived commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Four production-hygiene defects in the i18n/telemetry layer (issue #95), plus three more found while fixing them. All are host-visible: this bundle runs inside somebody else's page.

  • i18next debug: true shipped to production — verified live in the deployed bundle. Now import.meta.env.DEV; confirmed as debug:!1 in both entry graphs of a production build.
  • Eight of ten shipped locales were unreachable. supportedLanguages is now all ten (cs de en es fr hu nl pt-BR ru uk), moved to the side-effect-free config/i18n-options.ts so the node lane can assert it without booting the HTTP backend, and pinned to public/locales/ in both directions by a test. All ten are SahajCloud-supported — translations: add Hungarian (hu) and Dutch (nl) locales SahajCloud#578 (hu + nl) closed on 2026-07-17 and its src/lib/locales/index.ts carries 19 locales, so nothing had to be held back.
  • The language detector ran on library defaults, reading cookies/localStorage and writing i18nextLng onto the host's origin. Now explicit: order: ['querystring','navigator'], caches: [].
  • Both third-party data flows are now host-controllable: analytics="false" and geolocation="false" on <sahaj-atlas>, defaulting on, so existing embeds are unchanged.

Found while fixing (not in the ticket)

Fathom was writing pageviews into a host's own tracker. fathom-client's load returns early if window.fathom already exists, but the tracking effect fired regardless — so on a host page running its own Fathom, our routes landed in their site, under our client's primaryDomain. The load effect now records ownership and the tracking effect checks it. Separately, Fathom.load() with no options leaves auto-tracking on, so Fathom recorded the host page's real URL and query string (which may carry a reset token or OAuth param) on every load. Now { auto: false, honorDNT: true }.

?locale=cimode defaced the embed. ?locale is read off the host's URL, so anyone who can link to their page controls it — and cimode is i18next's translator-debug pseudo-language: it bypasses supportedLngs, skips resource loading, and makes every t() return its raw key. A link ending ?locale=cimode rendered the whole widget as dotted key names. convertDetectedLanguage now refuses cimode/dev.

supportedLngs was the missing half of the locale fix. Widening the picker alone does not stop i18next resolving the browser's full tag: a US visitor fetched /locales/en-US/{common,events}.json — two 404s and two console warnings on every page load of the deployed widget. Wiring the same constant in as supportedLngs fixes it.

Caveat, load-bearing: do not pair this with load: 'languageOnly'. It strips the region from every tag, including pt-BR — a bundle we do ship — leaving a pt we don't. supportedLngs alone already resolves en-US→en and de-DE→de without fetching either. The new spec asserts this as a round trip against i18next itself (a recording stub backend), not against the option's name.

Locale gaps that the widened picker would have exposed to eight new audiences. theme.{light,dark,auto} were en-only in all nine non-English locales — sitting in the very menu being widened — and hu was missing widget.label entirely, the accessible name of the widget root's role="region" landmark (#92); WebKit drops the role when that name resolves empty. All filled via pnpm i18n:add. The common namespace is now at full parity, enforced per locale; events carries seven untranslated keys as a named, ratcheting list (a superset check, so a translator filling one in for German alone cannot turn CI red).

Privacy decisions

ipwho.is: kept passive, documented, and made switchable — not gated behind an interaction. The lookup is already purpose-limited (it fires only when the nearby suggestion could show, or on an online event that needs the viewer's local time) and already skipped when dismissed or when a search is active. Gating it behind an explicit interaction would not protect anyone: a suggestion you must ask for is not a suggestion, and a viewer cannot ask for their own timezone label. Under GDPR the host is the controller, so the right primitive is a switch they own plus a disclosure they can copy into their notice — geolocation="false", and it is never called.

README gained a privacy/storage/CSP section, additive to the existing embedding docs (#93 owns the integrator guide wholesale). Reviewing it caught that my first draft claimed to be complete while omitting Mapbox: it writes mapbox.eventData:<token> and mapbox.eventData.uuid:<token> — a persistent anonymous id — to the host's localStorage and POSTs map-load telemetry to events.mapbox.com. Now disclosed, with the honest note that the widget's own theme key is unnamespaced and will collide with a host's. The CSP block also had duplicate directive names, which CSP silently drops after the first occurrence — a host pasting it would have blocked Fathom while believing they had allowed it. One line per directive now.

Verification

  • Local: lint, typecheck, test:run (63 files / 697 tests), build + assert-css-scoped, size (both graphs under budget), ladle:build — all green.
  • Production bundle grepped: debug:!1; order:['querystring','navigator'],lookupQuerystring:'locale',caches:[]; the ten-locale array; i18nextLng appears only inside the detector library's own dead default.
  • i18next behaviour measured against the real library rather than reasoned about (the supportedLngs round trip, and confirming resolvedLanguage is unchanged at the SahajCloud boundary for locales we don't ship — so activeLocale() still sends what it always did).
  • MAP_WORLDVIEWS checked per .claude/rules/mapbox.md: all eight new languages correctly fall to default; no entry needed.
  • Browser verification was not authorized this wave (a sibling agent owned the shared browser). Manual checks worth doing: open the settings cog and switch through several new languages; confirm a host page's console is silent on load (no i18next debug lines, no /locales/en-US/* 404s); confirm analytics="false" and geolocation="false" suppress their requests in the network panel.

Review passes

/simplify (4 angles), /code-review and /security-review all completed and their findings were triaged and fixed — the Mapbox omission, the duplicate CSP directives, the events-parity ratchet, the Ladle picker (all ten bundles now load), the detector-options mutation, the attributeEnabled claim (now genuinely shared with map in both entries), and a comment that repeated the ticket's incorrect premise that the detector's storage write was unguarded (the library does guard it — the reason to drop the write is that it is undeclared, not that it throws). Not fixed, deliberately: renaming the unnamespaced theme key (outside this ticket's files, and it would cost every viewer their stored preference once) and the apikey/api-key contradiction at README:9 (a known blocker owned by #93).

Sessions were repeatedly killed by platform outages mid-run; the coordinator committed and pushed the final batch after verifying the gates.

Closes #95

🤖 Generated with Claude Code

Ardnived and others added 5 commits August 6, 2026 21:32
…e host-origin write

i18next shipped `debug: true` to every host page's console (verified in the
deployed bundle), the picker offered 2 of the 10 locale bundles that ship, and
the language detector ran on library defaults — reading cookies/localStorage and
writing `i18nextLng` onto the HOST's origin, the one storage path not wrapped
against a sandboxed-iframe throw.

`supportedLanguages` + the detection options move to the side-effect-free
`i18n-options.ts` so the node lane can assert them without booting the HTTP
backend, and a test pins the picker to `public/locales/` in both directions.
All ten shipped locales are SahajCloud-supported (hu + nl since #578).

Refs #95

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Fathom loaded our tracker into the host's page and ipwho.is received the
visitor's IP with no way for the site operator — the controller, under GDPR — to
decline either. Two attributes now do: `analytics="false"` and
`geolocation="false"`, both defaulting on, so an existing embed is unchanged.

The flags are a boot singleton read where they're needed (mirroring
config/api/auth.ts and config/preview.ts) rather than a context threaded through
App, so the analytics block and useIpLocation are the only call sites touched.
The IP lookup stays passive by default: it is purpose-limited to the nearby
suggestion and localized online-event times, already skipped when neither can
show, and gating it behind an interaction would remove the suggestion rather
than protect anyone.

Refs #95

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
An integrator's privacy notice has to describe what the widget makes their
visitors' browsers do, and nothing said what that was. Adds the two storage keys,
the two third-party hosts with the conditions and the attribute that stops each,
and the CSP lines they need — appended to the existing embedding section, which
issue #93 rewrites wholesale later.

Writing it surfaced a defect: Fathom was loaded with auto-tracking on, so its
script recorded the HOST page's real URL and query string on load — a page that
may carry a reset token — on top of the route the effect below reports. Loaded
with `auto: false` now, plus `honorDNT`.

Refs #95

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

Three findings from the simplify pass and a browser check of main, all the same
drift: the picker's list was never wired to i18next.

- `supportedLngs` was unset, so i18next resolved the browser's full tag and the
  backend fetched it: `/locales/en-US/*` 404s on every page load of the deployed
  widget, and `/locales/pt/*` for the pt-BR bundle this branch just exposed. Set
  from the same constant. NOT `load: 'languageOnly'`, which would strip pt-BR to
  a `pt` we don't ship — the new round-trip spec asserts that against i18next
  rather than trusting the option's name.
- `theme.{light,dark,auto}` were en-only in all nine other locales, sitting in
  the same menu as the picker being widened, and `hu` had no `widget.label` at
  all — the accessible name of the widget root's region landmark (#92), which
  WebKit drops entirely when it resolves empty.
- The common namespace is now at full parity and a per-locale test keeps it
  there; the events namespace carries seven untranslated keys as a named,
  ratcheted list rather than silent fallback.

Also folds `map`'s hand-rolled "false"/"0" reading into the shared
`attributeEnabled`, so all three boolean attributes share one spelling.

Refs #95

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Three corrections the reviews raised, plus the parity test they broke.

`?locale=` is read off the HOST page's URL, so anyone who can link to
someone's embed controls it. `cimode` is i18next's translator-debug
pseudo-language — appended to supportedLngs internally, skips resource
loading, and makes every t() return its raw key — so a link ending
`?locale=cimode` renders a customer's embed as a list of dotted key
names. convertDetectedLanguage now refuses it and `dev`.

The detector merges its defaults into whatever options object it is
handed, which was mutating the module's exported config in place; it is
now spread per init.

The events-parity assertion becomes a superset check: translations land
one language at a time, and an equality check would turn CI red the
moment German filled in one of the seven known gaps — punishing the fix.
Shrinking the list stays the ratchet's job.

Also corrects the storage rationale: the reason to drop the host-origin
write is that it was never declared to integrators, not a crash risk —
the library does guard the access.

Closes #95

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Ardnived added a commit that referenced this pull request Aug 7, 2026
…#122)

Cloudflare posts neither commit statuses nor GitHub deployments on this repo, so smoke preview-discovery rested entirely on the Cloudflare bot's PR comment — which is best-effort and simply never appeared on #120, whose deploy was healthy. Since #99 made a missing preview hard-fail a same-repo PR, that flake presented as a red check blocking a good merge. Now reads the check run's output summary, which exists exactly when the deploy does, restricted to Cloudflare's app.

Unblocks #120.
One conflict, in README.md's CSP block, and it was load-bearing: this
branch added `https://cdn.usefathom.com` to script-src plus a warning
that CSP ignores every repeat of a directive name after the first, while
#121 added the widget's own origin as a SECOND `script-src` line — the
exact mistake the warning describes. Merged onto one line carrying all
three sources, so a host pasting the block actually gets Turnstile and
Fathom rather than silently losing them, and kept both explanations.

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 with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5be5439
Status: ✅  Deploy successful!
Preview URL: https://faa7fcb3.sahajatlas.pages.dev
Branch Preview URL: https://fix-i18n-hygiene.sahajatlas.pages.dev

View logs

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying sahajatlas-design with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5be5439
Status: ✅  Deploy successful!
Preview URL: https://fb0269a0.sahajatlas-design.pages.dev
Branch Preview URL: https://fix-i18n-hygiene.sahajatlas-design.pages.dev

View logs

@Ardnived
Ardnived merged commit a586442 into main Aug 7, 2026
5 checks passed
@Ardnived
Ardnived deleted the fix/i18n-hygiene branch August 7, 2026 16:30
sydevs-bot pushed a commit that referenced this pull request Oct 3, 2026
The 27-line header repeated the section its own second line points the reader
at: the #148 `max-age` measurement, the `deployment_status` deviation, and the
filters-in-`if` reason each appeared in both. Two copies of one argument drift
apart, and the pointer is what makes the duplicate pointless rather than
merely long.

What stays is what a reader of this file alone cannot get from `docs/testing.md`:
the absent `concurrency` group, and — moved down to the `if:` it explains —
why two conditions gate the branch rather than one. Every `#NNN` breadcrumb cut
from here is live at the file it now points at: PR #120 in `docs/testing.md`
and in `get-cloudflare-preview-url.mjs`'s header, #148 and #244 still named
above.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0185rnixqGMn3BApUyF34Ka2
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.

fix(i18n): production hygiene for logging, locales, and storage

1 participant