Conversation
- Introduced `navHistory` and `asleep` properties to the Tab class. - Updated tab creation options to include navigation history and sleep state. - Implemented methods to manage tab sleep state, including `putToSleep` and `wakeUp`. - Enhanced tab data retrieval to include new properties. - Updated tab state management to account for sleep state and navigation history changes.
WalkthroughThe changes introduce a new "asleep" state for browser tabs, allowing tabs to be put to sleep and later woken up. This includes tracking and restoring navigation history, updating tab state management, and modifying the tab creation process to support these new behaviors. The Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant Tab
participant WebContents
User->>Tab: Show tab (tab is asleep)
Tab->>Tab: wakeUp()
Tab->>WebContents: Restore URL and navigation history
User->>Tab: Put tab to sleep
Tab->>Tab: putToSleep()
Tab->>WebContents: Save state, load about:blank
Suggested labels
Poem
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 2
🔭 Outside diff range comments (1)
electron/browser/tabs/tab.ts (1)
157-177:⚠️ Potential issuePutting a tab to sleep before its first real navigation loses the URL
When a tab is constructed with
asleep: true,putToSleep()is executed beforeloadURL(NEW_TAB_URL).Consequences
updateTabState()runs whilewebContents.getURL()is still"", sothis.urlis never initialised.putToSleep()then loadsabout:blank.wakeUp()later callsrestoreTabState()→loadURL(this.url, true)which is now"", so the tab never restores.Deferred sleeping fixes the issue:
- // Put to sleep if requested - if (asleep) { - this.putToSleep(); - } + // Defer sleeping until the initial navigation finished so we capture the + // real URL first. + if (asleep) { + process.nextTick(() => this.putToSleep()); + }Alternatively, capture the intended URL before replacing it with
about:blank.
🧹 Nitpick comments (2)
shared/types/tabs.ts (1)
3-6: Unify navigation‑history typings across renderer & main process
NavigationEntryis introduced as a project‑local alias.
Inelectron/browser/tabs/tab.tsa differentNavigationEntryis imported from the Electron types, so the same identifier now refers to two structurally similar but distinct interfaces. This can easily lead to subtle type‑mismatch errors (e.g. excess‑property checks or future Electron upgrades that change the built‑in shape).Consider standardising on one of the two below:
- Re‑export Electron’s
NavigationHistoryEntry(if that is the actual type you rely on) fromshared/types/tabs.tsand use a project alias such asBrowserNavigationEntry, or- Keep this local definition but remove the import from
electronand instead import it from~/types/tabseverywhere.Either way, ensure you only have a single source‑of‑truth for the navigation‑history entry shape.
Also applies to: 20-22
electron/ipc/browser/tabs.ts (1)
21-23: LargenavHistorypayload may bloat every IPC frame
navHistorycan easily contain hundreds of entries. Serialising and transferring the entire array on everytabs:on-data-changedbroadcast will noticeably increase IPC traffic and JSON serialisation costs.Two low‑effort mitigations to consider:
- navHistory: tab.navHistory + // Send *only* what the consumer needs. + navHistory: tab.navHistory.slice(-10) // last 10 entriesor gate it behind a flag:
navHistory: includeHistory ? tab.navHistory : []Optimising here keeps UI updates snappy, especially when many tabs change state simultaneously.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
electron/browser/tabs/tab.ts(11 hunks)electron/ipc/browser/tabs.ts(1 hunks)shared/types/tabs.ts(2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
electron/browser/tabs/tab.ts (1)
shared/types/tabs.ts (1)
NavigationEntry(3-6)
navHistoryandasleepproperties to the Tab class.putToSleepandwakeUp.Summary by CodeRabbit