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

Fix NetworkController Redux selectors #5193

Merged
merged 1 commit into from
Jan 24, 2025
Merged

Fix NetworkController Redux selectors #5193

merged 1 commit into from
Jan 24, 2025

Conversation

mcmire
Copy link
Contributor

@mcmire mcmire commented Jan 23, 2025

Explanation

When running tests, we are seeing the following warning:

An input selector returned a different result when passed same arguments. This means your output selector will likely run more frequently than intended.

This is happening because the "input selector" in selectAvailableNetworkClientIds returns a new object reference (returned by getNetworkConfigurations) each time it is called. This violates the Redux guidelines outlined here: https://redux.js.org/usage/deriving-data-selectors#optimizing-selectors-with-memoization.

To fix this, we split off the "input selector" into its own selector function which we then memoize.

References

Changelog

(Updated in PR.)

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've highlighted breaking changes using the "BREAKING" category above as appropriate
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

@mcmire mcmire force-pushed the fix-network-selectors branch 3 times, most recently from 973e88a to eb7baeb Compare January 23, 2025 23:14
When running tests, we are seeing the following warning:

> An input selector returned a different result when passed same
> arguments. This means your output selector will likely run more
> frequently than intended.

This is happening because the "input selector" in
`selectAvailableNetworkClientIds` returns a new object reference (returned
by `getNetworkConfigurations`) each time it is called. This violates the
Redux guidelines outlined here:
<https://redux.js.org/usage/deriving-data-selectors#optimizing-selectors-with-memoization>.

To fix this, we split off the "input selector" into its own selector
function which we then memoize.
@mcmire mcmire force-pushed the fix-network-selectors branch from eb7baeb to 816d47b Compare January 23, 2025 23:35
@mcmire mcmire marked this pull request as ready for review January 23, 2025 23:50
@mcmire mcmire requested review from a team as code owners January 23, 2025 23:50
Copy link
Contributor

@cryptodev-2s cryptodev-2s left a comment

Choose a reason for hiding this comment

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

LGTM!

@mcmire mcmire merged commit 3dc082b into main Jan 24, 2025
127 checks passed
@mcmire mcmire deleted the fix-network-selectors branch January 24, 2025 00:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants