-
Notifications
You must be signed in to change notification settings - Fork 31
Onboarding v4: design feedback round 2 #2440
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 6 commits
c4ae2b7
63a4b96
8d8e58b
b59639f
b908a49
e16f0be
131f4b0
093bf0f
f0abb5e
25615c8
fee4e6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -74,6 +74,8 @@ function DuckPlayerDefault({ advance }) { | |
| const videosRef = useRef(/** @type {Record<DPTarget, HTMLVideoElement | null>} */ ({ with: null, without: null })); | ||
|
|
||
| const [state, setState] = useState(/** @type {DPState} */ ({ target: 'with', phase: 'initial', reverse: false })); | ||
| const stateRef = useRef(state); | ||
| stateRef.current = state; | ||
|
|
||
| /** @type {(target: DPTarget) => DPTarget} */ | ||
| const flip = (target) => (target === 'with' ? 'without' : 'with'); | ||
|
|
@@ -89,12 +91,14 @@ function DuckPlayerDefault({ advance }) { | |
| return; | ||
| } | ||
| video.currentTime = 0; | ||
| /** @type {Promise<void>} */ | ||
| const frameReady = new Promise((resolve) => video.requestVideoFrameCallback(() => resolve())); | ||
noisysocks marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| try { | ||
| await video.play(); | ||
| } catch (error) { | ||
| // Ignore errors - we can assume that our browsers support playback | ||
| console.error(error); | ||
| } | ||
| await frameReady; | ||
noisysocks marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| /** @param {HTMLVideoElement | null} video */ | ||
|
|
@@ -114,7 +118,7 @@ function DuckPlayerDefault({ advance }) { | |
| return () => clearTimeout(id); | ||
| }, []); // exclude isReducedMotion from deps — must not re-fire if reduced motion changes after mount | ||
|
|
||
| const toggle = () => { | ||
noisysocks marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const toggle = async () => { | ||
| const { target, phase, reverse } = state; | ||
| if (phase === 'initial') { | ||
| // Queue or cancel a reverse so auto-play will switch to "without" once the "with" video ends | ||
|
|
@@ -124,18 +128,19 @@ function DuckPlayerDefault({ advance }) { | |
| if (!reverse) reset(videoFor(flip(target))); | ||
| setState({ target, phase: 'playing', reverse: !reverse }); | ||
| } else { | ||
| // Settled: switch to the other video | ||
| // Settled: play the other video, wait for its first frame, then switch visibility | ||
| const next = flip(target); | ||
| play(videoFor(next)); | ||
| await play(videoFor(next)); | ||
| setState({ target: next, phase: isReducedMotion ? 'settled' : 'playing', reverse: false }); | ||
| } | ||
| }; | ||
|
|
||
| const end = () => { | ||
| if (state.reverse) { | ||
| // A reverse was queued — play the other video now | ||
noisysocks marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Async toggle/end creates state machine race conditionMedium Severity Making Additional Locations (1) |
||
| const next = flip(state.target); | ||
| play(videoFor(next)); | ||
| const end = async () => { | ||
| const { reverse, target } = stateRef.current; | ||
| if (reverse) { | ||
| // A reverse was queued — play the other video, wait for its first frame, then switch | ||
| const next = flip(target); | ||
| await play(videoFor(next)); | ||
| setState({ target: next, phase: 'playing', reverse: false }); | ||
| } else { | ||
| // No reverse — just settle on the current video | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -41,7 +41,8 @@ | |
| position: absolute; | ||
| top: 0; | ||
| left: 0; | ||
| visibility: hidden; | ||
| opacity: 0; | ||
| pointer-events: none; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
|
|
||
| .titleContainer { | ||
| position: relative; | ||
| align-self: stretch; | ||
| } | ||
|
|
||
| .title { | ||
|
|
||


Uh oh!
There was an error while loading. Please reload this page.