Skip to content

Fix white flash during reconnection in dark mode#1155

Open
timbms wants to merge 3 commits intodevelopfrom
fix/reconnect-white-flash
Open

Fix white flash during reconnection in dark mode#1155
timbms wants to merge 3 commits intodevelopfrom
fix/reconnect-white-flash

Conversation

@timbms
Copy link
Copy Markdown
Contributor

@timbms timbms commented Apr 18, 2026

Summary

Test plan

  • Put device in dark mode
  • Open the app and let it connect
  • Force a reconnection (e.g. toggle airplane mode off/on, or background and foreground the app after a network interruption)
  • Verify no white flash appears during reconnection
  • Repeat in light mode and verify normal appearance

Fixes #1153

timbms added 3 commits April 18, 2026 21:58
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>
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.

Reconnection produces a “white page” that flashes briefly and blinds me frequently

1 participant