fix(browser): make tabs not always reload in the in app browser
Description
- in app browser tabs not reloading on refocus
Screenshot/Recording (if applicable)
https://streamable.com/4hdjuw
Checklist
- [X] I kept this PR small and focused
- [X] I ran a self-review before opening this PR
- [X] I ran the relevant local checks or explained why not
- [X] I updated docs when behavior or setup changed
- [X] I added or updated tests when behavior changed, or explained why not
- [X] I only added comments where the logic is not obvious
- [X] I used Conventional Commits for commit messages and, when possible, the PR title
Greptile Summary
This PR fixes in-app browser tabs reloading on refocus by keeping all browser panes mounted at all times (toggled via display:none through ShowHide) rather than unmounting and remounting the active pane on each tab switch. A visible prop is threaded into BrowserPane so setActiveBrowser is correctly called whenever a tab becomes active, and a new useEffect in PaneContent clears the active browser reference when the user switches away to a non-browser tab.
BrowserPanegains avisibleprop; thesetActiveBrowsereffect now guards on!visibleand includesvisiblein its dependency array, ensuring the main process is notified on every tab activation.PaneContentpre-renders all browser tabs viaShowHideand handles the "navigated away from browser" case with a dedicated effect that callssetActiveBrowser(null)whenactiveBrowserIdbecomes null.- The
.filter()call that producesbrowserTabsis missing a TypeScript type predicate, so the result isResolvedTab[]and the subsequenttab.browserIdaccess is a likely compilation error.
Confidence Score: 4/5
Safe to merge once the TypeScript type predicate issue in pane-content.tsx is resolved; the core tab-switching logic is correct.
The filter call in pane-content.tsx lacks a type predicate, leaving browserTabs typed as ResolvedTab[]. Accessing tab.browserId in the subsequent .map() would be a TypeScript compilation error unless the team's tsconfig is unusually lenient. The rest of the logic is sound and correctly addresses the tab-reload regression.
apps/emdash-desktop/src/renderer/features/tasks/view/pane-content.tsx — the missing type predicate on the filter call.
Important Files Changed
| Filename | Overview |
|---|---|
| apps/emdash-desktop/src/renderer/features/tasks/view/pane-content.tsx | Switches from conditionally rendering the active BrowserPane to rendering all browser tabs via ShowHide; adds a useEffect to call setActiveBrowser(null) when no browser tab is active — but the .filter() lacks a type predicate, likely causing a TypeScript compilation error on tab.browserId. |
| apps/emdash-desktop/src/renderer/features/browser/browser-pane.tsx | Adds a visible prop; guards setActiveBrowser with !visible and adds visible to the dependency array so it fires correctly when the tab becomes active rather than only on initial mount. |
Reviews (2): Last reviewed commit: "fix(browser): update active pane on tab ..." | Re-trigger Greptile
@greptileai
LGTM — thank you for the fix. Merging this.
One thing I noticed while testing: when I switch away from a task that has a browser tab open, then come back and re-enter that tab, the browser reloads.
I think we should prevent this self-reload behavior entirely if possible, since it can interrupt the user’s state. @janburzinski - I would propose to do this in a separate PR.