Fix white flash during reconnection in dark mode#1155
Open
Fix white flash during reconnection in dark mode#1155
Conversation
WKWebView.underPageBackgroundColor (iOS 15+) controls the WebKit rendering subprocess background, separate from the UIKit layer. Without setting it, it defaults to white even when backgroundColor is .clear and isOpaque is false — causing a visible white flash during reconnection when the DOM body is cleared and the new URL starts loading. Setting underPageBackgroundColor = .systemBackground makes this adaptive, showing dark in dark mode and white in light mode. Fixes #1153 Signed-off-by: Tim Mueller-Seydlitz <timbms@gmail.com>
WKWebView renders in a separate GPU process, so setting isOpaque=false and backgroundColor=.clear on the UIKit layer does not make the WebKit canvas itself transparent. The canvas still flashes white during navigation before content is painted. The fix adds a systemBackground-colored overlay view that covers the webview during page transitions. It is shown at the start of clearExistingPage() and didStartProvisionalNavigation, then faded out in didFinish and didFail. This hides the white flash in all cases: after body removal, during forced reloads, and on reconnection. In dark mode the overlay is near-black (matching systemBackground), replacing the white flash with a colour-appropriate transition. Fixes #1153 Signed-off-by: Tim Mueller-Seydlitz <timbms@gmail.com>
Two bugs prevented the overlay from working: 1. attachWebViewToLayout used view.addSubview() which appends the webview at the top of the z-order. On reconnection when a new webview instance is attached, it landed above the overlay, making it invisible. Fixed by using insertSubview(_:at:0) to always place webviews at the bottom of the stack. 2. The overlay started at alpha=0, leaving the initial blank webview unprotected before the first didStartProvisionalNavigation fires. Fixed by starting at alpha=1 so coverage is immediate from viewDidLoad. Signed-off-by: Tim Mueller-Seydlitz <timbms@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
WKWebView.underPageBackgroundColorcontrols the WebKit rendering subprocess background, which is separate from the UIKit compositing layerbackgroundColor = .clearandisOpaque = false— causing the white flash reported in Reconnection produces a “white page” that flashes briefly and blinds me frequently #1153.systemBackgroundmakes it adaptive (dark in dark mode, white in light mode)Test plan
Fixes #1153