Repository navigation
Fix browser pane reloads on tab switch - #1228
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Caution Review failedPull request was closed or merged during review 📝 WalkthroughWalkthroughIntroduces per-WKWebView rendering state reattach tracking via an associated object key and computed property. On hidden notification, marks the flag as needed. Adds a guard in rendering state reattachment to no-op unless the flag is set, and restricts hide notifications to trigger only when the portal is actually visible. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Comment |
Greptile SummaryThis PR fixes browser pane reloads that occurred on tab/workspace switches by preventing unnecessary WebKit lifecycle notifications ( Key changes in
Confidence Score: 4/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant UI as Tab Logic
participant Portal as WindowBrowserPortal
participant Container as WindowBrowserSlotView
participant WebView as WKWebView
Note over UI,WebView: Tab switch away (visibleInUI becomes false)
UI->>Portal: hideWebView sets entry.visibleInUI=false
Portal->>Portal: synchronizeWebView - shouldHide=true
Portal->>Portal: hideContainerView()
Note over Portal: entry.visibleInUI==false - skip browserPortalNotifyHidden
Portal->>Container: isHidden = true
Note over WebView: flag stays false - no _exitInWindow fired - no visibilitychange
Note over UI,WebView: Tab switch back (visibleInUI becomes true)
UI->>Portal: bind/show sets entry.visibleInUI=true
Portal->>Portal: synchronizeWebView - shouldHide=false
Portal->>Container: isHidden = false
Portal->>Portal: refreshHostedWebViewPresentation()
Portal->>WebView: browserPortalReattachRenderingState()
Note over WebView: flag==false - early return - no _enterInWindow - no reload
Note over UI,WebView: Real detach (window close or anchor removed)
UI->>Portal: detachWebView or hideContainerView with visibleInUI=true
Portal->>WebView: browserPortalNotifyHidden - flag=true - _exitInWindow fires
Portal->>Container: isHidden=true or removeFromSuperview
Note over UI,WebView: Re-attach or reveal
Portal->>Portal: refreshHostedWebViewPresentation()
Portal->>WebView: browserPortalReattachRenderingState()
Note over WebView: flag==true - proceed - flag=false - _enterInWindow fires
Last reviewed commit: c52bd24 |
| func browserPortalNotifyHidden(reason: String) { | ||
| browserPortalNeedsRenderingStateReattach = true | ||
| let firedSelectors = ["viewDidHide", "_exitInWindow"].filter { | ||
| browserPortalCallVoidIfAvailable($0) |
There was a problem hiding this comment.
Flag set unconditionally before selector check
browserPortalNeedsRenderingStateReattach is set to true before the selectors are actually attempted (line 64 precedes the filter on line 65). The PR description states the intent as "only re-run WebKit rendering state reattach when a prior hide actually invoked the detach selectors," but the current implementation marks the flag true even when neither viewDidHide nor _exitInWindow responds.
In practice this is harmless — if neither hide selector fires, the matching reattach selectors (viewDidUnhide, _enterInWindow) almost certainly won't fire either, and the only extra work is the needsLayout/needsDisplay calls in browserPortalReattachRenderingState. However, if precision matters for the stated goal, setting the flag only when firedSelectors is non-empty would more accurately track the invariant:
func browserPortalNotifyHidden(reason: String) {
let firedSelectors = ["viewDidHide", "_exitInWindow"].filter {
browserPortalCallVoidIfAvailable($0)
}
if !firedSelectors.isEmpty {
browserPortalNeedsRenderingStateReattach = true
}
// ...
}…er-tab-switch-reload Fix browser pane reloads on tab switch
Summary
Closes #1225.
Testing
./scripts/reload.sh --tag fix-1225-tabsSummary by cubic
Stops unexpected page reloads when switching tabs/workspaces by skipping full WebKit hide/show lifecycles on visibility-only changes. Fixes #1225.
browserPortalNeedsRenderingStateReattachflag to reattach rendering state only if it was previously detached.visibilitychangeand reload triggers.Written for commit c52bd24. Summary will update on new commits.
Summary by CodeRabbit
Release Notes