Skip to content

fix(player): a cancelled touch ends the seek drag, and the carousels and hooks get their first tests - #299

Merged
sydevs-bot merged 9 commits into
mainfrom
claude/test-carousels-and-hooks
Nov 19, 2026
Merged

sydevs-bot merged 9 commits into
mainfrom
claude/test-carousels-and-hooks

Conversation

@sydevs-bot

@sydevs-bot sydevs-bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Visitors (phones): before this change, if the browser or the system cancelled a touch in the middle of dragging the meditation player's progress ring, the drag never ended. Every later touch anywhere on the page then had preventDefault called on it, so the page could not be scrolled by touch, and the handle jumped to wherever the finger landed. Now a cancelled touch ends the drag and returns the handle to the playing time, without seeking.
  • Developers: ColumnCarousel and ContentCarousel now share one hooks/useCarousel.ts for their Embla wiring, where each used to carry its own copy. Interaction tests pinned both carousels before the refactor, and the same tests pass after it. useCircularProgress, useClipboard and pages/+onBeforeRender.ts get their first tests.
  • Editors: nothing changes.

Findings addressed

  • F12a, carousels. Adds the first jsdom interaction tests for both carousels: components/molecules/ColumnCarousel/ColumnCarousel.interaction.test.tsx (7 tests) and components/molecules/blocks/ContentCarousel/ContentCarousel.interaction.test.tsx (8 tests). jsdom does no layout, so tests/_helpers/embla.ts stands in for the Embla API and reports whatever position each test sets. The stand-in hands the API out the same way embla-carousel-react 8.6.0 does: undefined until the viewport ref attaches, then the API, created in an effect (review fix, below). With main's two carousel files checked out under these tests, all of them pass. Removing 'reInit' from the hook's events fails exactly "re-reads the arrows when the slides change".
  • F15c, duplicated Embla wiring. hooks/useCarousel.ts holds the shared options (align: 'center', slidesToScroll: 1, containScroll: 'trimSnaps'), the three scroll callbacks, and one effect that re-reads position on select, slidesInView and reInit (hooks/useCarousel.ts:43-60). ColumnCarousel passes only startIndex, and ContentCarousel passes only inViewThreshold. ContentCarousel keeps its reInit handling. ColumnCarousel now also listens for reInit, which re-reads the selected column when the slides change. Both stories were checked in Ladle with the real Embla at 390px: dots, nav titles, end-of-row disabling, withdrawn arrows and dimmed slides all behave as before. The existing SSR tests (ColumnCarousel.test.tsx, ContentCarousel.test.tsx, RelatedContent.test.tsx, tests/guards/faded-controls.test.ts) pass unchanged. Changing the initial selectedIndex to 0 fails 4 SSR tests.
  • F12a, useCircularProgress, and the touchcancel bug. The bug was real. Fixed by a touchcancel listener in components/organisms/MeditationPlayer/useCircularProgress.ts:116-125, which clears the previewed position and ends the drag. The hook lives under components/organisms/MeditationPlayer/, not hooks/. New file useCircularProgress.test.ts (6 tests, jsdom) covers: a mouse drag that previews and then seeks once on release, a seek target that holds until currentTime catches up, a touch drag that calls preventDefault and seeks on touchend, and the wraparound guard at the top in both directions. On main, "ends the drag on a cancelled touch, without seeking" fails with expected true to be false. A probe run on main also showed displayTime at 450 instead of 20 after the cancel, and a later touchmove moving the handle to 150.
  • F12a, useClipboard. New file hooks/useClipboard.test.ts (6 tests, jsdom, fake timers) covers the write and its true result, the copied flag with the default and a custom timeout, the timer restarting on a second copy, a refused write and a missing Clipboard API both returning false, and no timer left behind after unmount. Removing either clearTimeout (hooks/useClipboard.ts:43, :58) fails a test. No production change.
  • F12c, pages/+onBeforeRender.ts. Re-verified that main had no test for it. New file pages/onBeforeRender.test.ts (no + prefix, per docs/rules/testing.md), 4 tests. It mocks loadTranslations and loadLivePreview but keeps the real toClientState and LIVE_PREVIEW_OFF. It pins that both reads receive the pageContext, that the translations and the client preview state come back, that the preview token never reaches the serialised result, and that the result falls back to EN_TRANSLATIONS with no preview when either read throws. Returning the session instead of toClientState(session) (pages/+onBeforeRender.ts:37) fails 2 tests. No production change.
  • Review fix: the Embla stand-in handed its API out on the first render. So no test reached the hook's if (!emblaApi) return guard (hooks/useCarousel.ts:44). With that guard removed, all 37 carousel tests used to pass, although both carousels would throw a TypeError in a browser. Now the same mutation fails all 15 carousel interaction tests. Removing ContentCarousel's ref={emblaRef} now fails 6 of them.
  • Review note: what Embla already handles. A review asked whether any of this wiring could be dropped for Embla's built-ins, and whether a newer Embla would help. Three lines can: align: 'center', slidesToScroll: 1 and containScroll: 'trimSnaps' are Embla 8.6.0's own defaults. They stay as a deliberate pin, and hooks/useCarousel.ts now says so at the site. Nothing else drops. embla-carousel-react exports one hook, useEmblaCarousel, returning [ref, api | undefined] and no state of its own (node_modules/embla-carousel-react/index.d.ts), so the subscription effect is the whole React binding; every getter it reads — selectedScrollSnap, slidesInView, canScrollPrev, canScrollNext — is already a built-in. Deriving ColumnCarousel's nav bounds from canScrollPrev/canScrollNext instead of the column count fails 7 tests, because the server render has no Embla to ask. embla-carousel-class-names would move ContentCarousel's dimming to an is-in-view class, but the click-to-scroll on a dimmed slide reads the same flag, so the React state stays and the plugin only adds parts. Updating gains nothing either: 8.6.0 (April 2025) is the latest stable and is what the lockfile resolves; 9.0.0 has been in release candidates since January 2026 (rc04, October 2026), with renamed methods, options and events.
  • Review note: slide index vs snap index. Embla's scrollTo takes a snap index, and trimSnaps puts every slide that fits at the start of the row on snap 0. The hook's scrollTo parameter is now named snap, and its doc comment says which indexes are snaps and which are slides. ContentCarousel's click-to-scroll passes a slide index, so it now carries a shortcut: line (ContentCarousel.tsx:190-192). The interaction test states the one-snap-per-slide assumption behind its scrollTo(2) assertion. ColumnCarousel's full-width slides each get their own snap, so its dots are unaffected.

Not in this PR

  • ContentCarousel's slide-to-snap mapping. On a viewport wide enough that several leading slides share snap 0, clicking a dimmed slide scrolls past it, so a dimmed slide on the left can stay clipped. Main has the same behaviour (its ContentCarousel already set trimSnaps). Fixing it means mapping the slide through emblaApi.internalEngine().slideRegistry, as Embla's own SlideFocus does, and checking the result in a browser at a wide viewport. That is a behaviour change, so it is left for a follow-up and marked in the code with a shortcut: line.
  • Other F12a targets (FormBuilder, Dropdown, Accordion, MeditationPlayer effects, useAudioPlayer) belong to the forms, a11y and audio bundles.
  • Other F12c modules (related routes, preview discovery, sahajcloud-context, _lecture.ts, _meditation.ts) belong to other bundles or open PRs.
  • No translation key is needed. This PR adds no visitor-facing string.

Reconciled with open PRs

None of the open PRs touches any file this PR changes. Each branch's diff was checked against ColumnCarousel*, ContentCarousel*, hooks/useCarousel.ts, useCircularProgress*, useClipboard*, onBeforeRender* and tests/_helpers/embla.ts.

Test results

Results from .claude/skills/pr-prep/check.sh on the pushed head:

  • Lint: 0 errors, 1087 warnings. No warning sits on a line this PR writes; the count moved with the main merge, not with this branch.
  • tsc --noEmit: passed.
  • vitest run: 136 files, 1306 of 1306 tests passed.
  • pnpm build: not run, because this bundle is not marked BUILD.

main was merged into the branch at ad54db0, cleanly and with no conflict, so the gate above ran on the merged tree.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw

The carousels' server render was covered, but nothing ran their effects:
which slide Embla reports, which events they subscribe to, what a click
asks of Embla, and whether the listeners leave on unmount. A stand-in for
the Embla API (tests/_helpers/embla.ts) answers what each test sets,
since jsdom lays nothing out and the real engine never scrolls there.

ContentCarousel's reInit test fails with that subscription removed, so
items that load after mount keep their arrows right. These tests come
before extracting the shared wiring into one hook, and must hold across it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
…wiring

ColumnCarousel and ContentCarousel each spelled out the same Embla setup:
the centred one-at-a-time options, three scroll callbacks, and an effect
that reads the position once the API exists and again on every event.
hooks/useCarousel.ts now owns that, and each carousel passes only the
option it adds (startIndex, inViewThreshold) and reads the state it draws.

The hook keeps ContentCarousel's reInit subscription, so items that load
after mount still re-read the arrows and the in-view slides. ColumnCarousel
now hears reInit and slidesInView too: the first re-reads the selected
column when the slides change, the second costs a re-render while
scrolling and nothing else.

The interaction tests from the previous commit pass unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
The progress handle listened for touchend and mouseup but not touchcancel,
which the browser sends when the system takes a touch back mid-gesture.
The drag then stayed on: the window kept its non-passive touchmove
listener, so the next touch anywhere on the page called preventDefault
and could not scroll, and it moved the handle and the video frame to
wherever that finger went, seeking there on its touchend.

A cancelled touch now ends the drag and drops the previewed position, so
the handle returns to the playing time. Nothing was released, so nothing
is seeked.

These are the hook's first tests: mouse and touch drags, the seek on
release, the hand-over to the player's time, and the wraparound guard at
the top of the ring. The touchcancel test fails without the fix (the drag
stays on, a later touchmove is prevented and moves the handle).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
EmbedButton's copy feedback rests on this hook, and nothing ran it: the
write and its result, the copied flag's timeout, the restart on a second
copy, the refused write and the missing Clipboard API, and the timer an
unmount must clear. Removing either clearTimeout fails a test.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
This hook puts the locale's strings on every route, error page included,
and passToClient serialises what it returns into the page. Nothing ran
it. The tests pin the two reads it hands pageContext to, that the preview
token never reaches the result (handing back the session itself fails
them), and the English, no-preview fallback when either read throws.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
embla-carousel-react returns `undefined` until the viewport ref attaches
and its own effect creates the API. The stand-in returned an API on the
first render, so the carousel tests never reached useCarousel's
`if (!emblaApi) return` guard: removing it left all 37 carousel tests
green while both carousels would throw in a browser.

The stand-in now waits for the ref to attach and creates the API in an
effect, as the real hook does. With the guard removed, all 15 carousel
interaction tests fail; with ContentCarousel's `ref={emblaRef}` removed,
6 fail.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
Embla's scrollTo takes a snap index, and `trimSnaps` puts every slide
that fits at the start of the row on snap 0. ColumnCarousel's full-width
slides each get a snap of their own, so its dots are right. ContentCarousel
passes a clicked slide's index, which overshoots once a wide viewport
merges leading slides. That predates the hook (main's ContentCarousel set
trimSnaps too), so it is marked as a shortcut here rather than changed
in a test bundle; the test names the one-snap-per-slide assumption it
relies on.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjZcE8bs5uRJ6dsg6kw
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
wemeditate-design b770b6f Commit Preview URL

Branch Preview URL
Nov 19 2026, 10:55 PM

@sydevs-bot
sydevs-bot enabled auto-merge November 19, 2026 21:15
Comment thread hooks/useCarousel.ts Resolved
@sydevs-bot sydevs-bot added the bot:working Lock: a cloud session is running on this item. Removed when it ends. label Nov 19, 2026
@sydevs-bot

sydevs-bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

🤖 no session running

recent dispatches
  • 22:48Z address-review · attempt 1 · session · done
  • 22:48Z address-review · attempt 1 · session

Written by the sydevs dispatcher. Sessions never edit this comment.

@sydevs-bot sydevs-bot moved this from Awaiting to Working in SYDevelopers Technical Roadmap Nov 19, 2026
A review asked whether any of this wiring could be dropped in favour of
Embla's built-in handling. `align`, `slidesToScroll` and `containScroll`
are the only lines that can: all three are Embla 8.6.0's own defaults.
They stay because both carousels read them as part of their contract --
`align: 'center'` is ColumnCarousel's centre start, and `trimSnaps` is
the snap-vs-slide hazard the hook's doc comment owns -- and a default is
the maintainer's to change in a major. Say so at the site, so the next
reader does not have to ask again.

Co-Authored-By: Claude Opus 5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01Mg9rjVdrFdreoK86VEaswY
@sydevs-bot

Copy link
Copy Markdown
Contributor Author

Addressed the Embla thread, left open for you to settle.

Dropped what can be. align, slidesToScroll and containScroll are Embla 8.6.0's own defaults. They stay as a deliberate pin, and b770b6f says so at the site.

Kept the rest, with evidence. embla-carousel-react exports one hook and no state, so the effect is the whole React binding, and every getter it reads is a built-in. Deriving ColumnCarousel's nav bounds from canScrollPrev fails 7 tests — the server render has no Embla to ask. embla-carousel-class-names would move the dimming to a class, but the click-to-scroll reads the same flag, so the state stays.

Updating gains nothing. 8.6.0 is the latest stable and what the lockfile resolves. 9.0.0 has been in RC since January, with renamed methods, options and events.

main merged in cleanly at ad54db0. Gate on the merged tree: 0 lint errors, types pass, 1306/1306 tests.

🤖 Written by the sydevs autonomous loop — see what this is


Generated by Claude Code

@sydevs-bot
sydevs-bot added this pull request to the merge queue Nov 19, 2026
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
wemeditate-web b770b6f Commit Preview URL

Branch Preview URL
Nov 19 2026, 10:55 PM

@sydevs-bot sydevs-bot moved this from Awaiting to Pending in SYDevelopers Technical Roadmap Nov 19, 2026
Merged via the queue into main with commit 54d8684 Nov 19, 2026
31 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

3 participants