-
Notifications
You must be signed in to change notification settings - Fork 419
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
Put the BrowserConnectionStatus into redux state #3781
Conversation
Codecov Report
@@ 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
Continue to review full report at Codecov.
|
There was a problem hiding this 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.
src/components/app/DragAndDrop.js
Outdated
_handleProfileDrop = (event: DragEvent) => { | ||
_handleProfileDrop = async (event: DragEvent) => { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh yes, leftover indeed.
const browserConnection = | ||
browserConnectionStatus.status === 'ESTABLISHED' | ||
? browserConnectionStatus.browserConnection | ||
: null; |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)) { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
src/components/app/Home.js
Outdated
>, | ||
+triggerLoadingFromUrl: typeof triggerLoadingFromUrl, | ||
+onLoadProfileFromFileRequested: (file: File) => void, | ||
+onLoadProfileFromUrlRequested: (url: string) => void, | ||
|}; | ||
|
||
type ActionButtonsState = { | ||
isLoadFromUrlPressed: boolean, | ||
}; | ||
|
||
type LoadFromUrlProps = { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
src/components/app/Home.js
Outdated
createBrowserConnection('Firefox/123.0').then((browserConnectionStatus) => { | ||
const browserConnection = | ||
browserConnectionStatus.status === 'ESTABLISHED' | ||
? browserConnectionStatus.browserConnection | ||
: undefined; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.
…ction call further outside.
cfaaf64
to
10a80c9
Compare
- 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)
This makes it easily accessible anywhere we need it, and is an acceptable solution to the conundrum I encountered in #3656.