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

Rendering in Snapshot tests #100

Closed
PauliusLiekis opened this issue Apr 21, 2020 · 3 comments
Closed

Rendering in Snapshot tests #100

PauliusLiekis opened this issue Apr 21, 2020 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@PauliusLiekis
Copy link

Hi,

I'm having problems with GroupedVirtuoso in UnitTests. The first issue that I ran into was this:

Error: Uncaught [Invariant Violation: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.]

This happens when rendering an empty list.
I made sure that the rendering of functional-components and hooks works fine. The issue seems to be specific to GroupedVirtuoso.

I tried to narrow down the issue but run into another problem:

TypeError: Cannot read property 'removeEventListener' of null

  46 |         elRef.current = theRef
  47 |       } else {
> 48 |         elRef.current!.removeEventListener('scroll', onScroll)
     |                        ^
  49 |       }
  50 |     },
  51 |     [onScroll]

  at src/VirtuosoScroller.tsx:48:24

The latter issue was reproduced in master of react-virtuoso using the attached test:
Snapshot.test.tsx.zip

You will need to add these two dependencies:

"@types/react-test-renderer": "^16.9.2",
"react-test-renderer": "^16.13.1",

One of the reasons why we started on this path is that sometimes we get calls to item and group with out-of-bounds indices. I don't have more details on that yet...

@petyosi
Copy link
Owner

petyosi commented Apr 21, 2020

Thanks for the report, I will give this a try.

@petyosi petyosi self-assigned this Apr 21, 2020
@petyosi
Copy link
Owner

petyosi commented Apr 26, 2020

@PauliusLiekis - can you please test 0.16.1? Let me know if you discover more issues down the road with the hook usage.

@petyosi petyosi added the bug Something isn't working label Apr 26, 2020
@PauliusLiekis
Copy link
Author

Sorry for taking forever to respond. I can confirm that I no longer reproduce removeEventListener issue with latest code.

However, I still have the other one:

Error: Uncaught [Invariant Violation: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:

It has something to do with passing empty array of groups to it. I haven't managed to make a small repro case for it yet :/ I'll let you know once/if I do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants