-
Notifications
You must be signed in to change notification settings - Fork 144
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
props key returns empty object from scope #183
Comments
Good find! From what I can see, with the way the the mdx library is building up the component (reference), we'll have to treat Effectively what we are doing here is wrapping the result of running mdx in a function to create the scope: fn (props, props2) {
return function MDXContent(props) {
// local props would shadow props from scope
}
} I'll do some thinking on a sustainable way to accomplish this. Feel free to contribute if you've got something in mind! |
@BRKalow I've just run into this issue. I have to admit I was quite perplexed when only the props key didn't work. I'm forced to use this codepath with my setup. I'll noodle on this and get back to you with some ideas. |
Okay I've done a bit of poking around and I came up with a solution that works, though you may not like it. To bypass the shadowing issue, I think we can simply use the @@ -70,10 +70,11 @@ export function MDXRemote({
// if we're ready to render, we can assemble the component tree and let React do its thing
// first we set up the scope which has to include the mdx custom
// create element function as well as any components we're using
+ const {props = {}, ...remainingScope} = scope
const fullScope = Object.assign(
{ opts: { ...mdx, ...runtime } },
{ frontmatter },
- scope
+ remainingScope
)
const keys = Object.keys(fullScope)
const values = Object.values(fullScope)
@@ -88,7 +89,8 @@ export function MDXRemote({
keys.concat(`${compiledSource}`)
)
- return hydrateFn.apply(hydrateFn, values).default
+ const Component = hydrateFn.apply(hydrateFn, values).default
+ return () => <Component {...props} />
}, [scope, compiledSource])
if (!isReadyToRender) { This will extract any |
@rfrowe Sorry for the delay. If you're still interested, feel free to open a PR with this and we can take a further look! |
@BRKalow I've opened a PR for this, please take a look. |
No need to make any change in the package, the issue comes from the way of implementation. You can use like See mdx-js/mdx#2437 The |
Hi there
Have found that using the
props
key innext-mdx-remote
'sscope
property always returns an empty objectSee this example:
https://codesandbox.io/s/next-mdx-remote-props-s85i4?file=/pages/index.js
props.title
returnsundefined
, butprops2.title
returns as expected.props
does however return an empty object.Could there be something overwriting it somewhere in MDX, or is it somehow a reserved word?
Would ideally like to use the
props.
notation in MDX pages as it's familiar from the React ecosystem.Any help appreciated. Thanks
The text was updated successfully, but these errors were encountered: