Skip to content

feat(widget): container-aware responsiveness for embeds - #146

Merged
Ardnived merged 4 commits into
mainfrom
feat/container-responsive
Aug 11, 2026
Merged

Ardnived merged 4 commits into
mainfrom
feat/container-responsive

Conversation

@Ardnived

@Ardnived Ardnived commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Closes #107.

Every responsive decision in the widget keyed off the viewport, so a 320px column embed on a desktop screen got the desktop interaction model — a left panel with no drag handle and no swipe-dismiss. This makes the widget adapt to its own box.

What actually changes behaviourally

Stated precisely up front, because the scope is narrower than the ticket's symptom list:

  1. A map="false" embed narrower than 768px now gets the bottom-sheet model — drag handle, swipe-dismiss, sheet chrome — instead of the left panel, whatever the viewport is. This is the fix.
  2. Contact becomes tel: on touch devices and a copyable number everywhere else, in all modes, replacing a width proxy that mislabelled every touchscreen laptop.
  3. Map mode in a boxed/narrow slot now warns in the host's console instead of silently painting over their page.

And, deliberately, nothing else — see "no behaviour change in map mode" below. In particular the sticky Register bar is unchanged: it is gated on hasMap, and in map mode the new signal returns the old answer, so that line computes identically before and after. The ticket lists it as a narrow-embed symptom; it is really a map-mode-only affordance, and introducing it map-less would be a separate change (it rides --sy-sheet-top, which is only mirrored in map mode).

The finding that shaped the rest

In map mode the widget has no container, by construction. The theme root is display: contents, the canvas is position: fixed; inset: 0, and every drawer, peek strip and the cog are fixed — so <sahaj-atlas> has no box and the widget occupies the viewport whatever slot it was given. In map="false" the host sizes the element and the widget fills it.

So the container signal is a strict generalization, not a behaviour change: where a container exists it wins; where none does, useIsWide falls through to the viewport and returns exactly what useIsDesktop returned. DrawerStack only ever hands it an element in the map-less branch, so no map-mode embed behaves differently after this PR — in map mode "narrow" means a narrow viewport, i.e. a phone, which already got the sheet.

The decision table

Required output of the ticket. It lives in .claude/rules/components.md, and src/config/responsive.test.ts asserts the viewport call sites as a closed list, so it cannot quietly stop being true.

Behaviour Signal Why
Drawer direction — left panel vs bottom sheet container A fit question: does a 22rem side panel leave usable space beside it?
Drag handle · swipe-dismiss · handleOnly · snap ladder container (follows direction) The handle exists iff the sheet is a bottom sheet. One signal is what stops a handle-less panel being draggable.
Filter-overlay direction (right vs bottom) container Same panel-vs-sheet question.
Sticky Register bar (EventView) container It exists because a snap sheet can scroll the CTA away — a property of the sheet, so it must agree with whatever picked the sheet. (Still hasMap-gated, so unchanged today.)
Contact — tel: vs number + copy popover input (useCoarsePointer) Whether tel: reaches a dialer is hardware.
Map camera padding viewport A map only exists in map mode, where the widget spans the viewport.
Anchored-panel geometry (lg:inset-y-4, max-w-[calc(100vw-2rem)]), cog offset viewport (Tailwind) Map mode only; filled cancels them all map-less.
Modal box sizing viewport A modal is deliberately viewport-centred.
EventHeader md:pt-4, ListItem lg:h-9 viewport — accepted residue The only two that fire wrongly in a narrow embed. Cosmetic, and in files this ticket did not own.
Reduced motion, colour scheme preference Not a size question.

Where I disagreed with the ticket. It lists "the desktop contact popover instead of tel:" as a symptom of the narrow-embed bug. It isn't — a 320px column on a desktop still can't dial, so tel: there would be a new dead end. The ticket's own body anticipates this and its AC allows "the explicitly decided equivalent", so contact moved to (hover: none) and (pointer: coarse).

Map mode in a non-full-page slot — decided: full-page is a requirement

Not contained, and not for want of effort: vaul computes a snap sheet's translate from the WINDOW height (the Drawer atom already documents this), so a contained sheet is pushed off-screen by the library's own arithmetic; --sy-sheet-top is a viewport-relative measurement; the whole drawer layer is fixed. Containing it is a rewrite of the drawer layer, not a fixed → absolute swap.

So it is documented (README, App.tsx, demo.html, the rule) — and, past what the AC asked, detectable: lib/embed-slot.ts + a mount effect in Widget.tsx warn via the existing reportIntegrationWarning (console only, no telemetry) when map mode lands in a narrow column or on an element the host gave a height. Slack thresholds — a false positive lands in a stranger's console.

This is the call worth overruling if you disagree; it is a product decision about what map-mode embedding is for.

No @tailwindcss/container-queries

tailwind.config.js is untouched — no CSS-side case exists. Every layout-critical variant is map-mode-only (viewport == container) or cancelled by filled, which I measured rather than assumed.

A correction worth keeping. I first justified rejecting the plugin with the widely repeated claim that container-type: inline-size makes an element a containing block for position: fixed descendants. It's false, and I only caught it by testing. Chrome 151:

host style fixed child resolves against
container-type: inline-size / size the viewport — no re-parenting
contain: layout / transform the host

The false reason was replaced by the true one, and the correction is kept in the rule so it isn't re-derived.

Review

Both passes ran. Security review: no critical or high findings — reportIntegrationWarning confirmed console-only, nothing host-derived reaches the network/storage/Sentry, the ResizeObserver disconnects and cannot feedback-loop. Two taken: the slot probe read the host's DOM unguarded (a host that has patched getBoundingClientRect would have thrown from a mount effect into RootBoundary, tearing down an already-rendered widget — a diagnostic breaking what it diagnoses), and the seed/observer measured different boxes (getBoundingClientRect is transformed, borderBoxSize isn't), so a scaled ancestor would flip the model on the first unrelated resize.

Code review cleared the four risk areas (no stuck state or loop in useIsWide; provider placement correct — portals preserve context; the probe reads the right element, confirmed by measuring a real <sahaj-atlas> in Chrome; the first-render vaul remount is real but flushes before paint and is focus-safe). Findings taken:

  • The drag handle this PR promised did not render — and my own browser pass missed it. Drawer's default is direction === 'bottom' && mode !== 'filled' and map-less is always filled, so a narrow embed got a handle-less sheet that was still drag-dismissible: an invisible affordance, and a false claim in the README. The tell was in my own story, which had to force handle={!isWide} to demo it — I verified the story, not the app. DrawerStack now passes handle explicitly, keyed on dismissibility so the map-less root still shows none.
  • EventView's comment claimed a fix it does not deliver — corrected in code, spec and table (see "What actually changes").
  • The closed list was bypassable by the cheapest route — useMediaQuery({ query: '(min-width: 48rem)' }) satisfied both it and the 768px check. The set of files importing react-responsive is now pinned too.
  • Four small ones: no discarded damper per consumer; the story keys its drawer on direction; a duplicate embed-slot case became a real one; path separators normalised.

Nothing dismissed outright. One nit noted rather than solved: stripComments also strips inside string literals.

Verified in the browser (Ladle + Playwright)

The dev backend was down, so there is no data-backed testing here. Ladle needs none, and the new Drawer — container width story exercises the measured path. All by computed style / DOM attribute, never class names.

At a 1440px viewport, two boxes on one page:

box readout data-vaul-drawer-direction drag handle
320px column bottom sheet bottom present
820px slot left panel left absent
  • Damping: 820 → 400px holds left at 120ms (inside the 200ms window), commits to bottom + handle by ~420ms.
  • The handle override works at the atom level: the 320px filled drawer renders a handle, which is what the DrawerStack fix relies on. DrawerStack's own wiring of it is in the unverified list below.
  • filled cancels the anchored geometry: both compute to position: absolute, max-width: none, border-radius: 0, filling the box to the pixel.
  • Zero console errors or warnings.

Gates: lint, typecheck, test:run (1011 tests), build, size, ladle:build all pass locally. Bundle 370.2 / 372.3 KiB against 395 (24.8 / 22.7 spare) — under 1 KiB added, budget untouched.

Needs a check once the backend is back

  1. Map mode end to end — should be unchanged (container is null there), but it is the default mode and the argument above is structural rather than observed.
  2. The real DrawerStack map-less — specifically the first-render remount: container is null on the first render, so <Drawer key={direction}> may mount and immediately remount a vaul root. It happens before paint, but has not been observed.
  3. Snap ladder / drag chrome / swipe dismiss at a real mobile size.
  4. The map-slot warning firing — and not firing — on a real host page.
  5. EventActions contact on an actual touch device.

Deliberately not changed

LEFT_DRAWER_PX / --sy-drawer-w: the ticket calls this duplication "with no link", but that is stale — use-map-controller.test.ts already discovers every fallback and fails on drift. Resolving it again at runtime would re-introduce the DOM read in the map's hot path that the existing comment argues against.

Report: .claude/reports/107-container-responsive.md.

🤖 Generated with Claude Code

Ardnived and others added 2 commits August 11, 2026 09:55
Every responsive decision keyed off the screen, so a 320px column embed on a
desktop viewport got the desktop interaction model — a left panel with no drag
handle and no swipe dismiss, and no sticky register bar.

`useIsWide` observes the widget's own box and falls back to the viewport when
there is nothing to measure, which is a strict generalization: in map mode the
widget IS the viewport (fixed-inset canvas, fixed drawers, `display: contents`
root), so map-mode embeds get exactly the answer they got before.

- responsive.ts rewritten: one `WIDE_MIN_PX`, the dead xs/sm/xl entries and the
  generic `useBreakpoint` gone. First measurement commits pre-paint; only later
  changes are damped, since vaul's `direction` is not hot-swappable.
- Contact moves to `useCoarsePointer`, not width: narrowing a desktop window
  has never given it a dialer.
- Map camera padding stays viewport-derived, and says why — a map only exists
  where the widget spans the viewport.
- Map mode in a boxed slot is now audible (`lib/embed-slot.ts`) instead of
  silently painting over the host's page.
- `responsive.test.ts` pins the decision table: a fourth viewport caller turns
  the lane red.

Closes #107

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The durable half of #107. Per behaviour: container, viewport or input, with the
reason each one is right — and `responsive.test.ts` asserts the viewport list so
the table cannot quietly stop being true.

Also records two things that were measured rather than assumed:

- `mode="filled"` really does cancel the anchored geometry (at a 1440px
  viewport a filled drawer computes to `position: absolute`, `max-width: none`,
  and fills its box), which is what makes "no CSS-side container-query case
  exists" a finding rather than a hope.
- `container-type: inline-size` does NOT make an element a containing block for
  `position: fixed` descendants — the widely repeated claim this rule was first
  written on. Chrome 151 re-parents for `contain: layout` and `transform` and
  not for `container-type`. The false reason is replaced by the true one, and
  the correction is kept so it is not re-derived.

README gains a host-facing sizing section: map mode needs a full-page slot,
`map="false"` fills whatever box you give it and adapts to that box.

Closes #107

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

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

Copy link
Copy Markdown

Deploying sahajatlas-design with  Cloudflare Pages  Cloudflare Pages

Latest commit: a8a276a
Status: ✅  Deploy successful!
Preview URL: https://2907b4d8.sahajatlas-design.pages.dev
Branch Preview URL: https://feat-container-responsive.sahajatlas-design.pages.dev

View logs

@cloudflare-workers-and-pages

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

Copy link
Copy Markdown

Deploying sahajatlas with  Cloudflare Pages  Cloudflare Pages

Latest commit: a8a276a
Status: ✅  Deploy successful!
Preview URL: https://2029d5eb.sahajatlas.pages.dev
Branch Preview URL: https://feat-container-responsive.sahajatlas.pages.dev

View logs

Ardnived and others added 2 commits August 11, 2026 10:16
Three fixes from review, plus the CI break my own spec caught.

- `Widget.tsx` reads four properties of a DOM we do not own to produce a
  console line, and did it unguarded. A host that has patched
  `getBoundingClientRect` — consent wrappers and page builders do — would have
  thrown from a mount effect straight into RootBoundary, tearing down a widget
  that had already rendered. Guarded like `claimFragment` beside it.

- `useIsWide` seeded from `getBoundingClientRect().width` (the TRANSFORMED box)
  and then observed `borderBoxSize` (the untransformed one), so under a scaled
  ancestor it read one width at mount and another on the first resize. Seeds
  from `offsetWidth` now, which is the box the observer reports — and the right
  answer anyway, since a scaled widget still lays itself out in its own pixels.

- The decision-table scans now strip comments, because documenting the rule was
  breaking it: "resize past the 768px crossing" in a story docblock reddened the
  lane as a second hardcoded crossing. The story's visible description keeps the
  number by interpolating `WIDE_MIN_PX`, so it cannot drift either.

- `embed-slot.test.ts` no longer claims the thresholds are slack enough that no
  normal page trips them; 0.6 does fire for a centred article column, and that
  is a correct warning rather than a false positive.

Closes #107

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Code-review findings. The first is the one the browser pass missed.

- A narrow map-less embed got a bottom sheet that was drag-dismissible with NO
  drag handle. The atom's default is `direction === 'bottom' && mode !==
  'filled'`, which was right while `filled` could only be the wide left panel;
  container-awareness makes it a bottom sheet, and the default then hid the
  affordance while leaving the behaviour — plus the README promised a handle
  that never rendered. DrawerStack passes `handle` explicitly now, keyed on
  dismissibility so the map-less root still shows none.

  Worth recording HOW this got through: the Ladle story had to force
  `handle={!isWide}` to demo it, so the browser pass verified the story rather
  than the app. A story that props its way into a state is not covering it.

- `EventView`'s comment claimed a fix it does not deliver. The sticky bar is
  gated on `hasMap` and map mode has no container, so that line computes what it
  always did. Corrected in the code, the spec and the rules table.

- The closed list was bypassable by the cheapest route: it grepped one
  identifier, so `useMediaQuery({ query: '(min-width: 48rem)' })` satisfied both
  it and the `768px` check. The set of files importing react-responsive is now
  pinned too, and the container check is call-shaped.

- Smaller: no discarded damper per consumer; the story keys its drawer on
  direction (vaul's is not hot-swappable); a duplicate embed-slot case became a
  real one; path separators normalised.

Closes #107

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@Ardnived
Ardnived merged commit 42a2c28 into main Aug 11, 2026
5 checks passed
@Ardnived
Ardnived deleted the feat/container-responsive branch August 11, 2026 17:46
Ardnived added a commit that referenced this pull request Aug 11, 2026
Two conflicts, both from #146 editing the very sections this branch moved.

README.md — #146 enriched the inline sizing section with #107's
container-responsive behaviour; this branch had replaced that block with a
pointer to docs/embedding.md. Kept the pointer, and ported #146's new facts
INTO the guide's own "Sizing the element" section rather than dropping them:
map-less now adapts to the element rather than the viewport, touch
affordances deliberately follow the device instead, and map mode warns in
the console when it is given a slot it cannot use.

demo.html — #146 added the full-page-slot warning to the same comment where
this branch replaced the dead API key with a placeholder. Kept both: the
warning reads first, then the key instruction. The 1cf076ab literal stays
gone; SahajCloud answers 403 to it, so restoring it would put the harness
back to looking broken for a reason unrelated to the code under test.

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): container-aware responsiveness for embeds

1 participant