Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions Sources/Panels/BrowserPanel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2296,6 +2296,7 @@ private enum BrowserInsecureHTTPNavigationIntent {

nonisolated enum BrowserWebViewLifecycleState: String {
case newTab = "new_tab"
case deferredURL = "deferred_url"
case liveVisible = "live_visible"
case liveHidden = "live_hidden"
case discarded
Expand Down Expand Up @@ -2748,9 +2749,9 @@ final class BrowserPanel: Panel, ObservableObject {
private var isWebViewVisibleInUI: Bool = false
private var isClosingWebViewLifecycle: Bool = false

/// True when the browser is showing the internal empty new-tab page (no WKWebView attached yet).
/// True when the browser is showing the internal empty new-tab page.
var isShowingNewTabPage: Bool {
!shouldRenderWebView
!shouldRenderWebView && preferredURLStringForOmnibar() == nil
}

/// Published page title
Expand Down Expand Up @@ -3008,7 +3009,7 @@ final class BrowserPanel: Panel, ObservableObject {
} else if hiddenWebViewDiscardManager.isDiscardedForMemory {
nextState = .discarded
} else if !shouldRenderWebView {
nextState = .newTab
nextState = preferredURLStringForOmnibar() == nil ? .newTab : .deferredURL
} else if isWebViewVisibleInUI {
nextState = .liveVisible
} else {
Expand Down
15 changes: 7 additions & 8 deletions Sources/Panels/BrowserPanelView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -855,10 +855,10 @@ struct BrowserPanelView: View {
if addressBarFocused,
!panel.shouldSuppressWebViewFocus(),
addressWasEmpty,
!isWebViewBlank() {
!isBrowserContentBlankForOmnibar() {
setAddressBarFocused(false, reason: "panel.currentURL.loaded")
}
if isWebViewBlank() {
if panel.isShowingNewTabPage {
refreshEmptyStateImportBrowsers()
}
panel.resetReactGrabState(
Expand Down Expand Up @@ -1947,7 +1947,7 @@ struct BrowserPanelView: View {
}

private var shouldShowEmptyStateImportOverlay: Bool {
!panel.shouldRenderWebView && isWebViewBlank()
panel.isShowingNewTabPage
}

private func presentImportDialogFromHint() {
Expand Down Expand Up @@ -1983,10 +1983,9 @@ struct BrowserPanelView: View {
isBrowserImportHintPopoverPresented = false
}

/// Treat a WebView with no URL (or about:blank) as "blank" for UX purposes.
private func isWebViewBlank() -> Bool {
guard let url = panel.webView.url else { return true }
return url.absoluteString == "about:blank"
/// Treat content as blank only if neither WebKit nor the panel model has a nonblank URL.
private func isBrowserContentBlankForOmnibar() -> Bool {
panel.preferredURLStringForOmnibar() == nil
}

private func autoFocusOmnibarIfBlank() {
Expand Down Expand Up @@ -2022,7 +2021,7 @@ struct BrowserPanelView: View {
#endif
return
}
guard isWebViewBlank() else {
guard isBrowserContentBlankForOmnibar() else {
#if DEBUG
logBrowserFocusState(event: "addressBarFocus.autoFocus.skip", detail: "reason=webview_not_blank")
#endif
Expand Down
14 changes: 14 additions & 0 deletions cmuxTests/BrowserConfigTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,20 @@ final class BrowserDeveloperToolsConfigurationTests: XCTestCase {
XCTAssertFalse(panel.isShowingNewTabPage)
}

func testBrowserPanelWithDeferredInitialURLIsNotNewTabPage() throws {
let url = try XCTUnwrap(URL(string: "https://example.com/restored"))
let panel = BrowserPanel(
workspaceId: UUID(),
initialURL: url,
renderInitialNavigation: false
)

XCTAssertFalse(panel.shouldRenderWebView)
XCTAssertEqual(panel.currentURL, url)
XCTAssertFalse(panel.isShowingNewTabPage)
XCTAssertEqual(panel.webViewLifecycleState, .deferredURL)
}

func testBrowserPanelThemeModeUpdatesWebViewAppearance() {
let panel = BrowserPanel(workspaceId: UUID())

Expand Down
6 changes: 3 additions & 3 deletions cmuxTests/GhosttyConfigTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@ final class BrowserPanelWebViewLifecycleTests: XCTestCase {
}
}

func testLifecycleStartsAsNewTabUntilRenderable() {
func testLifecycleDistinguishesDeferredURLFromNewTab() {
let panel = BrowserPanel(
workspaceId: UUID(),
initialURL: URL(string: "https://example.test/")!,
Expand All @@ -1536,11 +1536,11 @@ final class BrowserPanelWebViewLifecycleTests: XCTestCase {
)
defer { panel.close() }

XCTAssertEqual(panel.webViewLifecycleState, .newTab)
XCTAssertEqual(panel.webViewLifecycleState, .deferredURL)

panel.noteWebViewVisibility(true, reason: "test.visible")

XCTAssertEqual(panel.webViewLifecycleState, .newTab)
XCTAssertEqual(panel.webViewLifecycleState, .deferredURL)
}

func testBackgroundInitialNavigationOwnsHeadlessWebKitHostBeforeViewAppears() {
Expand Down
Loading