Skip to content

fix(ui): upgrade swiper to v12 and add a carousel pause control - #119

Merged
Ardnived merged 6 commits into
mainfrom
fix/swiper-carousel
Aug 7, 2026
Merged

Ardnived merged 6 commits into
mainfrom
fix/swiper-carousel

Conversation

@Ardnived

@Ardnived Ardnived commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Closes #104

Two things in one ticket because they share ImageCarousel.tsx: a CRITICAL advisory that needed a major bump, and the WCAG 2.2.2 failure in the component that bump touches.

1. swiper 11.2.1 → 12.2.0 — the critical advisory is cleared

GHSA-hmx5-qpq5-p643 (prototype pollution, vulnerable >=6.5.1 <12.1.2) was the repo's only critical. pnpm audit --prod now reports 0 critical (was 1); 64 advisories → 63. The waiver naming this ticket is removed from scripts/audit-baseline.json — the weekly --strict run fails on a waiver whose advisory has been fixed, so a stale one would have gone red.

The v12 migration turned out to be a version number and nothing else. Its breaking changes are LESS/SCSS sources dropped (we import the CSS), SVG navigation icons (we register no Navigation module), and tighter types. swiper/react and all three CSS entry points (swiper/css, /a11y, /pagination) are unchanged, so src/styles/globals.css needed no edit and the .sy-carousel pagination theming still matches v12's DOM. The upstream fix is a noExtend = ['__proto__','constructor','prototype'] filter on the param-merge helper our <Swiper> props flow through.

Not taken: v14, which exists and is also patched, but is a second major (browser-baseline raise) and is not what the ticket scoped.

The eager payload got smaller: 481.8 → 479.2 KiB standalone, 483.3 → 480.7 KiB embed (budget 495). Worth knowing for #96, which is lowering that budget concurrently.

2. The carousel can be stopped

The carousel autoplayed at 4s with disableOnInteraction: false and offered no way to stop it, so the only way to read a caption under it was to out-pace it.

  • A toggle button over the image, keyboard-operable, localized across all 10 locales. The accessible name stays put and aria-pressed carries the state — a name flipping "Pause"/"Play" beside aria-pressed announces the state twice and disagrees with itself doing it. Only the glyph swaps.
  • Under prefers-reduced-motion: reduce autoplay never starts (the repo's first reduced-motion support) and the control does not render, because there is nothing to pause. Images stay reachable by swipe and by the bullets: the whole carousel minus the motion nobody asked for.
  • Pressing pause calls autoplay.stop(), not pause() — that distinction is what satisfies "interacting must not silently restart it". stop() clears running, and every one of swiper's interaction handlers (touch, transition end, pagination click, tab visibility) early-returns on !running. The guarantee is structural, not something we watch for.
  • The declarative autoplay prop only decides whether autoplay starts at init — swiper's React wrapper merges changed params but never starts/stops (updateSwiper) — so later changes are applied in an effect that compares against running.

3. Not in the ticket: the v12 CSS broke the scope gate, and the gate had a hole

Swiper 12 ships native CSS nesting (the consequence of dropping its LESS/SCSS sources). The scoping pass correctly leaves a nested rule to its parent's prefix — and then the minifier, which runs after us, flattens the nesting and folds the scope into the middle or the subject of the selector:

.swiper-pagination-disabled > :is(:where(.sy-atlas) .swiper-pagination)

15 selectors like this. All correctly confined; the head-anchored check called every one a host-page leak and failed pnpm build. So isSelectorScoped now asks the question the pass has always been for — is the element this rule paints inside the widget? — instead of the proxy it was using. Note the shape above: no test that looks at the head of the string can accept it, because the scope legitimately lives in the subject.

Probing that predicate adversarially then found a real hole, which predates this branch: .sy-atlas ~ .foo was accepted as confined. It is not — it styles a sibling of the widget root, an arbitrary host element. The head fast path only ever checked that the scope led the selector. Nothing emits that shape, so nothing was leaking; the risk was a hand-written rule in globals.css, which the transform passes through untouched and the gate would then have waved through. Fixed, and the branch had made it incoherent anyway — it added an explicit refusal of sibling combinators in the subject walk, with a comment on why it was necessary, right beside a path that accepted them.

✓ assert-css-scoped: 1133 rules across 4 injected stylesheets confined to .sy-atlas.

Verification

Gates: lint · typecheck · test:run (677) · build (incl. assert-css-scoped) · size · ladle:build · audit:check (also clean under --strict).

Browser-verified in Ladle (Playwright, real emulateMedia), because none of this is expressible in the node lane:

result
Autoplay advances 1→2→0 at ~4s
Pause (via Enter, keyboard) aria-pressed=true, glyph swaps, 0 advances in 10s, focus retained
Pagination click + pointer drag while paused still 0 advances in 10s — no silent restart
Resume advances again
Reduced motion, flipped ON live control disappears, motion stops
Reduced motion, flipped OFF live control returns, motion resumes
Reduced motion, fresh load no control, 0 advances, bullets still navigate manually
Single slide no autoplay, no bullets, no control
Slide tap lightbox opens with the right caption
Console 0 errors, 0 warnings

Measured rather than assumed (per .claude/rules/code-style.md on inert Tailwind classes): the control computes to 32×32, rgba(0,0,0,.5), a 2px ring-focus ring, and end-2 → inset-inline-end: 8px (logical, so it mirrors under RTL).

Review passes

/simplify completed — 8 findings applied, most valuably a missing data-vaul-no-drag: the carousel renders on the vaul sheet, which reads a tap with any micro-movement as a drag and swallows the click, so the one control this PR exists to add would have fired only intermittently on touch. A spec pins it now, since losing it again is invisible to every other gate. That pass also moved usePrefersReducedMotion to src/hooks/use-reduced-motion.ts and rebuilt it on react-responsive — the mechanism config/responsive.ts already uses — replacing a hand-rolled matchMedia subscription that, being a local copy, had skipped the environment guarding the widget's other preference reader carries.

/code-review and /security-review did not complete — both subagents died on API errors during a platform instability window, and per the coordinator were not re-dispatched further. The security-relevant surface (the scoping predicate) was instead triaged inline and empirically: 28 adversarial selectors run against the real predicate, covering :not(), :has(), :nth-child(… of …), empty/unscoped :is() branches, case variants, attribute selectors, prefix collisions (.sy-atlas-thing), and both failure paths (the gate accepting a leak, and scopeSelector wrongly skipping a prefix). That is what found the sibling hole above. All 28 now behave as intended and are pinned in the spec. A human reviewer may still want a fresh pass on scripts/postcss-scope-widget.mjs.

Unsigned commits — the 1Password SSH agent had no identities loaded this session.

Ardnived and others added 6 commits August 6, 2026 21:44
…tring

The CSS scoping pass is not the last thing to touch a selector. Native CSS
nesting is flattened downstream of it, by the minifier, and flattening moves the
scope off the head of the string without moving it out of the selector — so the
head-anchored `isSelectorScoped` read correctly-confined CSS as a host-page leak
and failed the build.

Swiper 12 is what surfaced it (it dropped its LESS/SCSS sources for nested CSS),
in two families, fifteen selectors:

    :is(<scoped>, <scoped>) .swiper-lazy-preloader
    .swiper-pagination-disabled > :is(<scoped>)

The second is the one that settles the design: no test that looks at the head of
the string can accept it, because the scope legitimately lives in the SUBJECT.
So ask the question the pass has always been for — is the element this rule
PAINTS necessarily inside the widget? — for which the head of the string was
only ever a proxy. Walk left from the subject compound through ancestor steps
and look for a compound that pins itself to the scope.

It stays a fix rather than a hole because every branch of an `:is()` must be
scoped (one unscoped branch is a way out of the widget) and because only
descendant/child combinators are followed: a sibling combinator also happens to
confine the subject in everything we emit, but that argument leans on the scoped
part being a strict descendant of the scope root, which is too fine a
distinction to rest a host-page guarantee on. Nothing needs it, so it is
refused.

The emitted bytes are unchanged — the specificity of every flattened form still
matches the unscoped original, because `:where()` continues to contribute zero.

Closes #104

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
GHSA-hmx5-qpq5-p643 (prototype pollution, `>=6.5.1 <12.1.2`) was the repo's only
CRITICAL, and patching it needed a major. `pnpm audit --prod` now reports 0
critical, so the baseline waiver naming this ticket is removed with it — the
weekly `--strict` run fails on a waiver whose advisory has been fixed, which is
how a stale one prunes itself.

The fix upstream is a `noExtend` list on the param-merge helper, which is the
code path our `<Swiper>` props flow through.

The v12 migration is a version number and nothing else. Its breaking changes are
LESS/SCSS sources dropped (we import the CSS), SVG navigation icons (we have no
Navigation module) and tighter types; `swiper/react` and all three CSS entry
points — `swiper/css`, `/a11y`, `/pagination` — are unchanged, so
`src/styles/globals.css` needed no edit and the `.sy-carousel` pagination
theming still matches v12's DOM.

Not taken: v14, which exists and is also patched, but is a second major
(browser-baseline raise) and is not what the ticket scoped.

The eager payload gets slightly SMALLER: 481.8 → 479.3 KiB standalone,
483.3 → 480.7 KiB embed.

Closes #104

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
WCAG 2.2.2 (Pause, Stop, Hide): anything that moves for more than five seconds
needs a way to stop it. The carousel autoplayed at 4s with
`disableOnInteraction: false` and offered none, so the only way to read a
caption under it was to out-pace it.

- A toggle button over the image, keyboard-operable, localized across all ten
  locales. The accessible name stays put and `aria-pressed` carries the state:
  a name that flipped between "Pause"/"Play" alongside `aria-pressed` would
  announce the state twice and disagree with itself doing it. Only the glyph
  swaps.
- Under `prefers-reduced-motion: reduce`, autoplay never starts — the repo's
  first reduced-motion support — and the control does not render, because there
  is nothing to pause. The images stay reachable by swipe and by the pagination
  bullets: the whole carousel minus the motion nobody asked for.
- Read through `useSyncExternalStore`, not a `matchMedia().matches` at render,
  because the preference CHANGES: turning it on mid-session should settle the
  carousel, not wait for an unrelated re-render.

Pressing pause calls `autoplay.stop()`, not `pause()`. That is the difference
between the two acceptance criteria: `stop()` clears `running`, and every one of
Swiper's interaction handlers — touch, transition end, pagination click, tab
visibility — early-returns on `!running`. So no later interaction can silently
restart what the viewer stopped, structurally rather than by our watching for it.

The declarative `autoplay` prop only decides whether autoplay starts AT INIT:
Swiper's React wrapper merges changed params into the live instance but never
starts or stops it (`updateSwiper`). Every later change is therefore applied in
an effect, which compares against `running` so a repeat can't queue a second
timer — `start()` has no re-entry guard of its own.

Single-slide behaviour is untouched: still a static slide, no autoplay, no
pagination, and now no pause control either.

Closes #104

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- The pause control was missing `data-vaul-no-drag`. The carousel renders on the
  vaul sheet (EventDetails), where a tap carrying any micro-movement is read as a
  drag and the click is swallowed — so the one control this branch exists to add
  would have fired only intermittently on touch, which is exactly where a
  pause affordance earns its keep. The Button atom sets it on every button and
  ActionRow carries it by hand; this now does too, and a spec pins it, since
  losing it again would be invisible to every other gate.
- `usePrefersReducedMotion` moves to `src/hooks/use-reduced-motion.ts` and is
  rebuilt on `react-responsive`'s `useMediaQuery` — the media-query mechanism
  `config/responsive.ts` already uses. That deletes a hand-rolled
  `useSyncExternalStore` + `matchMedia` subscription which, being a local copy,
  had also skipped the environment guarding the widget's other preference reader
  carries: a bare `window.matchMedia` in a `getSnapshot` runs DURING render, so a
  host without it would have taken the whole photo section to an error panel.
  The hook is a `() => boolean` environment read with no carousel knowledge, and
  the repo already keeps single-importer hooks in `src/hooks/`.
- Its docstring records why it is not framer-motion's `useReducedMotion`, which
  is already a dependency: that one reads the preference once at mount. The
  remaining reduced-motion surfaces are framer-motion animations whose natural
  fix is one `<MotionConfig reducedMotion="user">`, and whoever lands it should
  decide about the disagreement rather than discover it.
- `isSubjectConfined` drops two parallel arrays for a single right-to-left scan;
  the combinator/compound pairing was rebuilding order `sel.nodes` already had.
- Two comment corrections, both claims I had not checked. `start()` does not
  queue a second timer (`run()` clears the previous one) — the guard prevents a
  restarted countdown, which is a smaller and truer reason. And refusing sibling
  combinators is NECESSARY, not fastidious: a bare `.sy-atlas` counts as a scope
  token, so crediting siblings would accept `:is(:where(.sy-atlas)) ~ .b`, and a
  sibling of the scope ROOT is an arbitrary host element.
- The scope gate's failure message no longer asserts a leak outright. A refusal
  can also be a shape the check declines to credit — `swiper/css/navigation`
  would produce one the day someone adds arrows — and this branch already spent
  a day looking for a leak that a flattened-but-confined selector did not have.

Closes #104

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
- `.claude/rules/components.md` described the scoping pass as "rewrites every
  emitted selector to `:where(.sy-atlas)`", which stopped being the enforced
  invariant this branch. What the gate checks is that the element a rule PAINTS
  is inside the widget; those coincided only until a dependency shipped nested
  CSS the minifier flattens after us. The rule now says so, names the fact that
  we are not the last stage to rewrite a selector, and warns that a red gate can
  mean "not confined" rather than "leaks" — otherwise the next contributor reads
  the stale model first and goes looking for a leak that isn't there, which is
  most of what #104 cost.
- The accessibility section gains the two rules this branch had to discover:
  motion needs a stop control and must not start under `prefers-reduced-motion`
  (with the worked example's toggle-button semantics and where the hook lives),
  and a hand-rolled control on the drawer needs `data-vaul-no-drag` or it fires
  only intermittently on touch.
- CLAUDE.md's hooks list gains `use-reduced-motion`.

Closes #104

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

Found by adversarially probing the predicate rather than reasoning about it:
`.sy-atlas ~ .foo` and `:where(.sy-atlas) + .b` were accepted as confined. They
are not. They style a SIBLING of the widget root, which is an arbitrary element
of the host page — exactly the leak this gate exists to stop.

The cause is the head fast path: leading with the scope is not the same as
confining the subject, and the regex only ever checked the former. This predates
the branch — but the branch made it incoherent, adding an explicit refusal of
sibling combinators in the subject walk, with a comment explaining why it is
necessary, immediately beside a path that accepted them anyway. The two now
agree: the fast path declines any selector carrying `~`/`+` and lets the walk
decide.

Nothing emits that shape, so nothing was leaking. What was at risk was a
hand-written `.sy-atlas ~ .foo` in globals.css, which the transform passes
through untouched (correctly — it leads with the scope) and the gate would then
have waved through. Checked: globals.css has no such rule today.

The over-broad `[~+]` test also catches `:nth-child(2n+1)`, which just sends a
rare selector down the slow path; the spec pins that it still resolves to true.
Spec additions cover the sibling shapes and the scope-shaped tokens that do not
confine — `:has()`, `:not()`, `[class~=…]`, `:nth-child(… of …)`, empty `:is()`.

Closes #104

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

Copy link
Copy Markdown

Deploying sahajatlas-design with  Cloudflare Pages  Cloudflare Pages

Latest commit: dbaed9e
Status: ✅  Deploy successful!
Preview URL: https://a6d26c22.sahajatlas-design.pages.dev
Branch Preview URL: https://fix-swiper-carousel.sahajatlas-design.pages.dev

View logs

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying sahajatlas with  Cloudflare Pages  Cloudflare Pages

Latest commit: dbaed9e
Status: ✅  Deploy successful!
Preview URL: https://ae842424.sahajatlas.pages.dev
Branch Preview URL: https://fix-swiper-carousel.sahajatlas.pages.dev

View logs

@Ardnived
Ardnived merged commit 61243e1 into main Aug 7, 2026
5 checks passed
@Ardnived
Ardnived deleted the fix/swiper-carousel branch August 7, 2026 16:19
Ardnived added a commit that referenced this pull request Aug 7, 2026
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]>
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(ui): upgrade swiper to v12 and add carousel pause control

1 participant