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

chore: Bump reselect to ^5.1.1 for heterogeneously-typed selectors support #29094

Merged

Conversation

MajorLift
Copy link
Contributor

@MajorLift MajorLift commented Dec 11, 2024

Motivation

Homogenous selector types:

const selectorOne = (state: State) => state.something;
const selectorTwo = (state: State) => state.other;
createSelector([selectorOne, selectorTwo], () => ...);

Heterogenous selector types:

const selectorOne = (state: { something: string }) => state.something;
const selectorTwo = (state: { other: number }) => state.other;
createSelector([selectorOne, selectorTwo], () => ...);

Support for heterogeneous typing is essential for selectors to function properly, because selectors must be both mergeable and atomic. Without heterogeneous selectors, these becoming conflicting objectives.

  • Mergeable:

    • Without heterogeneous typing for selectors, the size of the state type for all selectors tend to inflate. This is because a selector's state must be a supertype of the intersection of the state types of all of its merged selectors, including selectors nested in the definitions of merged selectors.
    • Eventually, many selectors end up being defined with a state type that is close to the entire Redux state.
    • Paradoxically, selectors that only need access to very few properties end up needing to have the widest state type, because they tend to be merged into the most selectors across several nested levels.
  • Atomic:

    • When selectors are actually invoked, including in test files, it's not always practical to prepare and pass in a very large state object.
    • It's both safer and more convenient to restrict the state being passed into the selector to the minimum size required for the selector to function.
    • This requirement becomes incompatible with the mergeability requirement if all selectors must share a common state type.

Enabling merged selectors to accept different, even disjoint state types resolves this issue.

Note

See the MultichainState type for an example of a bloated selector state type which will become unnecessary with this update.

Description

Open in GitHub Codespaces

Related issues

Manual testing steps

Screenshots/Recordings

Before

After

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@MajorLift MajorLift added dependencies Pull requests that update a dependency file team-tiger Tiger team (for tech debt reduction + performance improvements) labels Dec 11, 2024
@MajorLift MajorLift self-assigned this Dec 11, 2024
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@MajorLift
Copy link
Contributor Author

@metamaskbot update-policies

@metamaskbot
Copy link
Collaborator

Policies updated.
👀 Please review the diff for suspicious new powers.

🧠 Learn how: https://lavamoat.github.io/guides/policy-diff/#what-to-look-for-when-reviewing-a-policy-diff

@MajorLift MajorLift force-pushed the jongsun/fix/redux/241211-heterogenuous-selector-typings branch from 76747ea to 76f2574 Compare December 11, 2024 13:09
@MajorLift
Copy link
Contributor Author

@metamaskbot update-policies

@metamaskbot
Copy link
Collaborator

Policies updated.
👀 Please review the diff for suspicious new powers.

🧠 Learn how: https://lavamoat.github.io/guides/policy-diff/#what-to-look-for-when-reviewing-a-policy-diff

@MajorLift MajorLift changed the title chore: Bump reselect from ^3.0.1 to ^4.0.0 chore: Bump reselect from ^3.0.1 to ^5.1.1 Dec 11, 2024
@MajorLift MajorLift marked this pull request as ready for review December 11, 2024 13:50
@MajorLift MajorLift requested review from a team as code owners December 11, 2024 13:50
@MajorLift MajorLift changed the title chore: Bump reselect from ^3.0.1 to ^5.1.1 chore: Bump reselect to ^5.1.1 for heterogenously-typed selectors support Dec 11, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [9025606]
Page Load Metrics (2023 ± 340 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint31635141787728350
domContentLoaded139037381983680327
load140437612023708340
domInteractive26133603416
backgroundConnect9198414421
firstReactRender15142553316
getState591192211
initialActions00000
loadScripts99130821508572275
setupStore76920199
uiStartup160345412290872419
Bundle size diffs [🚀 Bundle size reduced!]
  • background: 0 Bytes (0.00%)
  • ui: 108 Bytes (0.00%)
  • common: -1.94 KiB (-0.02%)

@MajorLift MajorLift requested a review from a team as a code owner December 11, 2024 23:02
@MajorLift MajorLift enabled auto-merge December 11, 2024 23:03
@metamaskbot
Copy link
Collaborator

Builds ready [f286e48]
Page Load Metrics (1643 ± 63 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint13821963164413163
domContentLoaded13501905161912459
load13831967164313163
domInteractive247439168
backgroundConnect763272010
firstReactRender1677312110
getState44915157
initialActions01000
loadScripts9621464121410550
setupStore65917199
uiStartup16082192187113665
Bundle size diffs [🚀 Bundle size reduced!]
  • background: 0 Bytes (0.00%)
  • ui: 108 Bytes (0.00%)
  • common: -1.94 KiB (-0.02%)

@MajorLift MajorLift requested a review from a team December 12, 2024 17:21

export const createDeepEqualSelector = createSelectorCreator(
defaultMemoize,
lruMemoize,
Copy link
Member

Choose a reason for hiding this comment

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

Just to clarify, this implementation is the same under the hood right?

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! It was just renamed in v5.

Copy link
Contributor Author

@MajorLift MajorLift Dec 13, 2024

Choose a reason for hiding this comment

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

Copy link
Member

@FrederikBolding FrederikBolding left a comment

Choose a reason for hiding this comment

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

Snaps changes LGTM

@MajorLift MajorLift added this pull request to the merge queue Dec 13, 2024
Merged via the queue into main with commit c671bf3 Dec 13, 2024
83 checks passed
@MajorLift MajorLift deleted the jongsun/fix/redux/241211-heterogenuous-selector-typings branch December 13, 2024 15:41
@github-actions github-actions bot locked and limited conversation to collaborators Dec 13, 2024
@metamaskbot metamaskbot added the release-12.11.0 Issue or pull request that will be included in release 12.11.0 label Dec 13, 2024
@MajorLift MajorLift changed the title chore: Bump reselect to ^5.1.1 for heterogenously-typed selectors support chore: Bump reselect to ^5.1.1 for heterogeneously-typed selectors support Jan 8, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
dependencies Pull requests that update a dependency file release-12.11.0 Issue or pull request that will be included in release 12.11.0 team-extension-platform team-tiger Tiger team (for tech debt reduction + performance improvements)
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants