Skip to content
This repository has been archived by the owner on May 10, 2024. It is now read-only.

Commit

Permalink
Fix #7366: Tab restoring white screen sometimes (#7367)
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon-T authored May 3, 2023
1 parent 8293f41 commit 36b3483
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
7 changes: 6 additions & 1 deletion Sources/Brave/Frontend/Browser/TabManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,7 @@ class TabManager: NSObject {

if let request = request {
tab.loadRequest(request)
tab.url = request.url
} else if !isPopup {
tab.loadRequest(PrivilegedRequest(url: TabManager.ntpInteralURL) as URLRequest)
tab.url = TabManager.ntpInteralURL
Expand Down Expand Up @@ -901,7 +902,11 @@ class TabManager: NSObject {
for savedTab in savedTabs {
let tabURL = savedTab.url
// Provide an empty request to prevent a new tab from loading the home screen
let tab = addTab(URLRequest(url: tabURL),
let request = InternalURL.isValid(url: tabURL) ?
PrivilegedRequest(url: tabURL) as URLRequest :
URLRequest(url: tabURL)

let tab = addTab(request,
flushToDisk: false,
zombie: true,
id: savedTab.tabId,
Expand Down
15 changes: 10 additions & 5 deletions Sources/Data/models/SessionTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ extension SessionTab {

public static func update(tabId: UUID, interactionState: Data, title: String, url: URL) {
DataController.perform { context in
guard let sessionTab = Self.from(tabId: tabId, in: context) else { return }
guard let sessionTab = Self.from(tabId: tabId, in: context) else {
Logger.module.error("Error: SessionTab.update missing managed object")
return
}
sessionTab.interactionState = interactionState
sessionTab.title = title
sessionTab.url = url
Expand All @@ -166,7 +169,7 @@ extension SessionTab {
DataController.perform { context in
for (index, tabId) in tabIds.enumerated() {
guard let tab = Self.from(tabId: tabId, in: context) else {
Logger.module.error("Error: SessionTab missing managed object")
Logger.module.error("Error: SessionTab.updateScreenshot missing managed object")
continue
}
tab.index = Int32(index)
Expand All @@ -176,12 +179,14 @@ extension SessionTab {

public static func updateAll(tabs: [(tabId: UUID, interactionState: Data, title: String, url: URL)]) {
DataController.performOnMainContext { context in
for (index, tab) in tabs.enumerated() {
guard let sessionTab = Self.from(tabId: tab.tabId, in: context) else { return }
for tab in tabs {
guard let sessionTab = Self.from(tabId: tab.tabId, in: context) else {
Logger.module.error("Error: SessionTab.updateAll missing managed object")
continue
}
sessionTab.interactionState = tab.interactionState
sessionTab.title = tab.title
sessionTab.url = tab.url
sessionTab.index = Int32(index)
}

do {
Expand Down

0 comments on commit 36b3483

Please sign in to comment.