From 7da9367dc91fe86a1fa246823331f780b4d5df12 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Tue, 9 Dec 2025 15:59:15 +0200 Subject: [PATCH] fix(tab_navigation): affecting server and mobile views --- .../widgets/TabHistoryNavigationButtons.tsx | 20 ++++++++++++------- .../widgets/launch_bar/HistoryNavigation.tsx | 6 +++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/apps/client/src/widgets/TabHistoryNavigationButtons.tsx b/apps/client/src/widgets/TabHistoryNavigationButtons.tsx index 142f4c7bb..07ecf6b66 100644 --- a/apps/client/src/widgets/TabHistoryNavigationButtons.tsx +++ b/apps/client/src/widgets/TabHistoryNavigationButtons.tsx @@ -3,19 +3,19 @@ import "./TabHistoryNavigationButtons.css"; import { useEffect, useMemo, useState } from "preact/hooks"; import { t } from "../services/i18n"; -import { dynamicRequire } from "../services/utils"; +import { dynamicRequire, isElectron } from "../services/utils"; import { handleHistoryContextMenu } from "./launch_bar/HistoryNavigation"; import ActionButton from "./react/ActionButton"; import { useLauncherVisibility } from "./react/hooks"; export default function TabHistoryNavigationButtons() { - const webContents = useMemo(() => dynamicRequire("@electron/remote").getCurrentWebContents(), []); - const onContextMenu = handleHistoryContextMenu(webContents); + const webContents = useMemo(() => isElectron() ? dynamicRequire("@electron/remote").getCurrentWebContents() : undefined, []); + const onContextMenu = webContents ? handleHistoryContextMenu(webContents) : undefined; const { canGoBack, canGoForward } = useBackForwardState(webContents); const legacyBackVisible = useLauncherVisibility("_lbBackInHistory"); const legacyForwardVisible = useLauncherVisibility("_lbForwardInHistory"); - return ( + return (isElectron() &&
{!legacyBackVisible && { + if (!webContents) return; + const updateNavigationState = () => { setCanGoBack(webContents.navigationHistory.canGoBack()); setCanGoForward(webContents.navigationHistory.canGoForward()); @@ -54,5 +56,9 @@ function useBackForwardState(webContents: Electron.WebContents) { }; }, [ webContents ]); + if (!webContents) { + return { canGoBack: true, canGoForward: true }; + } + return { canGoBack, canGoForward }; } diff --git a/apps/client/src/widgets/launch_bar/HistoryNavigation.tsx b/apps/client/src/widgets/launch_bar/HistoryNavigation.tsx index ee7e4fac8..3e0ce6f96 100644 --- a/apps/client/src/widgets/launch_bar/HistoryNavigation.tsx +++ b/apps/client/src/widgets/launch_bar/HistoryNavigation.tsx @@ -6,7 +6,7 @@ import contextMenu, { MenuCommandItem } from "../../menus/context_menu"; import froca from "../../services/froca"; import link from "../../services/link"; import tree from "../../services/tree"; -import { dynamicRequire } from "../../services/utils"; +import { dynamicRequire, isElectron } from "../../services/utils"; import { LaunchBarActionButton, useLauncherIconAndTitle } from "./launch_bar_widgets"; interface HistoryNavigationProps { @@ -18,14 +18,14 @@ const HISTORY_LIMIT = 20; export default function HistoryNavigationButton({ launcherNote, command }: HistoryNavigationProps) { const { icon, title } = useLauncherIconAndTitle(launcherNote); - const webContents = useMemo(() => dynamicRequire("@electron/remote").getCurrentWebContents(), []); + const webContents = useMemo(() => isElectron() ? dynamicRequire("@electron/remote").getCurrentWebContents() : undefined, []); return ( ); }