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

Put the BrowserConnectionStatus into redux state #3781

Merged

Conversation

mstange
Copy link
Contributor

@mstange mstange commented Dec 31, 2021

This makes it easily accessible anywhere we need it, and is an acceptable solution to the conundrum I encountered in #3656.

@mstange mstange requested a review from julienw December 31, 2021 11:30
@mstange mstange self-assigned this Dec 31, 2021
@codecov
Copy link

codecov bot commented Dec 31, 2021

Codecov Report

Merging #3781 (cfaaf64) into main (ccabe8e) will increase coverage by 0.03%.
The diff coverage is 78.12%.

❗ Current head cfaaf64 differs from pull request most recent head 10a80c9. Consider uploading reports for the commit 10a80c9 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main    #3781      +/-   ##
==========================================
+ Coverage   87.85%   87.88%   +0.03%     
==========================================
  Files         269      269              
  Lines       22364    22434      +70     
  Branches     5737     5745       +8     
==========================================
+ Hits        19647    19716      +69     
- Misses       2506     2507       +1     
  Partials      211      211              
Impacted Files Coverage Δ
src/app-logic/browser-connection.js 86.66% <ø> (ø)
src/components/app/ProfileLoader.js 73.68% <ø> (+4.45%) ⬆️
src/actions/receive-profile.js 86.28% <33.33%> (-0.21%) ⬇️
src/components/app/Home.js 71.11% <50.00%> (-0.66%) ⬇️
src/actions/app.js 88.54% <100.00%> (+0.24%) ⬆️
src/components/app/DragAndDrop.js 98.46% <100.00%> (ø)
src/components/app/UrlManager.js 84.05% <100.00%> (+0.47%) ⬆️
src/reducers/app.js 99.37% <100.00%> (+0.03%) ⬆️
src/selectors/app.js 57.04% <100.00%> (+1.18%) ⬆️
src/selectors/cpu.js 100.00% <0.00%> (ø)
... and 5 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ccabe8e...10a80c9. Read the comment docs.

Copy link
Contributor

@julienw julienw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the change!

If I'd done this, I'd have implemented a singleton in browser-connection (which is a global effectively) for more simplicity. Indeed this will never change after the app is loaded.
But I agree that this might be more painful in tests. So I don't mind using redux for this.

Comment on lines 150 to 153
_handleProfileDrop = (event: DragEvent) => {
_handleProfileDrop = async (event: DragEvent) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be a leftover? Or did you want to await retrieveProfileFromFile too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes, leftover indeed.

Comment on lines 1422 to 1425
const browserConnection =
browserConnectionStatus.status === 'ESTABLISHED'
? browserConnectionStatus.browserConnection
: null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me what is expected here. Because we're in a test it would be good to better assert what result we have in browserConnection after the call to createBrowserConnection.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I converted this to an if + throw. An expect(...).toBe(...) is not enough to convince flow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, nevermind, this test always ended up with browserConnectionStatus.status === 'DENIED', because it mocks a WebChannel which always says "No such channel".
So I was able to simplify this whole setup: We no longer need to mock a WebChannel, we can just pass a null browserConnection. And we don't need to call createBrowserConnection.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this review comment was definitely warranted. I was confused about what the test was expecting!

@@ -101,7 +107,9 @@ class UrlManagerImpl extends React.PureComponent<Props> {
let browserConnectionStatus;
const route = window.location.pathname.split('/').filter((s) => s)[0];
if (['from-browser', 'from-addon', 'from-file'].includes(route)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at this now, I wonder why it's not happening for from-url or even compare? What happens when the datasource changes (eg moving from 'none' to 'from-file')?

update: I see that when loading from a file, we create a browser connection at that moment. Note that there shouldn't be a from-file here because we can't load "from-file" at load time.

I think I'd create the connection for all datasources always but I'm fine if it's in a follow-up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's definitely planned for a follow-up. The current behavior is not what we want, but it's equivalent to what we had before.

@@ -101,7 +107,9 @@ class UrlManagerImpl extends React.PureComponent<Props> {
let browserConnectionStatus;
const route = window.location.pathname.split('/').filter((s) => s)[0];
if (['from-browser', 'from-addon', 'from-file'].includes(route)) {
updateBrowserConnectionStatus({ status: 'WAITING' });
browserConnectionStatus = await createBrowserConnection('Firefox/123.0');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't remember why we override the user agent here? Is that only so that this passes in tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests, and because doing so didn't change behavior. This definitely needs to be addressed at some point, for example to fix #3638.

>,
+triggerLoadingFromUrl: typeof triggerLoadingFromUrl,
+onLoadProfileFromFileRequested: (file: File) => void,
+onLoadProfileFromUrlRequested: (url: string) => void,
|};

type ActionButtonsState = {
isLoadFromUrlPressed: boolean,
};

type LoadFromUrlProps = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you can make this an exact object now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Comment on lines 459 to 463
createBrowserConnection('Firefox/123.0').then((browserConnectionStatus) => {
const browserConnection =
browserConnectionStatus.status === 'ESTABLISHED'
? browserConnectionStatus.browserConnection
: undefined;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we create a browser connection for all data sources like suggested, then I believe we can retrieve it here instead of creating it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's the plan. Just trying to keep the set of behavior changes minimal here.

@mstange
Copy link
Contributor Author

mstange commented Jan 5, 2022

If I'd done this, I'd have implemented a singleton in browser-connection (which is a global effectively) for more simplicity. Indeed this will never change after the app is loaded. But I agree that this might be more painful in tests.

Exactly, and painful tests mean painful code changes. I've struggled enough with existing tests recently that I'm now strongly leaning towards avoiding globals wherever possible.

…le and into the callers.

This introduces some code duplication, while making no changes to behavior.
A future commit in this series removes the code duplication again.
@mstange mstange force-pushed the browserconnection-in-redux-state branch from cfaaf64 to 10a80c9 Compare January 5, 2022 13:15
@mstange mstange enabled auto-merge January 5, 2022 13:16
@mstange mstange merged commit 4d921af into firefox-devtools:main Jan 5, 2022
@mstange mstange mentioned this pull request Jan 6, 2022
mstange added a commit that referenced this pull request Jan 6, 2022
 - Recommend gecko_profile_generator.py for Android (PR #3763
 - Replace fetchSource thunk action with a <SourceFetcher>. (PR #3765)
 - ⬆️ Update @fluent/bundle to version 0.17.1 (PR #3774)
 - ⬆️ Update @fluent/langneg to version 0.6.1 (PR #3775)
 - ⬆️ Update @fluent/react to version 0.14.1 (PR #3776)
 - Update all development Yarn dependencies (2022-01-03) (PR #3773)
 - Remove the prop-types dependency (PR #3784)
 - Check all threads for threadCPUDelta. (PR #3785)
 - Limit default visible threads to 15. (PR #3743)
 - Put the BrowserConnectionStatus into redux state (PR #3781)
 - Add tests for source fetching. (PR #3780)
 - Add support for fetching source code from local symbol servers (PR #3777)
 - Add support for fetching source code from crates.io. (PR #3778)
 - Add support for fetching source code from the browser, for local Firefox builds (PR #3786)
 - When the user sanitizes a fake global track, we need to sanitize its real children tracks (PR #3788)
 - Fix a few styles of the timeline header (PR #3792)
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.

2 participants