Bug 194924 - REGRESSION(PSON) Scroll position is sometimes not restored on history navigation
Summary: REGRESSION(PSON) Scroll position is sometimes not restored on history navigation
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Chris Dumez
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2019-02-21 16:38 PST by Chris Dumez
Modified: 2019-02-22 10:25 PST (History)
6 users (show)

See Also:


Attachments
Patch (6.88 KB, patch)
2019-02-21 16:45 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (6.73 KB, patch)
2019-02-21 18:28 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (6.57 KB, patch)
2019-02-21 19:45 PST, Chris Dumez
no flags Details | Formatted Diff | Diff
Patch (8.49 KB, patch)
2019-02-21 20:40 PST, Chris Dumez
ggaren: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumez 2019-02-21 16:38:50 PST
Scroll position is sometimes not restored on history navigation when PSON is enabled.
Comment 1 Chris Dumez 2019-02-21 16:39:06 PST
<rdar://problem/48216125>
Comment 2 Chris Dumez 2019-02-21 16:45:01 PST
Created attachment 362671 [details]
Patch
Comment 3 Alex Christensen 2019-02-21 16:56:07 PST
Comment on attachment 362671 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=362671&action=review

> Source/WebKit/WebProcess/WebPage/WebPage.cpp:2710
> +    SetForScope<void (*)(WebCore::HistoryItem&)> bypassHistoryItemUpdateNotifications(WebCore::notifyHistoryItemChanged, ignoreHistoryItemUpdates);

ignoreHistoryItemUpdates could be replaced by my favorite lambda [](auto){}

> Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:4837
>  TEST(ProcessSwap, ScrollPositionRestoration)

This test passes for me in debug before the change.  Is that expected?
Comment 4 Alex Christensen 2019-02-21 17:22:18 PST
Comment on attachment 362671 [details]
Patch

A release build also shows the test doesn't exercise the fix.
Comment 5 Chris Dumez 2019-02-21 18:20:28 PST
(In reply to Alex Christensen from comment #4)
> Comment on attachment 362671 [details]
> Patch
> 
> A release build also shows the test doesn't exercise the fix.

Did you try on iOS? It definitely reproduced the bug for me with the iOS simulator.
Comment 6 Chris Dumez 2019-02-21 18:21:54 PST
Comment on attachment 362671 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=362671&action=review

Not sure why the r-

>> Source/WebKit/WebProcess/WebPage/WebPage.cpp:2710
>> +    SetForScope<void (*)(WebCore::HistoryItem&)> bypassHistoryItemUpdateNotifications(WebCore::notifyHistoryItemChanged, ignoreHistoryItemUpdates);
> 
> ignoreHistoryItemUpdates could be replaced by my favorite lambda [](auto){}

Will this work even though it expects a function pointer?
Comment 7 Chris Dumez 2019-02-21 18:28:46 PST
Created attachment 362681 [details]
Patch
Comment 8 EWS Watchlist 2019-02-21 18:30:59 PST
Attachment 362681 [details] did not pass style-queue:


ERROR: Source/WebKit/WebProcess/WebPage/WebPage.cpp:2708:  Missing space before {  [whitespace/braces] [5]
ERROR: Source/WebKit/WebProcess/WebPage/WebPage.cpp:2708:  Missing space inside { }.  [whitespace/braces] [5]
Total errors found: 2 in 4 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 9 Ryosuke Niwa 2019-02-21 19:00:58 PST
Comment on attachment 362681 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=362681&action=review

This seems sensible but I'd like someone familiar with the relevant code review it.W

> Source/WebKit/ChangeLog:14
> +        wuch as the scroll position.

Nit: wuch.

> Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:4863
> +    TestWebKitAPI::Util::sleep(0.5);

What's up with all these sleeps?
Comment 10 Chris Dumez 2019-02-21 19:38:37 PST
(In reply to Ryosuke Niwa from comment #9)
> Comment on attachment 362681 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=362681&action=review
> 
> This seems sensible but I'd like someone familiar with the relevant code
> review it.W
> 
> > Source/WebKit/ChangeLog:14
> > +        wuch as the scroll position.
> 
> Nit: wuch.
> 

Whoops.

> > Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:4863
> > +    TestWebKitAPI::Util::sleep(0.5);
> 
> What's up with all these sleeps?

Need to give some time for the ipc to get received by the uiprocess.
Comment 11 Chris Dumez 2019-02-21 19:45:03 PST
Created attachment 362687 [details]
Patch
Comment 12 EWS Watchlist 2019-02-21 19:47:10 PST
Attachment 362687 [details] did not pass style-queue:


ERROR: Source/WebKit/WebProcess/WebPage/WebPage.cpp:2708:  Missing space before {  [whitespace/braces] [5]
ERROR: Source/WebKit/WebProcess/WebPage/WebPage.cpp:2708:  Missing space inside { }.  [whitespace/braces] [5]
Total errors found: 2 in 4 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 13 Ryosuke Niwa 2019-02-21 20:01:29 PST
(In reply to Chris Dumez from comment #10)
>
> > > Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:4863
> > > +    TestWebKitAPI::Util::sleep(0.5);
> > 
> > What's up with all these sleeps?
> 
> Need to give some time for the ipc to get received by the uiprocess.

There's no way to round-trip IPC to web content process to ensure such a state? Relying on a sleep makes me worry that this test might become flaky in the future...
Comment 14 Chris Dumez 2019-02-21 20:11:09 PST
(In reply to Ryosuke Niwa from comment #13)
> (In reply to Chris Dumez from comment #10)
> >
> > > > Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:4863
> > > > +    TestWebKitAPI::Util::sleep(0.5);
> > > 
> > > What's up with all these sleeps?
> > 
> > Need to give some time for the ipc to get received by the uiprocess.
> 
> There's no way to round-trip IPC to web content process to ensure such a
> state? Relying on a sleep makes me worry that this test might become flaky
> in the future...

I agree it is not ideal but I was already happy to be able to write a test for this. I will try to find a more robust way tomorrow.
Comment 15 Chris Dumez 2019-02-21 20:40:45 PST
Created attachment 362689 [details]
Patch
Comment 16 Chris Dumez 2019-02-21 20:41:43 PST
Comment on attachment 362671 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=362671&action=review

>>> Source/WebKit/WebProcess/WebPage/WebPage.cpp:2710
>>> +    SetForScope<void (*)(WebCore::HistoryItem&)> bypassHistoryItemUpdateNotifications(WebCore::notifyHistoryItemChanged, ignoreHistoryItemUpdates);
>> 
>> ignoreHistoryItemUpdates could be replaced by my favorite lambda [](auto){}
> 
> Will this work even though it expects a function pointer?

Your proposal did not build with WPE.
Comment 17 EWS Watchlist 2019-02-21 20:43:13 PST
Attachment 362689 [details] did not pass style-queue:


ERROR: Source/WebKit/WebProcess/WebPage/WebPage.cpp:2708:  Missing space before {  [whitespace/braces] [5]
ERROR: Source/WebKit/WebProcess/WebPage/WebPage.cpp:2708:  Missing space inside { }.  [whitespace/braces] [5]
Total errors found: 2 in 6 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 18 Chris Dumez 2019-02-21 20:51:02 PST
Woohoo found something that builds on WPE.
Comment 19 Geoffrey Garen 2019-02-22 10:15:54 PST
Comment on attachment 362689 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=362689&action=review

r=me

> Source/WebKit/ChangeLog:10
> +        call restoreSessionInternal() to restore the HistoryItems based on the UIProcess'

UIProcess's

> Source/WebKit/ChangeLog:12
> +        updates back to the UIProcess. Without PSON, this would be unnecessary but harmless.

When did this ever happen without PSON? (I think only PSON creates a new WebPage for backforward navigation.)

> Source/WebKit/WebProcess/WebPage/WebPage.cpp:2705
> +    // Since we're merely restoring HistoryItems from the UIProcess, there is no need to send HistoryItem update notifications back to the UIProcess.

I would comment more strongly: Avoid sending HistoryItem updates to the UIProcess because we may overwrite important in-flight state from the UI process (like scroll position).

> Tools/TestWebKitAPI/Tests/WebKitCocoa/ProcessSwapOnNavigation.mm:4816
> +// Pages with dedicated workers do not go into page cache.
> +var myWorker = new Worker('worker.js');

Seems like it would be nice to add window.internals.disablePageCache() for cases like this.
Comment 20 Alex Christensen 2019-02-22 10:19:32 PST
(In reply to Chris Dumez from comment #6)
> Will this work even though it expects a function pointer?
Lambdas with no captures can be used as function pointers.  Lambdas with auto parameters are kind of like templates, which was probably what was causing problems with WPE.
Comment 21 Chris Dumez 2019-02-22 10:21:35 PST
Comment on attachment 362689 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=362689&action=review

>> Source/WebKit/ChangeLog:12
>> +        updates back to the UIProcess. Without PSON, this would be unnecessary but harmless.
> 
> When did this ever happen without PSON? (I think only PSON creates a new WebPage for backforward navigation.)

After a crash.
Comment 22 Chris Dumez 2019-02-22 10:25:06 PST
Committed r241950: <https://trac.webkit.org/changeset/241950>