Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
refactor: hoist the remix by-id lookup out of the handoff effect (#12996)
[._.]/ Adam Eivy3308229096e7
diff --git a/client/src/pages/VideoGen.jsx b/client/src/pages/VideoGen.jsxindex 5122e43fff..2cc416d572 100644--- a/client/src/pages/VideoGen.jsx+++ b/client/src/pages/VideoGen.jsx@@ -550,6 +550,26 @@ export default function VideoGen() {return next;}, { replace: true });}, [setSearchParams]);+ // The page loads only the newest HISTORY_PAGE_LIMIT records, so an older clip+ // is hydrated by id before it is called missing. The handoff id is already+ // marked settled, so a history refresh mid-flight cannot start a second lookup;+ // a handoff that changed or cleared meanwhile resets that ref, which makes the+ // answer stale.+ const hydrateOlderRemix = useCallback((id) => {+ const current = () => settledRemixHandoffRef.current === id;+ getVideoHistoryItem(id, { silent: true })+ .then((older) => {+ if (!current()) return;+ applyRemix(older);+ setRemixHandoffProblem(null);+ consumeRemixHandoff();+ })+ .catch((err) => {+ if (!current()) return;+ // Only a 404 means the clip is gone; any other failure keeps the param so Retry resolves it.+ if (err?.status === 404) { setRemixHandoffProblem('missing'); consumeRemixHandoff(); } else setRemixHandoffProblem('error');+ });+ }, [applyRemix, consumeRemixHandoff]);useEffect(() => {// No handoff in the URL — including right after this one consumed its own.// Clearing the settled id here is what lets the NEXT handoff through, even@@ -579,26 +599,8 @@ export default function VideoGen() {consumeRemixHandoff();return;}- // The page loads only the newest HISTORY_PAGE_LIMIT records, so an older- // clip is hydrated by id before it is called missing.- // The id is marked settled above, so a history refresh mid-flight cannot- // start a second lookup. A handoff that changed or cleared meanwhile resets- // that ref, which makes this answer stale.- const id = remixHandoffId;- const current = () => settledRemixHandoffRef.current === id;- getVideoHistoryItem(id, { silent: true })- .then((older) => {- if (!current()) return;- applyRemix(older);- setRemixHandoffProblem(null);- consumeRemixHandoff();- })- .catch((err) => {- if (!current()) return;- // Only a 404 means the clip is gone; any other failure keeps the param so Retry resolves it.- if (err?.status === 404) { setRemixHandoffProblem('missing'); consumeRemixHandoff(); } else setRemixHandoffProblem('error');- });- }, [remixHandoffId, historyLoad, history, applyRemix, consumeRemixHandoff]);+ hydrateOlderRemix(remixHandoffId);+ }, [remixHandoffId, historyLoad, history, applyRemix, consumeRemixHandoff, hydrateOlderRemix]);// Back to 'loading' first, so a retry that fails again still moves the state// ('loading' → 'error') and re-runs the effect above.const retryRemixHandoff = useCallback(() => {