question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Filters - Cannot read properties of null (reading 'control')

See original GitHub issue

What you were expecting:

Normal filtering for the list

What happened instead: Screen Shot 2022-05-24 at 1 56 14 AM

Steps to reproduce:

  1. Add a resource
  2. Access the list for this resource
  3. Modify the <List /> to contain some filters

Related code:


const postFilters = [
  <TextInput variant="outlined" label="City" source="city" />,
];

<List
    filters={postFilters}
    actions={
      <TopToolbar>
        <FilterButton />
      </TopToolbar>
    }
    sort={{ field: 'created_at', order: 'DESC' }}>
    {...}
</List>

Environment

  • React-admin version: 4.1.0
  • Last version that did not exhibit the issue (if applicable): 3.x
  • React version: 18.1.0
  • Browser: Chrome

NB

Using yarn PnP for this project which might be something related to the issue.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:4
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
magnatticcommented, Jun 3, 2022

@yousseftarekkh and I investigated the issue further and found the culprit. For anyone else using yarn pnp and having this problem, here is the solution:

We had different versions of react-hook-form installed in the same project, which under pnp leads to problems with the react context not working. (The Provider and Context must be from the same version or the context will be empty.)

yarn why -R react-hook-form β”œβ”€ my-project β”‚ β”œβ”€ react-admin@npm:4.1.0 [31191] (via npm:4.1.0 [31191]) β”‚ β”‚ β”œβ”€ ra-ui-materialui@npm:4.1.0 [e24d5] (via npm:^4.1.0 [e24d5]) β”‚ β”‚ β”‚ └─ react-hook-form@npm:7.29.0 [31191] (via npm:7.31.3 [31191]) β”‚ β”‚ └─ react-hook-form@npm:7.31.3 [31191] (via npm:7.31.3 [31191]) β”‚ └─ react-hook-form@npm:7.31.2 [31191] (via npm:7.31.3 [31191])

After making sure that all versions are exactly the same, it worked. Specifically we fixed the missing dependency of ra-ui-materialui to react-hook-form in the .yarnrc.yml like this:

ra-ui-materialui@*:
    peerDependencies:
       react-hook-form: "*"

This way it is using the version from react-admin.

Also we made sure that in our project we are using the same version of react-hook-form as the one that react-admin installs. Now they are in sync and everything works again:

β”œβ”€ my-project β”‚ β”œβ”€ react-admin@npm:4.1.0 [31191] (via npm:4.1.0 [31191]) β”‚ β”‚ └─ react-hook-form@npm:7.31.3 [31191] (via npm:7.31.3 [31191]) β”‚ └─ react-hook-form@npm:7.31.3 [31191] (via npm:7.31.3 [31191])

So what can react-admin do to help people that use yarn pnp?

  • Add the missing peerDependency to the package.json of ra-ui-materialui. Right now this is implicitly using the package without declaring it, which to me looks like a mistake.
  • Consider making react-hook-form a peerDependency of react-admin. Many people will also need to work with the forms library in their own project and keeping the versions in sync will be much easier if it is a peerDependency instead of a dependency.
2reactions
djhicommented, May 25, 2022

Indeed, we did not test it with PnP

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot read properties of null (reading '_rawValidators')
The array does not render correctly. Here is a picture of how it initially loads. Tabbing through the controls seems to make it...
Read more >
Uncaught TypeError: Cannot read property of null - iDiallo
This error occurs when you read a property or call a method on a null object . That's because the DOM API returns...
Read more >
cannot read properties of undefined (reading 'filter') in react js
However, When I search for users using the search box, I get a TypeError: Cannot read property 'filter' of undefined The page initially...
Read more >
Solved: TypeError Cannot read properties of null (reading
Solved! Go to Solution. ... Hello @RafaelCelaya,. If you are applying a filter to a field in a repeat we have an issue...
Read more >
TypeError: Cannot read property 'filter' of Null in JS | bobbyhadz
The "Cannot read property 'filter' of null" error occurs when calling the filter() method on a null value. To solve the error, initialize...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found