diff --git a/src/renderer/src/components/browser-pane/BrowserPane.tsx b/src/renderer/src/components/browser-pane/BrowserPane.tsx index d824a3303c7..478c32d2d4f 100644 --- a/src/renderer/src/components/browser-pane/BrowserPane.tsx +++ b/src/renderer/src/components/browser-pane/BrowserPane.tsx @@ -1778,10 +1778,8 @@ function RemoteBrowserPagePane({ [closeMissingRemotePage, isCurrentRemoteStreamToken] ) - useEffect(() => { - startRemoteStreamRef.current = startRemoteStream - restartRemoteStreamForViewportRef.current = restartRemoteStreamForViewport - }, [restartRemoteStreamForViewport, startRemoteStream]) + startRemoteStreamRef.current = startRemoteStream + restartRemoteStreamForViewportRef.current = restartRemoteStreamForViewport useEffect(() => { return () => { @@ -2555,6 +2553,9 @@ function BrowserPagePane({ const initialBrowserUrlRef = useRef(browserTab.url) const browserTabUrlRef = useRef(browserTab.url) const activeLoadFailureRef = useRef(browserTab.loadError) + initialBrowserUrlRef.current = browserTab.url + browserTabUrlRef.current = browserTab.url + activeLoadFailureRef.current = browserTab.loadError // Why: CDP viewport emulation does not survive all renderer process swaps // (cross-origin navigations, crashes). We reapply on every dom-ready from // this ref so the persisted preset survives reloads without re-running the @@ -2572,11 +2573,16 @@ function BrowserPagePane({ const onSetUrlRef = useRef(onSetUrl) const addBrowserHistoryEntry = useAppStore((s) => s.addBrowserHistoryEntry) const addBrowserHistoryEntryRef = useRef(addBrowserHistoryEntry) + onUpdatePageStateRef.current = onUpdatePageState + onSetUrlRef.current = onSetUrl + addBrowserHistoryEntryRef.current = addBrowserHistoryEntry const [addressBarValue, setAddressBarValue] = useState(browserTab.url) const addressBarValueRef = useRef(browserTab.url) + addressBarValueRef.current = addressBarValue const [resourceNotice, setResourceNotice] = useState(null) const [downloadState, setDownloadState] = useState(null) const downloadStateRef = useRef(null) + downloadStateRef.current = downloadState const [contextMenu, setContextMenu] = useState<{ x: number y: number @@ -2797,10 +2803,6 @@ function BrowserPagePane({ } }, [browserAnnotations.length, isActive, pendingAnnotationPayload]) - useEffect(() => { - initialBrowserUrlRef.current = browserTab.url - }, [browserTab.id, browserTab.url]) - useEffect(() => { // Why: if the user is actively typing in the address bar (focused), do not // clobber their in-progress query when an async URL update lands (e.g., the @@ -2812,22 +2814,6 @@ function BrowserPagePane({ setAddressBarValue(toDisplayUrl(browserTab.url)) }, [browserTab.url]) - useEffect(() => { - browserTabUrlRef.current = browserTab.url - }, [browserTab.url]) - - useEffect(() => { - activeLoadFailureRef.current = browserTab.loadError - }, [browserTab.loadError]) - - useEffect(() => { - addressBarValueRef.current = addressBarValue - }, [addressBarValue]) - - useEffect(() => { - downloadStateRef.current = downloadState - }, [downloadState]) - useEffect(() => { setResourceNotice( consumeEvictedBrowserTab(browserTab.id) @@ -3228,12 +3214,6 @@ function BrowserPagePane({ }) }, [isActive]) - useEffect(() => { - onUpdatePageStateRef.current = onUpdatePageState - onSetUrlRef.current = onSetUrl - addBrowserHistoryEntryRef.current = addBrowserHistoryEntry - }, [onSetUrl, onUpdatePageState, addBrowserHistoryEntry]) - const syncNavigationState = useCallback( (webview: Electron.WebviewTag): void => { try { diff --git a/src/renderer/src/components/browser-pane/useGrabMode.ts b/src/renderer/src/components/browser-pane/useGrabMode.ts index 991c95cad33..f2822c84130 100644 --- a/src/renderer/src/components/browser-pane/useGrabMode.ts +++ b/src/renderer/src/components/browser-pane/useGrabMode.ts @@ -44,10 +44,7 @@ export function useGrabMode(browserPageId: string): GrabModeHook { const [contextMenu, setContextMenu] = useState(false) const activeOpIdRef = useRef(null) const browserTabIdRef = useRef(browserPageId) - - useEffect(() => { - browserTabIdRef.current = browserPageId - }, [browserPageId]) + browserTabIdRef.current = browserPageId // Why: when the browser page changes while grab is active, cancel the // current grab operation so stale overlays don't survive tab switches.