hashicorp / next-mdx-remote

Load MDX content from anywhere
Mozilla Public License 2.0
2.58k stars 140 forks source link

[v5] Upstream `@types/mdx` doesn't support React v19 yet #462

Open mwskwong opened 3 months ago

mwskwong commented 3 months ago

Describe the bug

Regarding the latest release of v5, which claimed to support React 19, please note that @types/mdx, a dependency of @mdx-js/mdx and @mdx-js/react, is still accessing the global JSX namespace, which now needs to be imported from react in React 19. Ref: https://react.dev/blog/2024/04/25/react-19-upgrade-guide#the-jsx-namespace-in-typescript

As such, we must patch @types/mdx to support React 19 for now. e.g.

diff --git a/node_modules/@types/mdx/types.d.ts b/node_modules/@types/mdx/types.d.ts
index 498bb69..030a05f 100644
--- a/node_modules/@types/mdx/types.d.ts
+++ b/node_modules/@types/mdx/types.d.ts
@@ -1,3 +1,5 @@
+import { type JSX } from 'react'
+
 // Internal helper types

 /**

Reproduction

N/A

next-mdx-remote version

v5.0.0

dstaley commented 3 months ago

Thank you for reporting this! This is technically a "issue" (using that term loosely) with MDX and a as-of-yet unreleased version of React. The change from React to use their own JSX namespace will have wide reaching implications, particularly for libraries like MDX that work in several non-React JSX ecosystems. It will likely take time for everything upstream to settle, but it's my current belief that this won't require any changes on the next-mdx-remote side.

Gonna leave this open and pinned so that others can benefit from the patch you shared. Thanks again!

akarabach commented 1 month ago

@mwskwong @dstaley How do you do it on CI ?