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

Invalid hook call in React with HOC #5305

Closed
1 task
whs opened this issue Nov 5, 2022 · 0 comments · Fixed by #5426
Closed
1 task

Invalid hook call in React with HOC #5305

whs opened this issue Nov 5, 2022 · 0 comments · Fixed by #5426
Assignees
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)

Comments

@whs
Copy link

whs commented Nov 5, 2022

What version of astro are you using?

1.6.3

Are you using an SSR adapter? If so, which one?

No

What package manager are you using?

npm

What operating system are you using?

Linux

Describe the Bug

It seems that #4220 were solved in #4831 by adding more React component detection rules. However, components wrapped with HOC still get the error:

Warning: 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://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.

In my case local development (astro start) also might not work due to this issue. Stack trace:

[plugin:@astrojs/react] Cannot read properties of null (reading 'useRef')

 error   Cannot read properties of null (reading 'useRef')
  File:
    node_modules/react/cjs/react.development.js:1630:21
  Code:
      1629 |   var dispatcher = resolveDispatcher();
    > 1630 |   return dispatcher.useRef(initialValue);
           |                     ^
      1631 | }
      1632 | function useEffect(create, deps) {
      1633 |   var dispatcher = resolveDispatcher();
    
  Stacktrace:
TypeError: Cannot read properties of null (reading 'useRef')
    at Object.useRef (node_modules/react/cjs/react.development.js:1630:21)
    at useConstant (node_modules/@xstate/react/lib/useConstant.js:5:21)
    at useIdleInterpreter (node_modules/@xstate/react/lib/useInterpret.js:47:45)
    at Proxy.useMachine (node_modules/@xstate/react/lib/useMachine.js:35:57)
    at eval (/src/utils/xstate.tsx:11:60)
    at Tester (@astrojs/react/server.js:38:18)
    at describeNativeComponentFrame (node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js:3732:7)
    at describeFunctionComponentFrame (node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js:3827:12)
    at getStackByComponentStackNode (node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js:5294:19)
    at getCurrentStackInDEV (node_modules/react-dom/cjs/react-dom-server-legacy.node.development.js:5460:12)

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-mnqssn?file=src/components/withCounter.tsx

Participation

  • I am willing to submit a pull request for this issue.
@matthewp matthewp added the - P4: important Violate documented behavior or significantly impacts performance (priority) label Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P4: important Violate documented behavior or significantly impacts performance (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants