Skip to content

Comments

MAJOR FIX: Duplicate web instances#297

Merged
jonathancaudill merged 3 commits intonook-browser:devfrom
jonathancaudill:dev
Feb 17, 2026
Merged

MAJOR FIX: Duplicate web instances#297
jonathancaudill merged 3 commits intonook-browser:devfrom
jonathancaudill:dev

Conversation

@jonathancaudill
Copy link
Contributor

duplicate web instances were being created in an attempt to prepare for multi window sync. This should be a MAJOR performance increase!

…e RAM usage

**Problem:**
Each tab was creating TWO WKWebView instances:
1. Tab's lazy 'primary' WebView (created on first access, never displayed)
2. Window-specific WebView (created for display)

This resulted in double RAM usage in Activity Monitor (2 WebContent processes per tab).

**Solution:**
Implemented smart WebView assignment system:

1. **Tab.swift:**
   - Added primaryWindowId tracking to know which window owns the WebView
   - Added assignedWebView property that only returns WebView if assigned
   - Added assignWebViewToWindow() method for explicit assignment

2. **WebViewCoordinator.swift:**
   - Added getOrCreateWebView() that intelligently assigns WebViews
   - First window gets 'primary' WebView (assigned to tab)
   - Additional windows get 'clone' WebViews
   - Added createPrimaryWebView() and createCloneWebView() methods
   - Refactored createWebView() to use internal implementation

3. **WebsiteView.swift:**
   - Updated webView() method to use smart assignment
   - Now calls getOrCreateWebView() instead of separate get/create

4. **Lazy initialization elimination:**
   - Removed forced lazy initialization in TabManager (lines 2158, 2344)
   - Updated ExtensionManager, PiPManager, MediaControlsManager,
     ExtensionBridge, and Navigation menus to use assignedWebView

**Result:**
- Single window: 1 WebView per tab (was 2)
- Multi-window: 1 WebView per window per tab (no waste)
- Expected 50% RAM reduction in single-window mode
…ent objects

**Problem:**
Creating a new window caused a crash:
'No Observable object of type AIService found'

The SidebarAIChat view requires AIService and AIConfigService via @Environment,
but they weren't being passed when BrowserManager created new windows manually.

**Solution:**
1. Added aiService and aiConfigService weak references to BrowserManager
2. Wired these services in NookApp.setupApplicationLifecycle()
3. Added .environment(aiService) and .environment(aiConfigService) to both:
   - createNewWindow()
   - createIncognitoWindow()

Also added missing .nookSettings environment to createIncognitoWindow() for consistency.
@jonathancaudill jonathancaudill merged commit fec941a into nook-browser:dev Feb 17, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant