Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When navigating back new tab page doesn't load #5249

Closed
corymcdonald opened this issue Jul 15, 2019 · 7 comments · Fixed by brave/brave-core#2957
Closed

When navigating back new tab page doesn't load #5249

corymcdonald opened this issue Jul 15, 2019 · 7 comments · Fixed by brave/brave-core#2957

Comments

@corymcdonald
Copy link

corymcdonald commented Jul 15, 2019

Description

On the nightly version of Chrome
Version 0.69.44 Chromium: 75.0.3770.100 (Official Build) nightly (64-bit)

Steps to Reproduce

  1. Open multiple new tab pages
  2. go to one of the NTP tabs
  3. search
  4. press back
  5. page like this is shown

Actual result:

image

Expected result:

image

Reproduces how often:

pretty much every time

Brave version (brave://version info)

Brave 0.69.44 Chromium: 75.0.3770.100 (Official Build)nightly (64-bit)
Revision cd0b15c8b6a4e70c44e27f35c37a4029bad3e3b0-refs/branch-heads/3770@{#1033}
OS Mac OS X
JavaScript V8 7.5.288.23
Flash (Disabled)
User Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36
Command Line /Applications/Brave Browser Nightly.app/Contents/MacOS/Brave Browser Nightly --enable-dom-distiller --disable-domain-reliability --disable-chrome-google-url-tracking-client --no-pings --extensions-install-verification=enforce_strict --enable-features=NewExtensionUpdaterService,DesktopPWAWindowing,SimplifyHttpsIndicator --disable-features=AutofillSaveCardSignInAfterLocalSave,AutofillServerCommunication,NetworkService,UnifiedConsent --flag-switches-begin --allow-insecure-localhost --load-media-router-component-extension=1 --enable-features=NewExtensionUpdaterService,DesktopPWAWindowing,SimplifyHttpsIndicator,CastAllowAllIPs,ViewsCastDialog --flag-switches-end
Executable Path /Applications/Brave Browser Nightly.app/Contents/MacOS/Brave Browser Nightly
Profile Path /Users/cory/Library/Application Support/BraveSoftware/Brave-Browser-Nightly/Default

Version/Channel Information:

Nightly

  • Can you reproduce this issue with the current release?
    no
  • Can you reproduce this issue with the beta channel?
    no
  • Can you reproduce this issue with the dev channel?
    no
  • Can you reproduce this issue with the nightly channel?
    yes

Other Additional Information:

  • Does the issue resolve itself when disabling Brave Shields?
  • Does the issue resolve itself when disabling Brave Rewards?
  • Is the issue reproducible on the latest version of Chrome?

Miscellaneous Information:

@imptrx
Copy link

imptrx commented Jul 16, 2019

Looked into reproducing the issue and it seems non-deterministic in terms of when I get the "blank" menu versus "last known state of NTP." However, it does require a multiple NTPs to be open at the same time.

Just from a glance it looks some conflict/race-condition is causing our initialize function not to be called properly (to load the preferences object) when we press the back button and thus we're rendering solely based on the default values in redux?

cc: @petemill @cezaraugusto

@petemill
Copy link
Member

petemill commented Jul 16, 2019

From what you're saying that'll most likely be caused by calling initialize only on DOMContentLoaded. When the JS runs, DOMContentLoaded may have already fired, so we would need to check if the document is ready first. Something like:

if (document.readyState === 'interactive') {
   initialize()
} else {
	document.addEventListener('DOMContentLoaded', initialize)
}

...or probably more clearly use readystatechange instead of DOMContentLoaded and test for an 'interactive' value.

@imptrx
Copy link

imptrx commented Jul 16, 2019

@petemill I dug around a bit further and it doesn't seem like it isn't a problem with initialize function as thought previously. It's defaulting our NTP settings to false because chrome.getVariableValue(key) is giving us "" rather than true/false in the PreferencesAPI.

Perhaps it's a race condition where we are requesting the preferences object from chrome before it exists?

@petemill
Copy link
Member

petemill commented Jul 16, 2019

@imptrx good find, we may have to convert to using the more-common way of setting properties on the webui, using loadTimeData, rather than SetWebUIProperty. That will require a c++ change. It could be that as we're calling SetWebUIProperty only on RenderViewReady that the race condition is that initialize is called before this event. It's a shame that even making sure initialize was fired didn't cause the variable to be read later.

@imptrx
Copy link

imptrx commented Jul 16, 2019

I don't think I have the required depth to make that change 😞 - would you mind taking this over?

@petemill
Copy link
Member

petemill commented Jul 18, 2019

Verified that when navigating back, the page doens't initially have access to anything set via SetWebUIProperty. This is because we don't get the RenderViewReady event, since it's reused (but apparent not the WebUIProperties).

However, the page does have access to properties set via loadTimeData, so I do suggest we refactor to using that method:

image

This screenshot is some logging I added taken of a page after navigating 'back'. It shows that the page does not have access to the adsBlockedStat variable value at page load (it's blank where the 35 should be). If we force that to be set after some JS request for it, then the variable is accessible again. However, the page did have access to the textDirection property of loadTimeData (value of "ltr" set via DataSource->AddString in c++) when the navigation back occured.

@rebron rebron added the priority/P3 The next thing for us to work on. It'll ride the trains. label Jul 19, 2019
petemill added a commit to brave/brave-core that referenced this issue Jul 26, 2019
Fix brave/brave-browser#5249

The previous method of wvh->SetWebUIProperty has issues in that the rvh does not always fire the 'ready' event, especially when navigating 'back'. Using DataSource is a more consistent chromium method for sending properties to the JS context. However, this is usually used for non-changing data. Whilst an UpdateDataSource function does exist, that kind of data is usually pulled from the JS via an explicit call to the C++ WebUI, so we may have to go down that route. The issue with the implementation in this commit is that a page may miss the 'updated' events that fire, for example due to have being navigated away and then back to the page.

- Creates JS -> C++ functions to get data for: Preferences, Stats and PrivateProperties (alternativeSearchEngine). loadTimeData is also not a great place for data which can change. Although a DataSource (i.e. strings.js and loadTimeData.data) can be updated, it is complicated and is not normal chromium pattern. Since this data is not required exactly at page creation (since it is not read via static HTML but via React in JS), then we can afford the time it takes to request this data via JS.
- Converting to a JS API required refactoring some of the app store / reducer initialization, including creating the concept of 'initial data' which is any data required to render the page. Since we need Preferences to know what to show, and we need Stats since they are shown on the initial page load, then those are contained within.

Includes some minor cleanup with regard to 'API' separation and definition.
- Fixes storage being loaded multiple times during redux init (the function is called with an empty state param 3 times, so the state was being loaded from storage 3 times).
- Only saves to local storage the state which we will be re-used.
@kjozwiak kjozwiak added this to the 0.70.x - Nightly milestone Jul 26, 2019
petemill added a commit to brave/brave-core that referenced this issue Sep 10, 2019
Fix brave/brave-browser#5249

The previous method of wvh->SetWebUIProperty has issues in that the rvh does not always fire the 'ready' event, especially when navigating 'back'. Using DataSource is a more consistent chromium method for sending properties to the JS context. However, this is usually used for non-changing data. Whilst an UpdateDataSource function does exist, that kind of data is usually pulled from the JS via an explicit call to the C++ WebUI, so we may have to go down that route. The issue with the implementation in this commit is that a page may miss the 'updated' events that fire, for example due to have being navigated away and then back to the page.
SetWebUIProperty was also causing issues with browser tests in guest windows.

- Creates JS -> C++ functions to get data for: Preferences, Stats and PrivateProperties (alternativeSearchEngine). loadTimeData is also not a great place for data which can change. Although a DataSource (i.e. strings.js and loadTimeData.data) can be updated, it is complicated and is not normal chromium pattern. Since this data is not required exactly at page creation (since it is not read via static HTML but via React in JS), then we can afford the time it takes to request this data via JS.
- Converting to a JS API required refactoring some of the app store / reducer initialization, including creating the concept of 'initial data' which is any data required to render the page. Since we need Preferences to know what to show, and we need Stats since they are shown on the initial page load, then those are contained within.

Includes some minor cleanup with regard to 'API' separation and definition.
- Fixes storage being loaded multiple times during redux init (the function is called with an empty state param 3 times, so the state was being loaded from storage 3 times).
- Only saves to local storage the state which we will be re-used.
@btlechowski
Copy link

btlechowski commented Sep 18, 2019

Verification passed on

Brave 0.70.96 Chromium: 76.0.3809.132 (Official Build) beta (64-bit)
Revision fd1acc410994a7a68ac25bc77513d443f3130860-refs/branch-heads/3809@{#1035}
OS Ubuntu 18.04 LTS

Verified STR from the description

image

Verification passed on

Brave 0.70.97 Chromium: 77.0.3865.65 (Official Build) beta (64-bit)
Revision 87a331a3169cab563505fb44011058b904011ba1-refs/branch-heads/3865@{#726}
OS Windows 10 OS Version 1803 (Build 17134.1006)
  • Verified STR from the description
    image

Verification PASSED on macOS 10.14.6 x64 using the following build:

Brave 0.69.128 Chromium: 77.0.3865.75 (Official Build) (64-bit)
Revision 201e747d032611c5f2785cae06e894cf85be7f8a-refs/branch-heads/3865@{#776}
OS macOS Version 10.14.6 (Build 18G95)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment