Bug 207516 - Flash of white can occur if JS forces an early layout
Summary: Flash of white can occur if JS forces an early layout
Alias: None
Product: WebKit
Classification: Unclassified
Component: Layout and Rendering (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ben Nham
Keywords: InRadar
: 204828 (view as bug list)
Depends on:
Reported: 2020-02-10 16:08 PST by Ben Nham
Modified: 2020-02-13 17:31 PST (History)
7 users (show)

See Also:

repro case (1.37 KB, application/zip)
2020-02-10 16:08 PST, Ben Nham
no flags Details
Patch (2.28 KB, patch)
2020-02-10 16:47 PST, Ben Nham
no flags Details | Formatted Diff | Diff
Patch (5.25 KB, patch)
2020-02-13 16:46 PST, Ben Nham
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ben Nham 2020-02-10 16:08:43 PST
Created attachment 390306 [details]
repro case

In https://bugs.webkit.org/show_bug.cgi?id=134833, we added in a hack to force a layer flush on first layout on Mac (rather than waiting for first non-empty layout as we do for all other platforms). This can cause a flash of white if the first layout creates an empty render tree, e.g. if JS forces an empty layout early on in the page. We also see this flash-of-white issue in several real-world webpages on our PLT test suite, e.g. NYT and FB.

We should probably revert this change. This fixes the issue in our PLT content and in the attached repro case (which can be run by executing something like `php -S localhost:8081` and then navigating to http://localhost:8081).
Comment 1 Radar WebKit Bug Importer 2020-02-10 16:09:37 PST
Comment 2 Ben Nham 2020-02-10 16:47:44 PST
Created attachment 390315 [details]
Comment 3 Ben Nham 2020-02-10 16:50:04 PST
I've verified that this patch fixes the repro case as well as the flash of white on NYT and FB PLT content.

I'm also kicking off some PLT5 A/B tests to make sure this doesn't cause a perf regression. I don't anticipate one since in theory an extra paint on FirstLayout should not cause DidFirstVisuallyNonEmptyLayout to fire any later (if anything, it could marginally help).
Comment 4 Ben Nham 2020-02-10 17:00:45 PST
The original reason why we did https://bugs.webkit.org/show_bug.cgi?id=134833 years ago was for a scenario like this:

1. Open Safari with status bar enabled
2. Cmd+F for some text on a page
3. Click on some link with the find bar still open
4. A 20px white gap appears where the status bar used to be

I can no longer repro this issue with the current Safari with the current patch (which is good).
Comment 5 Antti Koivisto 2020-02-11 09:42:53 PST
Might want to check if those test failures are real.
Comment 6 Ben Nham 2020-02-13 13:15:13 PST
*** Bug 204828 has been marked as a duplicate of this bug. ***
Comment 7 Ben Nham 2020-02-13 16:46:06 PST
Created attachment 390704 [details]
Comment 8 Ben Nham 2020-02-13 16:50:06 PST
The latest patch should fix the test failures.

* fast/scrolling/rtl-scrollbars-listbox-scroll.html: This test was scrolling a list box from an inline script as the main resource was being parsed. Since the list box is not enough to be considered visually significant, after this patch we don't render the list box until after the inline script executes. Fixed by moving the scrolling code to after the document finishes loading.
* imported/w3c/web-platform-tests/css/css-transitions/before-load-001.html: As the top of this file indicates, this doesn't actually test behavior specified in the standard. It produces different results depending on when first paint occurs. As a result, we had already skipped this test on iOS where it was failing (https://bugs.webkit.org/show_bug.cgi?id=203416). Since this patch makes Mac first paint behave like iOS first paint, I propose skipping this test on Mac as well for now and tracking fixing the test for both iOS and Mac in https://bugs.webkit.org/show_bug.cgi?id=203416.
Comment 9 Ben Nham 2020-02-13 17:00:19 PST
Also, according to the A/b bots, this is a 1.75% - 3% improvement on PLT5 for Mac.
Comment 10 WebKit Commit Bot 2020-02-13 17:31:10 PST
Comment on attachment 390704 [details]

Clearing flags on attachment: 390704

Committed r256577: <https://trac.webkit.org/changeset/256577>
Comment 11 WebKit Commit Bot 2020-02-13 17:31:12 PST
All reviewed patches have been landed.  Closing bug.