Skip to content

docs(widget): publish an accurate integrator guide #93

Closed

Description

@Ardnived

Summary

The host-facing documentation actively misleads integrators. The README's embed snippet fails on both of its two lines, the CSP guidance covers 3 directives when the real contract is ~a dozen (including the hardest ask, style-src 'unsafe-inline', which appears nowhere), no attribute reference exists (two of the six attributes are documented in no host-facing doc), and there is no sizing guidance, browser-support statement, privacy disclosure, or troubleshooting section. The closest thing to an integrator guide today is a comment block in demo.html. Fix the snippet and publish a dedicated, accurate integrator guide. (Release-readiness blockers 5 and 6.)

Current behavior

The README snippet is wrong twice (README.md:8-9):

<script type="module" src="https://sahajatlas.pages.dev/sahaj-atlas.js"></script>
<sahaj-atlas apikey="…"></sahaj-atlas>
  1. sahaj-atlas.js does not exist — the build emits embed.js (vite.config.ts:32-34: entryFileNames returns 'embed.js' for the widget entry). Copy-paste yields a 404.
  2. apikey is never observed — r2wc dash-cases the apiKey prop to api-key (src/Widget.tsx:104-111). A host that gets past the 404 lands on the "not set up correctly" config-error screen. demo.html:25 has it right (<sahaj-atlas api-key="…">).

The CSP guidance documents 3 directives (README.md:15-37: script-src/frame-src for Turnstile, img-src for flags); the real contract compiled from code + the shipped bundle (readiness report §3.4) is:

Directive Values
script-src widget origin; blob: (mapbox-gl workers); challenges.cloudflare.com (Turnstile); cdn.usefathom.com (only if built with Fathom)
worker-src (+child-src) blob:
style-src 'unsafe-inline' (CSS-in-JS injection, no nonce — the hardest, currently undocumented ask) + fonts.googleapis.com (runtime @import)
font-src fonts.gstatic.com
img-src data: (marker sprites); blob:; api.mapbox.com; SahajCloud image origin(s) (cloud.sydevelopers.com / imagedelivery.net); react-circle-flags.pages.dev
connect-src cloud.sydevelopers.com; sahajatlas.com (locale JSON — a different origin from the script); api.mapbox.com, events.mapbox.com, *.tiles.mapbox.com; ipwho.is; challenges.cloudflare.com; cdn.usefathom.com (conditional)
frame-src challenges.cloudflare.com

Only Turnstile degrades gracefully when blocked (mailto fallback); everything else fails blank or unstyled with no guidance.

Missing entirely from host-facing docs:

  • Attribute reference — six attributes exist (api-key, locale, map, base-path, primary-color, secondary-color; src/Widget.tsx:104-111); primary-color/secondary-color appear in NO host-facing doc.
  • Sizing guidance — map mode renders position: fixed; inset: 0, taking over the viewport regardless of the element's size, so it effectively requires a full-page slot (report §5); map="false" requires the host to size the element or it collapses to zero height (currently stated only in a demo.html comment, lines 33-34).
  • Browser floor — the build targets Baseline Widely Available 2026-01-01: Chrome/Edge 111+, Firefox 114+, Safari 16.4+ (vite.config.ts:20-23 comment); stated nowhere host-facing.
  • #anchor-conflict + history caveats — a pre-existing host #anchor (e.g. #respond, #comment-123) currently renders the widget blank (src/Widget.tsx:56-67; report blocker 2), and the mount-time hash write pushes one history entry. Both need documenting until fixed, and the guide's wording reconciled with whatever the sibling fix ships.
  • Privacy disclosures — Fathom analytics (if enabled in the build), ipwho.is IP geolocation, i18next's default localStorage write, and the runtime Google Fonts @import are all undisclosed to hosts (report §3.5) — a GDPR exposure surface for EU clients.
  • The stable sahaj-atlas-style style-tag id as an integration point — vite.config.ts:10-16 deliberately pins attributes: { id: 'sahaj-atlas-style' } because "host sites key off this exact style-tag id", yet no host-facing doc mentions it.
  • Cache-skew note — a stale host-side-cached embed.js imports hashed chunk names the CDN no longer serves → hard 404, widget dead with no fallback (report §4).
  • Troubleshooting section and the sahajatlas.com vs sahajatlas.pages.dev origin story (locale JSON loads from a different origin than the script; the production bundle bakes in sahajatlas.com).

Proposed changes

  • Fix the README.md embed snippet: embed.js + api-key.
  • Add a dedicated integrator guide (suggest docs/embedding.md — the docs/ directory does not exist yet — or a substantial README section, linked from the README either way) covering:
    • the correct embed snippet and the two-origin story (sahajatlas.pages.dev / sahajatlas.com — script vs locale JSON),
    • a full attribute table for all six attributes (name, type, default, behavior — including map="false" and base-path boot routes),
    • the complete CSP table above, with the reason per directive and which failures degrade gracefully vs fail blank,
    • sizing guidance (map mode = full-page slot; map="false" = host sizes the element, display:block;height:…),
    • the browser-support statement (Baseline 2026 floors),
    • the #anchor + mount-time-history caveats,
    • privacy disclosures (Fathom, ipwho.is, localStorage, Google Fonts),
    • the stable sahaj-atlas-style style-tag id,
    • the cache-skew note and pointer to the versioning story,
    • a troubleshooting section (404 on script, config-error screen, blank widget on #anchor URLs, unstyled/pinless widget under strict CSP, missing flags).
  • Align demo.html's comment block with the guide (point to it; remove now-duplicated caveats or keep them consistent).

Note on concurrent CSP changes: sibling release-hardening tickets may change the CSP origin set (self-hosting fonts would remove the two Google Fonts origins; an error reporter would add an ingest origin). This guide documents the current state; each origin-changing sibling carries its own criterion to update the table, and final reconciliation happens at merge.

Acceptance criteria

  • The README embed snippet references embed.js and uses api-key — copy-pasting it (with a real key) produces a working widget, not a 404 or the config-error screen
  • An integrator guide exists (e.g. docs/embedding.md) and is linked from the README
  • Attribute table documents all six attributes from src/Widget.tsx:104-111, including primary-color and secondary-color
  • The CSP section reproduces the full contract (every directive/value in the table above, matching what the current code actually requires — spot-check style-src 'unsafe-inline', worker-src blob:, and the sahajatlas.com connect-src entry are present), and notes which blocked directives degrade gracefully vs fail blank
  • Sizing guidance covers both modes (map = full-page slot; map="false" = host-sized element)
  • Browser floor stated (Chrome/Edge 111+, Firefox 114+, Safari 16.4+)
  • #anchor-conflict and mount-time history caveats documented
  • Privacy disclosures cover Fathom, ipwho.is, localStorage, and Google Fonts
  • The sahaj-atlas-style style-tag id and the cache-skew failure mode are documented
  • A troubleshooting section maps the common failure symptoms to causes
  • demo.html comments do not contradict the guide
  • No source (src/**) changes — this ticket is docs-only
  • Lint + typecheck + test:run pass
  • Write an implementation report to .claude/reports/<issue-number>-<short-slug>.md — in the MAIN checkout at /Users/devindra/Documents/Projects/SahajAtlasWeb even when implementing from a worktree (the folder is gitignored) — covering what changed, what was deliberately NOT changed, and which readiness-report findings are resolved

Files affected

  • README.md (fix snippet, replace/expand the CSP section, link the guide)
  • demo.html (align comments with the guide)
  • docs/embedding.md (new — new docs/ directory)

Parallel implementation: this ticket OWNS the files listed above; sibling release-hardening tickets run concurrently — avoid edits outside owned files except strictly additive ones.

References

  • .claude/reports/RELEASE_READINESS.md §3.4 (full CSP table), §3.5 (privacy), §4 (cache skew), §5 (sizing), §9 (docs/monitoring), Appendix D; ship-blockers 5 and 6
  • README.md:8-9 (broken snippet), README.md:15-37 (partial CSP)
  • vite.config.ts:32-34 (embed.js entry name), vite.config.ts:10-16 (sahaj-atlas-style id), vite.config.ts:20-23 (browser floor)
  • src/Widget.tsx:104-111 (the six r2wc props), src/Widget.tsx:56-67 (hash mount guard)
  • demo.html:25 (correct api-key usage), demo.html:33-34 (sizing note to be promoted)

Activity

  1. Ardnived commented on Aug 7, 2026

    @Ardnived
    ContributorAuthor

    Correction from #92: the documented hash URL shape is wrong

    While implementing #92 we pinned react-router's actual behaviour with a test that mounts a real HashRouter (src/lib/shape/hash.router.test.tsx), and the URL shape this guide is meant to document is not what the readiness report (or this issue) assumed:

    • The boot write produces #!/gb/london — that spelling is real, but transient.
    • After any in-widget navigation, react-router normalises the basename ! to /!, so the address bar reads #/!/gb/london.

    So a host page — and anyone copying a link out of the address bar — will overwhelmingly see the #/!/… form. The integrator guide should document #/!/… as the shape hosts will observe, note #!/… as the accepted boot/base-path spelling, and avoid presenting either as the only form. Both are accepted on the way in (mountRoute, src/lib/shape/hash.ts).

    Two related behaviours to document, also from #92

    1. Foreign host anchors put the widget in memory-routing mode. If the page is loaded at e.g. #respond, the widget renders normally but routes in memory and writes nothing to the URL. Consequence worth stating plainly for integrators: in that mode the widget's internal route is not reflected in the address bar, so deep links out of the widget are not shareable from the URL bar on such a page.
    2. Mount no longer pushes a history entry (replaceState, absolutised against the current location so a host <base href> can't redirect it). The old "first Back press appears to do nothing" caveat is gone and should not be written into the guide.

    demo.html also gained an #respond anchor target in #92 for manual verification — worth keeping when this ticket edits that file.

  2. added a commit that references this issue on Aug 11, 2026
    f7367fd
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