The best way to control Claude Code, Codex and more from any computer or phone
refactor(web): the hosted browser webview keeps its caching without "use memo" (#20824)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 17, 2026 at 00:52 UTC
f03378f70ac37f56276210e193769c970a759047
1 file changed
+20
-27
apps/web/src/browser/HostedBrowserWebview.tsx
+20
-27
@@ -13,12 +13,7 @@ import { usePreviewBridge } from "~/components/preview/usePreviewBridge";
13
import { useClientSettingsHydrated } from "~/hooks/useSettings";
14
import { cn, isMacPlatform } from "~/lib/utils";
15
16
-import {
17
- type BrowserSurfaceContentPresentation,
18
- type BrowserSurfaceRect,
19
- resolveBrowserSurfacePanelRect,
20
- useBrowserSurfaceStore,
21
-} from "./browserSurfaceStore";
16
+import { resolveBrowserSurfacePanelRect, useBrowserSurfaceStore } from "./browserSurfaceStore";
17
import { useActiveBrowserRecordingTabIds } from "./browserRecording";
18
import {
19
browserViewportSettingKey,
@@ -224,8 +219,23 @@ export function HostedBrowserWebview(props: {
219
const handleAspectRatioChange = (aspectRatio: number | null) => {
220
setAspectRatioLocked(aspectRatio !== null);
221
};
227
- const hiddenSize = useHiddenSize(viewport, normalizedZoomFactor, presentation.content, lastRect);
228
- const containerSize = active && lastRect ? lastRect : hiddenSize;
222
+ const content = presentation.content;
223
+ const hiddenWidth =
224
+ viewport._tag !== "fill"
225
+ ? viewport.width * normalizedZoomFactor
226
+ : content
227
+ ? content.width / content.scale
228
+ : (lastRect?.width ?? 1280);
229
+ const hiddenHeight =
230
+ viewport._tag !== "fill"
231
+ ? viewport.height * normalizedZoomFactor
232
+ : content
233
+ ? content.height / content.scale
234
+ : (lastRect?.height ?? 800);
235
+ // Built from primitives on each side of the resize hook, so neither object is
236
+ // shared across it and both stay cached; the hook's layout keys the sync effect.
237
+ const containerSize =
238
+ active && lastRect ? lastRect : { width: hiddenWidth, height: hiddenHeight };
239
const deviceToolbarVisible = active && viewport._tag !== "fill" && !presentation.fitSourceContent;
240
const {
241
activeDrag,
@@ -297,7 +307,7 @@ export function HostedBrowserWebview(props: {
307
cornerRadius: presentation.cornerRadius,
308
zIndex: presentation.zIndex,
309
rect: lastRect,
300
- hiddenSize,
310
+ hiddenSize: { width: hiddenWidth, height: hiddenHeight },
311
});
312
313
return (
@@ -313,7 +323,7 @@ export function HostedBrowserWebview(props: {
323
{deviceToolbarVisible && effectiveViewport._tag !== "fill" ? (
324
<BrowserDeviceToolbar
325
setting={effectiveViewport}
316
- width={Math.max(1, Math.round(containerSize.width))}
326
+ width={Math.max(1, Math.round(active && lastRect ? lastRect.width : hiddenWidth))}
327
aspectRatio={lockedAspectRatio}
328
onAspectRatioChange={handleAspectRatioChange}
329
onChange={commitViewportChange}
@@ -390,20 +400,3 @@ export function HostedBrowserWebview(props: {
400
</div>
401
);
402
}
393
-
394
-// The size feeds useBrowserViewportResize, whose layout keys the content sync effect.
395
-function useHiddenSize(
396
- viewport: PreviewViewportSetting,
397
- zoomFactor: number,
398
- content: BrowserSurfaceContentPresentation | null,
399
- lastRect: BrowserSurfaceRect | null,
400
-) {
401
- "use memo";
402
- if (viewport._tag !== "fill") {
403
- return { width: viewport.width * zoomFactor, height: viewport.height * zoomFactor };
404
- }
405
- return {
406
- width: content ? content.width / content.scale : (lastRect?.width ?? 1280),
407
- height: content ? content.height / content.scale : (lastRect?.height ?? 800),
408
- };
409
-}