diff --git a/package.json b/package.json index c9791da..7b26a60 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "version": "1.0.0-alpha.4", "type": "module", "scripts": { - "dev": "vite --force && tsr watch", + "dev": "vite && tsr watch", "build": "vite build", "preview": "vite preview", "tauri": "tauri", diff --git a/src/components/search/index.tsx b/src/components/search/index.tsx index b2f4847..2a814d8 100644 --- a/src/components/search/index.tsx +++ b/src/components/search/index.tsx @@ -17,6 +17,7 @@ import type { TransitionProps } from "@mui/material/transitions"; import { useQuery } from "@tanstack/react-query"; import { useNavigate } from "@tanstack/react-router"; import { register } from "@tauri-apps/plugin-global-shortcut"; + import React, { type ChangeEvent, useCallback, @@ -42,6 +43,10 @@ const Transition = React.forwardRef(function Transition( return ; }); +// Register the global shortcut once. StrictMode mounts this component twice +// in development, and a second register() fails with an unhandled rejection. +let searchShortcutRegistered = false; + const Search = () => { const theme = useTheme(); const { isOpen, handleClose, toggleSearchDialog } = useSearchStore( @@ -54,7 +59,7 @@ const Search = () => { const api = useApiInContext((s) => s.api); const userId = useCentralStore((s) => s.currentUser?.Id || ""); const suggestions = useQuery({ - queryKey: ["search", "suggestions"], + queryKey: ["search", "suggestions", userId], queryFn: async () => api && ( @@ -67,6 +72,9 @@ const Search = () => { recursive: true, }) ).data, + // Do not fetch random suggestions during app startup. + enabled: isOpen && Boolean(api && userId), + staleTime: 5 * 60 * 1000, }); const [searchTerm, setSearchTerm] = useState(""); @@ -135,14 +143,15 @@ const Search = () => { }, [navigate, toggleSearchDialog, debouncedSearchTerm]); useEffect(() => { - async function registerglobalShortcut() { - await register("CommandOrControl+K", (e) => { - if (e.state === "Pressed") { - toggleSearchDialog(); - } - }); - } - registerglobalShortcut(); + if (searchShortcutRegistered) return; + searchShortcutRegistered = true; + register("CommandOrControl+K", (e) => { + if (e.state === "Pressed") { + useSearchStore.getState().toggleSearchDialog(); + } + }).catch((error) => { + console.warn("Global search shortcut is unavailable", error); + }); }, []); return ( diff --git a/src/components/updater/index.tsx b/src/components/updater/index.tsx index 862598c..93ca365 100644 --- a/src/components/updater/index.tsx +++ b/src/components/updater/index.tsx @@ -24,7 +24,6 @@ export default function Updater() { try { const update = await check(); if (update) { - // console.log(update); setUpdateInfo(update); setUpdateDialog(true); @@ -34,7 +33,9 @@ export default function Updater() { console.error(error); } } - checkForUpdates(); + // Let the first page paint and its own requests start first. + const timer = window.setTimeout(checkForUpdates, 5000); + return () => window.clearTimeout(timer); }, []); const { enqueueSnackbar } = useSnackbar(); const [downloadProgress, setDownloadProgress] = useState(0); diff --git a/src/main.tsx b/src/main.tsx index dbd674d..c77795d 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -46,8 +46,10 @@ const router = createRouter({ fetchCurrentUser: undefined!, queryClient, }, - defaultPreload: false, - defaultPreloadStaleTime: 0, + // Preload route chunks/data when the user shows intent (hover/focus), so + // navigation itself stays instant without paying for every route at boot. + defaultPreload: "intent", + defaultPreloadStaleTime: 30_000, // Only animate real page changes; search-param updates (typing in the // search field) must not trigger a transition on every keystroke. defaultViewTransition: { diff --git a/vite.config.ts b/vite.config.ts index 1aa571b..2a13317 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -5,7 +5,14 @@ import wasm from "vite-plugin-wasm"; import { tanstackRouter } from '@tanstack/router-vite-plugin' import path from "path"; -const plugins = [react(), svgr(), tanstackRouter(), wasm()]; +const plugins = [ + // Must run before the JSX transform. Splits route components out of the + // initial bundle, so startup only pays for the opening page. + tanstackRouter({ autoCodeSplitting: true }), + react(), + svgr(), + wasm(), +]; export default defineConfig({ plugins: plugins,