fix(frontend): four state defects the deep-review found in the E27 S2 sweep
Every one of them is the same shape: a value derived correctly, and a WRITE to the thing it derives from left unattended. Deriving hides a stale value; it does not consume it. PlayerModal — the watch toggle inherited the previous video's auto-watch. Moving the queue-advance sync into render was right for `currentVideoId`, but the same block also synced `status`, and that one had an ordering constraint of its own: useYtProgress's cleanup for the OUTGOING item can still call setWatched(true) near the end of a clip, and cleanups run after the commit. As an effect the sync landed last and corrected it; from render it lands first and the stray write wins. Press Next in the final ten seconds and the NEXT video showed as watched — one click on the toggle then sent onState(next, "new") for an item already new. Fixed by keying the mirror to the id it describes, so a write for another item is ignored rather than displayed, and no ordering has to be argued about at all. ChannelsProvider — a focus-channel intent was masked by the page rather than consumed, and nothing ever cleared it. The manager is a page chunk: it unmounts on every navigation, and its seed effect runs again on each mount, so returning to it re-applied a channel name from earlier in the session over whatever the user had typed since. The consumed marker now lives in the provider, keyed on the token — which also closes the case the old clear-on-leave effect never handled, opening a channel page (that does not change `page` at all). TagFilterChips + ChannelTags x2 — `open = openRaw && hidden > 0` hides the overflow popover when the lane stops overflowing, but floating-ui only reports a close for a real event on a mounted surface, so the raw flag stayed true and the menu came back by itself on the next re-fit — a window resize or the text-size slider is enough, with nobody near it. The flag is now reset in render against the same condition that hides it. Avatar + downloadRow — remembering a failed image BY URL fixed the recycled-row frame but never forgot it, so a transient 429 pinned a channel to its initial for the life of the instance, never re-requesting. The memory is now dropped once `src` moves off it, which keeps both properties. And playerModalHooks' last exhaustive-deps suppression claimed "nothing in the body reads a render value" while reading five. The invariant that is actually load-bearing is that each of them is a per-item snapshot — written down instead. All four fixes are mutation-checked: each new test was seen red, against the fixed line only, naming the real defect.
This commit is contained in:
@@ -351,3 +351,53 @@ describe("PlayerModal — the dialog contract", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// --- the watch toggle belongs to the item it describes -------------------------------------------
|
||||
// A late writer exists by construction: useYtProgress's cleanup for the OUTGOING item runs after the
|
||||
// commit that already advanced `active`, and within the finish margin it auto-marks that item
|
||||
// watched. While the mirror was a bare boolean that write landed last and painted the INCOMING item
|
||||
// as watched. Keying the mirror by id makes the stray write not this item's, so it is ignored.
|
||||
describe("PlayerModal — the watch toggle after a queue advance", () => {
|
||||
const A = vid("A", 0);
|
||||
const B = vid("B", 0);
|
||||
|
||||
beforeEach(() => {
|
||||
vi.spyOn(api, "videoDetail").mockReturnValue(new Promise(() => {}));
|
||||
vi.spyOn(api, "saveProgress").mockImplementation(async (id: string) => ({
|
||||
video_id: id,
|
||||
position_seconds: 0,
|
||||
}));
|
||||
});
|
||||
|
||||
it("does not inherit the outgoing item's auto-watch when stepping away near the end", async () => {
|
||||
const onState = vi.fn();
|
||||
clock.current = 2995; // inside min(FINISH_MARGIN, duration/2) = 10s of 3000
|
||||
renderModal(
|
||||
<PlayerModal video={A} queue={[A, B]} startIndex={0} onClose={() => {}} onState={onState} />,
|
||||
);
|
||||
await waitFor(() => expect(lastStart()?.videoId).toBe("A"));
|
||||
|
||||
next();
|
||||
await waitFor(() => expect(lastStart()?.videoId).toBe("B"));
|
||||
await settle();
|
||||
|
||||
// A really is marked watched — that part is correct and must keep working.
|
||||
expect(onState.mock.calls).toContainEqual(["A", "watched"]);
|
||||
// B is not, and its toggle says so. Before the fix both toggles read "watchedUnmark" here.
|
||||
expect(screen.queryAllByTitle("player.watchedUnmark")).toHaveLength(0);
|
||||
expect(screen.queryAllByTitle("player.markWatched").length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it("still reflects a watch toggled on the item you are actually on", async () => {
|
||||
const onState = vi.fn();
|
||||
clock.current = 0;
|
||||
renderModal(
|
||||
<PlayerModal video={A} queue={[A, B]} startIndex={0} onClose={() => {}} onState={onState} />,
|
||||
);
|
||||
await waitFor(() => expect(lastStart()?.videoId).toBe("A"));
|
||||
|
||||
fireEvent.click(screen.getAllByTitle("player.markWatched")[0]!);
|
||||
expect(onState.mock.calls).toContainEqual(["A", "watched"]);
|
||||
expect(screen.queryAllByTitle("player.watchedUnmark").length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user