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

React hook warning when using MDX #12802

Open
1 task
olafsulich opened this issue Dec 20, 2024 · 4 comments
Open
1 task

React hook warning when using MDX #12802

olafsulich opened this issue Dec 20, 2024 · 4 comments
Labels
needs triage Issue needs to be triaged

Comments

@olafsulich
Copy link

Astro Info

Astro                    v5.1.1
Node                     v22.4.0
System                   macOS (arm64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             @astrojs/react
                         @astrojs/tailwind
                         @astrojs/mdx

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

I'm getting the react hooks warning on route change. It only shows up when I have enabled the MDX integration.

Related:

The whole message:

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

What's the expected result?

No warnings in the console

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-syektoew?file=astro.config.mjs

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Dec 20, 2024
@dervism
Copy link

dervism commented Dec 21, 2024

Having the same issue with 5.1.1. With the MDX-integration enabled I get this error:

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

Removing the mdx-integration and the error messages is gone.

@ascorbic
Copy link
Contributor

Try running npm ls react to see if you have multiple copies of the package. That's usually the cause for these kinds of error.

@olafsulich
Copy link
Author

@ascorbic, it looks like two react but with the same version (?). Here's how it looks for the example:
Zrzut ekranu 2024-12-23 o 20 15 39

@CodeAndWeb
Copy link

CodeAndWeb commented Dec 26, 2024

Same here. I've created a clean project for that. As soon as react and mdx are both present in the astro config, using a hook triggers the warning.

Changing the order of the integration does not seem to have any influence.

npm ls react:

[email protected] /Users/sk/Programming/_tmp/astro-react-test/helpless-horizon
├─┬ @astrojs/[email protected]
│ └── [email protected] deduped
├─┬ [email protected]
│ └── [email protected] deduped
└── [email protected]

The waning only appears on the command line, not in the browser.

Reproduce:

https://github.com/CodeAndWeb/astro-react-mdx-hook-error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

4 participants