-
Notifications
You must be signed in to change notification settings - Fork 4
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
evaling code breaks if code contains import statements with sources that should be resolved by the bundler #9
Comments
I think and insist that the issue is not related with |
It has the same cause as
Example that is already broken in Next.js 14 for the same underlying reason: import { Suspense } from "react";
import { MDXRemote } from "next-mdx-remote-client/rsc";
export default async function Page() {
const source = "# Import\nimport Test from './Test.mjs';\n\n<Test />";
return (
<Suspense fallback="Loading...">
<MDXRemote
source={source}
options={{
mdxOptions: {
baseUrl: import.meta.url,
},
}}
/>
</Suspense>
);
}
import * as React from "react";
export default function Test() {
React.useId();
return "Hello, Dave!";
} |
Hi @eps1lon, I confirmed that Seems that the imported component within MDX couldn't find the Even if we don't use any React APIs/hooks, just return A React component within an I will try to include But, I am trying to understand, why ? What is going on during function construction ?
|
I updated and published the new version of Now, Basically, I passed the If the MDX content doesn't contain any import declarations for React components, you don't need to do any additional things. But, if the MDX content contains a import declaration for a React component, then you need to use a Basically, // ...
+ const React = arguments[0].React;
const {Fragment: _Fragment, jsx: _jsx, jsxs: _jsxs} = arguments[0];
// ...
const {default: Test} = await import(_resolveDynamicMdxSpecifier("./context/Test.mjs"));
function _createMdxContent(props) {
// ...
return _jsxs(_Fragment, {
// ...
- _jsx(Test, {})
+ _jsx(Test, { React })
// ...
})
} In the example that @eps1lon shared above, importing
// import * as React from "react"; // no need
export default function Test({ React }) {
React.useId();
return "Hello, Dave!";
} As a conclusion, passing But, a new problem appeared. I am able to use any react hooks (like |
This is based off of vercel/next.js#76395
The concrete case used
React.createElement
instead of just JSX to construct elements. However, the same issue occurs if any other React API is being used.Next.js applies aliases to certain import sources. However, this does not apply to code dynamically evaluated like
eval
orReflect.construct
. Sincenext-mdx-remote-client
usesReflect.construct
to run code, imports to React will resolve to the wrong version of React. In this case it's the installed, Client React. Mixing different versions of React or Server and Client React in the same component is not supported.The text was updated successfully, but these errors were encountered: