Skip to content

Add a beforeShot hook that runs after the page settles - #85

Merged
tmashara merged 2 commits into
mainfrom
claude/issue-71-before-shot
Oct 29, 2026
Merged

tmashara merged 2 commits into
mainfrom
claude/issue-71-before-shot

Conversation

@tmashara

Copy link
Copy Markdown
Owner

What

A new beforeShot hook. It works like before, but it runs after the page settles, right before the masks and the shot.

Why

A before hook runs before the settle's scroll pass, so it can't keep a state that scrolling changes. A scroll-spy nav, for example, is left on its last section by the time the shot is taken (#71). A beforeShot hook sets that state after the scroll pass.

Semantics

  • It has the same signature as before: (page, { side, route, width }). It can be set per route (routes[i].beforeShot) or at the top level.
  • Precedence works per key: a route's own beforeShot replaces the top-level one. A route with its own before still gets the top-level beforeShot.
  • It runs in capture() after the whole settle (scroll pass, image decode, fonts, network idle, the late freezeVideo/neutralizeCss) and before the selector, mask and text reads and the stability shots. Nothing settles again after it, so the docs say to await what it changes. On a selector route, the element is still scrolled into view after it.
  • When it throws, the route errors with beforeShot hook failed on <side>: …, a HookError. It is never retried. A hung hook times out at beforeShot hook, also not retried. The step label goes back to settle afterwards, so a later read that hangs is still retried.
  • The recheck and the unsettled retry both go through capture, so the hook runs there too.

Behaviour changes

  • The report card badge before hook is now hook, since it also marks beforeShot-only routes. results.json keeps hook: true.
  • shotId includes beforeShot, so existing --cache-right recordings miss once and get re-recorded (1h TTL anyway). Without that, a hook that makes requests would replay a recording that lacks them.
  • The duplicate-route message now says "different hooks" instead of "different before hooks".

How tested

  • New guard-rail fixture scroll-spy: the nav keeps whichever section the last scroll event saw, and Soon's status text differs per side.
  • New visual tests:
    • before clicking Soon is undone by the scroll pass (diff 0). This guards the fixture.
    • A route beforeShot clicking Soon shows each side's own text, overrides a throwing top-level hook, and isn't flagged varies on the recheck.
    • A throwing beforeShot errors and isn't retried.
    • A hung beforeShot times out at beforeShot hook and isn't retried.
  • Unit tests: validation of beforeShot (top level and per route), the dedupe message, and shotId differing when a beforeShot is set.
  • With src/capture.ts reverted, the 3 beforeShot tests fail and the guard still passes. With the change, they pass.
  • typecheck, lint and format:check are clean. npm test passes (317) and npm run test:visual passes (341).

Fixes #71

🤖 Generated with Claude Code

tmashara and others added 2 commits October 29, 2026 19:21
A before hook runs ahead of the scroll pass, so state the scroll changes
(a scroll-spy nav) can't be held. beforeShot has the same signature and
precedence and runs right before masks and the shot.

Fixes #71

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tmashara
tmashara merged commit 8fec1c9 into main Oct 29, 2026
3 checks passed
@tmashara
tmashara deleted the claude/issue-71-before-shot branch October 29, 2026 18:35
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.

beforeShot hook: run after the scroll pass, right before the shot

1 participant