Repository navigation
Host core: playback's lifecycle as a state machine, with one stop path - #115
Merged
Merged
Conversation
agorischek
force-pushed
the
host-playback-machine
branch
from
November 20, 2026 23:43
0a52925 to
083f32d
Compare
This was referenced Nov 20, 2026
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved synchronization bugs between controlled props and the playback actor can freeze playback or cause pause, seek, and direction actions to conflict with the displayed state.
4 open issues
What changed in this PR
Moves host-core playback onto the state-machine package introduced in #110, centralizing lifecycle handling and endpoint stopping while preserving the ProjectionController API.
Changes:
- Replaces the actions and frame-loop hooks with a playback lifecycle machine and React adapter.
- Separates timeline calculations from playback state and request handling.
- Adds lifecycle tests and state exploration, and removes obsolete lifecycle-check baseline entries.
| File | Description |
|---|---|
tools/scripts/check-machines/baseline.json |
Removes baseline entries for migrated playback hooks. |
packages/host/core/test/playback-lifecycle.test.mjs |
Tests requests, transitions, endpoint stopping, and lifecycle invariants. |
packages/host/core/src/projection/use-projection.ts |
Integrates the new playback controller. |
packages/host/core/src/projection/playback-position.ts |
Retains timeline and position calculations without lifecycle state. |
packages/host/core/src/projection/playback-loop.ts |
Removes the effect-based frame loop. |
packages/host/core/src/projection/playback-lifecycle.ts |
Defines playback states, events, requests, and frame activity. |
packages/host/core/src/projection/playback-control.ts |
Connects the machine to React, controlled values, and animation frames. |
packages/host/core/src/projection/playback-actions.ts |
Removes the ref-based action handlers. |
packages/host/core/package.json |
Adds the state-machine dependency. |
package-lock.json |
Records the host-core dependency change. |
Review effort: Balanced
agorischek
added a commit
that referenced
this pull request
Nov 21, 2026
… be shown From the code review on #115. The lifecycle heard what the view shows only when it changed, so a request an embedder declined or hadn't applied yet left the two apart: - The position and a controlled direction are reconciled whenever they differ from the lifecycle's. A declined seek no longer leaves the next play starting from the rejected position, and togglePlayback plays the way `nextDirection` says. - Whether playback is shown playing is reconciled after every render. Pause then play in one event, while playing throughout, plays on. - `paused` is `stopping` from a stop it asked for until the view stops showing playback. An embedder that applies the stop later doesn't see playback start again from the end. If it declines the stop, Pause asks again rather than asking to play. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Playback was spread over two hooks, four effects and nine refs: an optimistic `playingRef`, a direction kept in three places, a `travelled` ref read during render, a float comparison to tell a play the embedder started from one the view asked for, and two separate ways playback stopped at its end. `playbackLifecycle` (playback-lifecycle.ts, on @githubnext/projections-machine) is now the one place: - `paused`, with a play asked for but not yet shown `armed`, or `playing`, frame by frame from its run. - Actions (play, pause, toggle, togglePlayback, seek) and frames are events. What the view shows (playing, the position, a controlled direction, reduced motion, the mode, the subject) arrives as events when it changes. Playing and the position stay requests the core or the embedder applies. - A play the view shows from `armed` plays from it. One the embedder started plays away from an end it is at. - Only a frame stops playback at its end; the view showing the end doesn't stop it a second time. - A play the embedder declines (the next render still shows paused) is asked for again by the next click, instead of being taken for playback that the click pauses. - `travelled` and the direction are state, so the play button's direction renders when they change. usePlaybackControl (playback-control.ts) runs it with useMachine. The frames are an activity of `playing`. It replaces usePlaybackActions and usePlaybackLoop. usePlaybackPosition keeps only the timeline and the position. The controller's API is unchanged. The tests cover the request and echo rules, the single stop, embedder start and decline, reduced motion, and a new subject. An exploration checks that every request leaves playback where it says and that the slider stays in range. The lifecycle baseline loses the three patterns these files had. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
… be shown From the code review on #115. The lifecycle heard what the view shows only when it changed, so a request an embedder declined or hadn't applied yet left the two apart: - The position and a controlled direction are reconciled whenever they differ from the lifecycle's. A declined seek no longer leaves the next play starting from the rejected position, and togglePlayback plays the way `nextDirection` says. - Whether playback is shown playing is reconciled after every render. Pause then play in one event, while playing throughout, plays on. - `paused` is `stopping` from a stop it asked for until the view stops showing playback. An embedder that applies the stop later doesn't see playback start again from the end. If it declines the stop, Pause asks again rather than asking to play. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
agorischek
force-pushed
the
host-playback-machine
branch
from
November 21, 2026 01:40
08b201a to
78a9788
Compare
This was referenced Nov 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Stacked on #110, which adds
@githubnext/projections-machine. Review the last commit; this retargets tomainonce #110 merges.Why
Playback's lifecycle was implicit, spread across
usePlaybackActions,usePlaybackLoopandusePlaybackPosition: four effects, nine refs, and transitions made in callbacks, effects and during render. The code review survey found:playingRefthat drifts from the view. If a controlled embedder declined a play, the next click on the single play button paused instead of asking again.travelledas a ref read during render, so the play button's direction could render stale.What changes
playbackLifecycleinprojection/playback-lifecycle.tsis the single owner:paused, holding a play that was asked for but isn't shown yet asarmed; orplaying, which advances frame by frame from its run. The frames are an activity ofplaying.play,pause,toggle,togglePlayback,seek) and frame ticks are events. So is what the view shows, sent when it changes: playing, the position, a controlled direction, reduced motion, the mode and the subject. Playing and the position remain requests, applied by the core or by the embedder that controls them.usePlaybackControlinprojection/playback-control.tsruns the machine withuseMachineand replaces the old actions and loop hooks.usePlaybackPositionnow keeps only the timeline and position. TheProjectionControllerAPI is unchanged.There is one deliberate behaviour change. When the embedder keeps controlled
playingon across a subject change,travelledstays true, because playback continues to travel. Previously it was reset while playback continued.Tests
test/playback-lifecycle.test.mjs:exploreover three plans (pause holds, looping, timeline), checking that the slider stays in range, that playing implies travelled, that a stop request leaves playback paused and disarmed, that a play request arms, and that a non-looping frame reaching its end stops. It runs withcomplete: true.The exploration found a case that broke "playing implies travelled" (a subject change while the embedder keeps playing). That case drove the
travelledchange above.Verification
tools check --fastpasses. The lifecycle baseline drops by 3.tscpasses for host core and its browser configuration.host.spec.tscontrolled playback,holds.spec.ts) are left to CI.