mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-25 16:37:32 +00:00
fix(studio): a deleted clip's focus fallback no longer re-renders every player store subscriber (#8633)
* fix(studio): a deleted clip's focus fallback no longer re-renders every player store subscriber * fix(studio): keep the focus coordinator's doc comment and fallow marker on the coordinator
This commit is contained in:
@@ -150,17 +150,27 @@ describe("useTimelineFocusCoordinator", () => {
|
||||
expect(document.activeElement).not.toBe(externalTarget);
|
||||
});
|
||||
|
||||
it("persists a deterministic parent-row fallback when a focused clip disappears", async () => {
|
||||
it("moves focus to the parent row when a focused clip disappears, writing the store only on unmount", async () => {
|
||||
usePlayerStore.getState().requestTimelineFocus(clipId);
|
||||
await act(async () => root.render(<Harness />));
|
||||
const writes: string[] = [];
|
||||
const off = usePlayerStore.subscribe((now, was) => {
|
||||
if (now.timelineFocus !== was.timelineFocus) writes.push(now.timelineFocus?.id ?? "none");
|
||||
});
|
||||
|
||||
const collapsedRows: readonly TimelineLogicalRow[] = [{ ...rows[0]!, items: [] }];
|
||||
await act(async () => root.render(<Harness logicalRows={collapsedRows} mountedId={rowId} />));
|
||||
expect(usePlayerStore.getState().timelineFocus?.id).toBe(rowId);
|
||||
expect(document.activeElement?.getAttribute("data-timeline-focus-id")).toBe(rowId);
|
||||
// A write right after the delete's commit makes every player-store subscriber render once more for nothing.
|
||||
expect(writes, "no store write while the timeline is mounted").toEqual([]);
|
||||
|
||||
act(() => root.unmount());
|
||||
off();
|
||||
expect(usePlayerStore.getState().timelineFocus?.id, "a remount keeps the row").toBe(rowId);
|
||||
root = createRoot(host);
|
||||
});
|
||||
|
||||
it("persists the next surviving row when both a clip and its parent track disappear", async () => {
|
||||
it("moves focus to the next surviving row when both a clip and its parent track disappear", async () => {
|
||||
const nextRowId = timelineTrackRowId(2);
|
||||
const nextRow: TimelineLogicalRow = {
|
||||
...rows[0]!,
|
||||
@@ -173,8 +183,10 @@ describe("useTimelineFocusCoordinator", () => {
|
||||
|
||||
await act(async () => root.render(<Harness logicalRows={[nextRow]} mountedId={nextRowId} />));
|
||||
|
||||
expect(usePlayerStore.getState().timelineFocus?.id).toBe(nextRowId);
|
||||
expect(document.activeElement?.getAttribute("data-timeline-focus-id")).toBe(nextRowId);
|
||||
act(() => root.unmount());
|
||||
expect(usePlayerStore.getState().timelineFocus?.id).toBe(nextRowId);
|
||||
root = createRoot(host);
|
||||
});
|
||||
|
||||
it("keeps a request alive across a few renders where its target hasn't landed yet", async () => {
|
||||
|
||||
@@ -126,6 +126,15 @@ const MAX_UNRESOLVED_FOCUS_RETRIES = 5;
|
||||
// bounds it by wall time instead, independent of re-renders.
|
||||
const UNRESOLVED_FOCUS_TIMEOUT_MS = 4000;
|
||||
|
||||
function keepFallbackForRemount(resolvedRef: RefObject<{ nonce: number; id: string } | null>) {
|
||||
return () => {
|
||||
const resolved = resolvedRef.current;
|
||||
const stored = usePlayerStore.getState().timelineFocus;
|
||||
if (resolved && stored?.nonce === resolved.nonce && stored.id !== resolved.id)
|
||||
usePlayerStore.getState().requestTimelineFocus(resolved.id);
|
||||
};
|
||||
}
|
||||
|
||||
/** Model-first focus actor; mounting is a consequence of its returned pins. */
|
||||
// Resolution, fallback, reveal, and focus form one ordered state machine.
|
||||
// fallow-ignore-next-line complexity
|
||||
@@ -178,6 +187,8 @@ export function useTimelineFocusCoordinator({
|
||||
previousRowsRef.current = logicalRows;
|
||||
}, [logicalRows]);
|
||||
|
||||
useEffect(() => keepFallbackForRemount(resolvedRef), []);
|
||||
|
||||
// Apply a request exactly once after its logical target and DOM node are both ready.
|
||||
// fallow-ignore-next-line complexity
|
||||
useEffect(() => {
|
||||
@@ -204,10 +215,6 @@ export function useTimelineFocusCoordinator({
|
||||
if (unresolvedFocusAttemptsRef.current.count !== 0) {
|
||||
unresolvedFocusAttemptsRef.current = { id: -1, count: 0 };
|
||||
}
|
||||
if (resolution.target.id !== request.id) {
|
||||
usePlayerStore.getState().requestTimelineFocus(resolution.target.id);
|
||||
return;
|
||||
}
|
||||
if (
|
||||
appliedRef.current?.nonce === request.nonce &&
|
||||
appliedRef.current.id === resolution.target.id
|
||||
|
||||
Reference in New Issue
Block a user