Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

fix(search): stop ~10s freeze on search bar open (reuse warm webview) (#4539)

Louis Beaumontd95f6fc58161
diff --git a/apps/screenpipe-app-tauri/app/search/page.tsx b/apps/screenpipe-app-tauri/app/search/page.tsx
index 29adeb85f..7856cdee9 100644
--- a/apps/screenpipe-app-tauri/app/search/page.tsx
+++ b/apps/screenpipe-app-tauri/app/search/page.tsx
@@ -4,9 +4,9 @@
"use client";
-import { useCallback, useEffect } from "react";
+import { useCallback, useEffect, useState } from "react";
import { SearchModal } from "@/components/rewind/search-modal";
-import { emit } from "@tauri-apps/api/event";
+import { emit, listen } from "@tauri-apps/api/event";
import { commands } from "@/lib/utils/tauri";
import {
RECENT_CHAT_SEARCH_HANDOFF_EVENT,
@@ -23,6 +23,24 @@ export default function SearchPage() {
await commands.closeWindow({ Search: { query: null } });
}, []);
+ // The search window is reused across opens: Rust hides it on close (keeping
+ // the webview warm) and emits "search-reset" instead of reloading the page.
+ // Bumping the key remounts SearchModal, which replays the normal fresh-open
+ // path (clean state + autofocus) without paying a webview cold-boot — the
+ // fix for the ~10s freeze before you could type.
+ const [reopenNonce, setReopenNonce] = useState(0);
+ useEffect(() => {
+ const unlistenPromise = listen<{ query?: string | null }>("search-reset", (event) => {
+ const q = event.payload?.query ?? "";
+ const url = q ? `/search?q=${encodeURIComponent(q)}` : "/search";
+ window.history.replaceState(null, "", url);
+ setReopenNonce((n) => n + 1);
+ });
+ return () => {
+ unlistenPromise.then((f) => f());
+ };
+ }, []);
+
// Close on click outside
useEffect(() => {
const handleBlur = () => {
@@ -62,6 +80,7 @@ export default function SearchPage() {
return (
<div className="w-screen h-screen bg-transparent">
<SearchModal
+ key={reopenNonce}
isOpen={true}
standalone
onClose={handleClose}
diff --git a/apps/screenpipe-app-tauri/src-tauri/src/window/show.rs b/apps/screenpipe-app-tauri/src-tauri/src/window/show.rs
index afdf00282..164273e67 100644
--- a/apps/screenpipe-app-tauri/src-tauri/src/window/show.rs
+++ b/apps/screenpipe-app-tauri/src-tauri/src/window/show.rs
@@ -466,15 +466,19 @@ impl ShowRewindWindow {
}
if id.label() == RewindWindowId::Search.label() {
- // Navigate to /search to reset state (clear previous results)
- let nav_url = if let Some(query) = self.metadata() {
- format!("/search/{}", query)
- } else {
- "/search".to_string()
- };
- let _ = window
- .eval(&format!("window.location.replace(`{}`);", nav_url))
- .ok();
+ // Reset the modal IN PLACE instead of reloading the webview.
+ // The search window is kept warm across opens (close() hides it
+ // rather than destroying it — see `close()` below), so a full
+ // `location.replace("/search")` here would throw the warm webview
+ // away and force a multi-second Next.js cold-boot on every open,
+ // during which the input is unresponsive (the ~10s "stuck" bug).
+ // Emitting "search-reset" lets the React side clear previous
+ // results and refocus the input instantly. metadata() carries an
+ // optional prefill query (empty string when none).
+ let _ = window.emit(
+ "search-reset",
+ serde_json::json!({ "query": self.metadata() }),
+ );
// Reposition to center of primary monitor
if let Ok(Some(monitor)) = app.primary_monitor() {
@@ -1844,6 +1848,36 @@ impl ShowRewindWindow {
// return Ok(());
// }
+ // Search: hide instead of destroy so the webview stays warm. Recreating
+ // the window forces a full Next.js cold-boot on every open (the input is
+ // unresponsive for several seconds); reuse via show()'s existing-window
+ // branch makes reopen instant. `window.close()` on the class-swizzled
+ // NSPanel also risks a use-after-free SIGSEGV (see the creation path),
+ // which order_out avoids.
+ if id.label() == RewindWindowId::Search.label() {
+ if let Some(window) = id.get(app) {
+ #[cfg(target_os = "macos")]
+ {
+ let window_clone = window.clone();
+ run_on_main_thread_safe(app, move || {
+ use objc::{msg_send, sel, sel_impl};
+ use tauri_nspanel::cocoa::base::{id, nil};
+ if let Ok(ns_win) = window_clone.ns_window() {
+ let ns_win = ns_win as id;
+ unsafe {
+ let _: () = msg_send![ns_win, orderOut: nil];
+ }
+ }
+ });
+ }
+ #[cfg(not(target_os = "macos"))]
+ {
+ window.hide().ok();
+ }
+ }
+ return Ok(());
+ }
+
if let Some(window) = id.get(app) {
// On Windows, minimize the Settings window instead of closing it
// so it stays in the taskbar and can be restored quickly.