-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Closed as not planned
Labels
closed: wontfixA fix will bring significant overhead, or is out of scope (for feature requests)A fix will bring significant overhead, or is out of scope (for feature requests)externalThis issue is caused by an external dependency and not Docusaurus.This issue is caused by an external dependency and not Docusaurus.
Description
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
Prerequisites
- I'm using the latest version of Docusaurus.
- I have tried the
npm run clear
oryarn clear
command. - I have tried
rm -rf node_modules yarn.lock package-lock.json
and re-installing packages. - I have tried creating a repro with https://new.docusaurus.io.
- I have read the console error message carefully (if applicable).
Description
When you try to declare react components using React.Component
in MDX files you end up with an Invalid hook call.
error.
Reproducible demo
No response
Steps to reproduce
- Setup an empty Docusuarus with latest dependencies
- npx create-docusaurus@latest my-website classic --typescript && npx ncu -u && npm i && npm start
- Open https://docusaurus.new/stackblitz-ts
- Open the
docs/tutorial-basics/markdown-features.mdx
- Change the file content to
---
sidebar_position: 4
---
import React from 'react'
export class Test extends React.Component {
render() {
return (<div>Title</div>);
}
}
<Test />
- Open the page in the browser.
- Experience the error.
Expected behavior
It should be possible declare React class components in MDX files without errors.
Actual behavior
The page crashes with:
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.
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
See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.
at Object.throwInvalidHookError (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:16227:9)
at Object.useContext (webpack-internal:///./node_modules/react/cjs/react.development.js:1619:21)
at useMDXComponents (webpack-internal:///./node_modules/@mdx-js/react/lib/index.js:47:64)
at Test.render (webpack-internal:///./docs/tutorial-basics/markdown-features.mdx:59:73)
at finishClassComponent (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:19747:31)
at updateClassComponent (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:19693:24)
at beginWork (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:21606:16)
at HTMLUnknownElement.callCallback (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:4164:14)
at Object.invokeGuardedCallbackDev (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:4213:16)
at invokeGuardedCallback (webpack-internal:///./node_modules/react-dom/cjs/react-dom.development.js:4277:31)
Moving the same class/code into a separate .tsx
under src/
and importing it into the MDX works.
Your environment
- Public source code: https://docusaurus.new/stackblitz-ts
- Public site URL: not relevant
- Docusaurus version used: 3.1.1
- Environment name and version (e.g. Chrome 89, Node.js 16.4): Chrome 122, Node 20.9
- Operating system and version (e.g. Ubuntu 20.04.2 LTS): Windows 11
Self-service
- I'd be willing to fix this bug myself.
Metadata
Metadata
Assignees
Labels
closed: wontfixA fix will bring significant overhead, or is out of scope (for feature requests)A fix will bring significant overhead, or is out of scope (for feature requests)externalThis issue is caused by an external dependency and not Docusaurus.This issue is caused by an external dependency and not Docusaurus.