Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
Bug 1868469 - Update the url immediately for existing engineSession
Browse files Browse the repository at this point in the history
When we have an existing `engineSession` we use an optimized route to
load the url without needing to dispatch the load action. This is still
a valid performance improvement to make page loads faster.

However, in this code path we do not end up update the url in the state
until we get back a response from the Engine. This gives a perceived
performance loss of slow browsing. Updating the url gives UI components
an immediate update which reflects a change that would have been entered
by the user.

It was considered if we should do this in a middleware, but since this
is an optimized route, we should not wait for the middleware to process
the action before we perform the state update.
  • Loading branch information
jonalmeida authored and mergify[bot] committed Feb 12, 2024
1 parent 9beaef6 commit a26e21e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

package mozilla.components.feature.session

import mozilla.components.browser.state.action.ContentAction
import mozilla.components.browser.state.action.CrashAction
import mozilla.components.browser.state.action.EngineAction
import mozilla.components.browser.state.action.LastAccessAction
Expand Down Expand Up @@ -99,6 +100,13 @@ class SessionUseCases(
flags = flags,
additionalHeaders = additionalHeaders,
)
// Update the url in content immediately until the engine updates with any new changes to the state.
store.dispatch(
ContentAction.UpdateUrlAction(
loadSessionId,
url,
),
)
store.dispatch(
EngineAction.OptimizedLoadUrlTriggeredAction(
loadSessionId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import mozilla.components.browser.state.action.EngineAction
import mozilla.components.browser.state.action.TabListAction
import mozilla.components.browser.state.engine.EngineMiddleware
import mozilla.components.browser.state.selector.findTab
import mozilla.components.browser.state.selector.selectedTab
import mozilla.components.browser.state.state.BrowserState
import mozilla.components.browser.state.state.TabSessionState
import mozilla.components.browser.state.state.createCustomTab
Expand Down Expand Up @@ -80,6 +81,7 @@ class SessionUseCasesTest {
assertEquals("mozilla", action.tabId)
assertEquals("https://getpocket.com", action.url)
}
assertEquals("https://getpocket.com", store.state.selectedTab?.content?.url)

useCases.loadUrl("https://www.mozilla.org", LoadUrlFlags.select(LoadUrlFlags.EXTERNAL))
store.waitUntilIdle()
Expand All @@ -93,6 +95,7 @@ class SessionUseCasesTest {
assertEquals("https://www.mozilla.org", action.url)
assertEquals(LoadUrlFlags.select(LoadUrlFlags.EXTERNAL), action.flags)
}
assertEquals("https://www.mozilla.org", store.state.selectedTab?.content?.url)

useCases.loadUrl("https://firefox.com", store.state.selectedTabId)
store.waitUntilIdle()
Expand All @@ -102,6 +105,7 @@ class SessionUseCasesTest {
assertEquals("mozilla", action.tabId)
assertEquals("https://firefox.com", action.url)
}
assertEquals("https://firefox.com", store.state.selectedTab?.content?.url)

useCases.loadUrl.invoke(
"https://developer.mozilla.org",
Expand Down
5 changes: 4 additions & 1 deletion docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ permalink: /changelog/

* **all components**
* All new usages of the `concept-fetch` component to make fetch requests now have conservative-mode off by default. Current features will continue to use conservative mode until individually updated.

* **browser-toolbar**
* Add `showMenuButton` and `hideMenuButton` API to `BrowserToolbar` and `DisplayToolbar` to allow hiding and showing of the menu button in
the `BrowserToolbar` [Bug 1864760](https://bugzilla.mozilla.org/show_bug.cgi?id=1864760)

* **feature-customtabs**
* Fallback behaviour when failing to open a new window in custom tab will now be loading the URL directly in the same custom tab. [Bug 1832357](https://bugzilla.mozilla.org/show_bug.cgi?id=1832357)

* **feature-session**
* Update URL in the store immediately when using the optimized load URL code path.

# 123.0
* [Commits](https://github.com/mozilla-mobile/firefox-android/compare/releases_v122..releases_v123)
* [Dependencies](https://github.com/mozilla-mobile/firefox-android/blob/releases_v123/android-components/plugins/dependencies/src/main/java/DependenciesPlugin.kt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class CrashReportingTest : TestSetup() {
verifyPageContent(tabCrashMessage)
}.openTabDrawer {
verifyExistingOpenTabs(firstWebPage.title)
verifyExistingOpenTabs(secondWebPage.title)
verifyExistingOpenTabs("about:crashcontent")
}.closeTabDrawer {
}.goToHomescreen {
verifyExistingTopSitesList()
Expand Down

0 comments on commit a26e21e

Please sign in to comment.