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

[DataGrid] All selectors accept only apiRef as first argument #16198

Merged
merged 31 commits into from
Feb 13, 2025

Conversation

arminmeh
Copy link
Contributor

@arminmeh arminmeh commented Jan 15, 2025

Closes #11440

Changelog

Breaking changes

  • The selectors signature has been updated. They are only accepting apiRef as a first argument.

    -mySelector(state, arguments, instanceId)
    +mySelector(apiRef, arguments)

@mui-bot
Copy link

mui-bot commented Jan 15, 2025

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 20, 2025
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 22, 2025
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 24, 2025
@github-actions github-actions bot added PR: out-of-date The pull request has merge conflicts and can't be merged and removed PR: out-of-date The pull request has merge conflicts and can't be merged labels Feb 5, 2025
Copy link

github-actions bot commented Feb 5, 2025

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 6, 2025
@arminmeh arminmeh added breaking change component: data grid This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature labels Feb 7, 2025
@arminmeh arminmeh marked this pull request as ready for review February 10, 2025 09:38
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 10, 2025
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged label Feb 10, 2025
);
```

To make the developer experience better, selectors are typed to allow `apiRef` to reference a `null` value, but they throw an error if called before the state is initialized. Use selectors after the initialization in a `useEffect()` hook or in an event handler.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I did this to allow using selectors with the apiRef retrieved from useGridApiRef(). It opens the room for an error, but I think it is still better than casting apiRef any time you need to pass it to the selector.

@@ -12,23 +11,19 @@ const reselectCreateSelector = createSelectorCreator({
maxSize: 1,
equalityCheck: Object.is,
},
argsMemoize: customWeakMapMemoize,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did we need to add a custom implementation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@MBilalShafi actually fixed this
reselect version didn't catch the updates inside apiRef of the dependency selectors, so the return values would be inaccurate

Copy link
Member

Choose a reason for hiding this comment

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

The original function weakMapMemoize doesn't memoize the apiRef argument properly due to the static nature of refs, causing in reselect wrapped selectors to not work properly, the custom implementation causes to use apiRef.current.state for comparison rather than apiRef itself.

@arminmeh arminmeh merged commit f854ac1 into mui:master Feb 13, 2025
22 checks passed
@arminmeh arminmeh deleted the align-selectors branch February 13, 2025 09:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change component: data grid This is the name of the generic UI component, not the React module! enhancement This is not a bug, nor a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[datagrid] Refactor: make all selectors accept the same argument
5 participants