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
[deps] Update to Electron v12 #3318
Conversation
Had to rollback some test dep updates because it broke too much stuff and this is already large. Will work on other updates before trying again to update those. |
* @param {*} fun - effect to run on mount | ||
*/ | ||
const useMountEffect = (fun) => useEffect(fun, []); | ||
const useMountEffect = (fun) => useEffect(fun, []); // eslint-disable-line react-hooks/exhaustive-deps |
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.
hrmm i'm totally fine with disabling eslint here if it's complaining but i'm just wondering as we always had react-hooks/exhaustive-deps
on but it never complained about this one and tbh it shouldn't.
the fun
here is a function param which means it defined inside the scope of useMountEffect
hence i would expect eslint to not complain that it's not in the deps array.
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 started complaining after updating one of the dependencies, so a newer linter version is probably being more aggressive in detecting these requirements.
But I'm confused by this:
the fun here is a function param which means it defined inside the scope of useMountEffect
I might be parsing this phrase wrongly, but I'm not sure this statement is correct. const useMountEffect = /*...*/
is not a function definition, but an assignment of a closure.
In any case, it seems to me the linter is in fact correct in complaining here. Consider:
function MyCompo() {
const [val, setVal] = useState('');
let f = () => console.log("bleh");
if val != '' {
f = () => console.log("blah");
}
useMountEffect(f);
// The above is equivalent to
// useEffect(f, []);
//...
}
This is wrong in all sorts of ways, but the key bit is that the contents of f
var can change arbitrarily between renders (for example, due to the value of the val
state), and thus it must be part of the dependency list for the useEffect
call.
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.
Hrmm I see what you mean, but I think the deps array is about deps of f
not f
itself, which in the example above is the actual effect and not one of it's deps.
If f was () => console.log(val)
I would expect val to be in the deps array but that isn't the case in the example above.
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 agree with your assessment (which is why the warning is also somewhat confusing to me).
I don't know enough about the underlying React and linter behavior to know for sure the origin of the warning, the above was my guess at what was happening based on useMountEffect
using a parametrized function (vs an inline one).
@@ -40,7 +40,7 @@ const EyeFilterMenuWithSliderMenu = ({ | |||
}); | |||
|
|||
const onChangeSliderCallback = useCallback( | |||
debounce((value, limit) => { | |||
() => debounce((value, limit) => { |
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.
lodash
debounce
returns a debounced version of its parameter. To call onChangeSliderCallback
after this change will return the debounced function instead of executing 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.
Please see the review fix commit. The simplest way I could see to fix this without resorting to disabling the warning (as in the other issue Amass pointed out) was to switch to useMemo
: the inline function now produces the memoized, debounced callback (and correctly recreates it if onChangeSlider
itself changes).
It seems to me though, looking at where onChangeSlider
is ultimately defined (the HistoryTab
component) it's being redefined at every component render there, thus causing unnecessary renders of the menu.
Anyways, hopefully this is correct. I also bumped up the delay a bit. 100ms seems way too small to debounce something that depends on fine use motion of the mouse.
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.
@matheusd That sounds as a good way to approach it, regarding unnecessary re-renders - I would try wrapping onChangeSliderValue
in HistoryTab
with useCallback
which should resolve the redefine/rerender issue.
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 well
d220101
to
1e42bc6
Compare
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.
tACK
This updates electron to the most recent version (v12). Unfortunately, several other dependencies had to be updated alongside it in order to make it work (too much interdependencies between them). OTOH, the win32ipc did not need to be updated.
Summary of changes:
Future PRs will look into fixing the trezor-connect dep, upgrading to webpack 5 to keep up with the most recent releases of the major dependencies of the project and using the new security features provided by electron v12.
Tested and working: linux (
yarn {dev, build && start, package-dev-linux}
) windows (yarn {dev, package}
).Windows
yarn build && yarn start
isn't currently working.