Skip to content

Commit 79fa0bd

Browse files
committed
fix(preview): keep store and guest matched on resize rollback
Apply-failure never put the new override on the guest, so the store still rolls back even if the guest CDP clear throws. Timeout still rolls the guest first and only persists previous if that apply succeeds; a failed store resize puts the guest back on the requested size.
1 parent fd6b40a commit 79fa0bd

1 file changed

Lines changed: 17 additions & 5 deletions

File tree

‎apps/web/src/components/preview/PreviewAutomationHosts.tsx‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,7 @@ function PreviewAutomationHost(props: { readonly environmentId: EnvironmentId })
502502
const rollbackGuestIfCurrent = async (
503503
previousSetting: PreviewViewportSetting,
504504
operationServerEpoch: string | null,
505+
guestHasRequestedOverride: boolean,
505506
) => {
506507
const latestState = readThreadPreviewState(threadRef);
507508
const latestSetting =
@@ -522,16 +523,18 @@ function PreviewAutomationHost(props: { readonly environmentId: EnvironmentId })
522523
} catch {
523524
return;
524525
}
526+
const zoomFactor = latestState.desktopByTabId[ready.tabId]?.zoomFactor ?? 1;
527+
let guestRolledBack = !guestHasRequestedOverride;
525528
try {
526529
await applyPreviewGuestViewport(
527530
setViewport,
528531
ready.runtimeTabId,
529532
previousSetting,
530-
latestState.desktopByTabId[ready.tabId]?.zoomFactor ?? 1,
533+
zoomFactor,
531534
);
535+
guestRolledBack = true;
532536
} catch {
533-
// Guest still has the requested override; leave the store matching it.
534-
return;
537+
if (guestHasRequestedOverride) return;
535538
}
536539
const rollback = await resize({
537540
environmentId,
@@ -543,6 +546,15 @@ function PreviewAutomationHost(props: { readonly environmentId: EnvironmentId })
543546
});
544547
if (rollback._tag !== "Failure") {
545548
updatePreviewServerSnapshot(threadRef, rollback.value);
549+
return;
550+
}
551+
if (guestHasRequestedOverride && guestRolledBack) {
552+
await applyPreviewGuestViewport(
553+
setViewport,
554+
ready.runtimeTabId,
555+
setting,
556+
zoomFactor,
557+
).catch(() => undefined);
546558
}
547559
};
548560
const persistViewport = async () => {
@@ -574,7 +586,7 @@ function PreviewAutomationHost(props: { readonly environmentId: EnvironmentId })
574586
operationState.desktopByTabId[ready.tabId]?.zoomFactor ?? 1,
575587
);
576588
} catch (error) {
577-
await rollbackGuestIfCurrent(previousSetting, operationState.serverEpoch);
589+
await rollbackGuestIfCurrent(previousSetting, operationState.serverEpoch, false);
578590
throw error;
579591
}
580592
return {
@@ -600,7 +612,7 @@ function PreviewAutomationHost(props: { readonly environmentId: EnvironmentId })
600612
);
601613
} catch (cause) {
602614
await runBrowserViewportMutation(ready.runtimeTabId, async () => {
603-
await rollbackGuestIfCurrent(applied.previousSetting, applied.serverEpoch);
615+
await rollbackGuestIfCurrent(applied.previousSetting, applied.serverEpoch, true);
604616
});
605617
throw cause;
606618
}

0 commit comments

Comments
 (0)