Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
},
"scripts": {
"bootstrap": "lerna bootstrap && lerna link --force-local",
"clean": "lerna exec \"rm -rf node_modules\"",
"docs": "x0 docs",
"docs:build": "x0 build docs",
"docs:deploy": "npm run docs:build && now dist --public && now alias",
Expand Down
2 changes: 2 additions & 0 deletions packages/mdx/mdx-hast-to-jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ function toJSX(node, parentNode = {}, options = {}) {
this.layout = ${layout}
}
render() {
const { components = {} } = this.props

return <MDXTag
name="wrapper"
${layout ? `Layout={this.layout} layoutProps={props}` : ''}
Expand Down
4 changes: 3 additions & 1 deletion packages/mdx/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const transform = code =>
const renderWithReact = async mdxCode => {
const jsx = await mdx(mdxCode, {skipExport: true})
const code = transform(jsx)
const scope = {MDXTag, components: {}}
const scope = {MDXTag}

const fn = new Function( // eslint-disable-line no-new-func
'React',
Expand Down Expand Up @@ -88,6 +88,8 @@ it('Should match sample blog post snapshot', async () => {
this.layout = undefined;
}
render() {
const { components = {} } = this.props;

return (
<MDXTag name=\\"wrapper\\" components={components}>
<MDXTag name=\\"h1\\" components={components}>{\`Hello World\`}</MDXTag>
Expand Down
8 changes: 4 additions & 4 deletions packages/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@
"dependencies": {
"@mdx-js/mdx": "^0.16.2",
"@mdx-js/tag": "^0.16.1",
"buble": "^0.19.3"
"buble": "^0.19.6"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-env": "^1.7.0",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"jest": "^23.2.0",
"react": "^16.4.1",
"react-dom": "^16.4.1",
"jest": "^23.6.0",
"react": "^16.6.3",
"react-dom": "^16.6.3",
"rehype-add-classes": "^1.0.0",
"remark-autolink-headings": "^5.0.0",
"remark-slug": "^5.1.0"
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ export default ({
const {code} = transform(jsx)

const keys = Object.keys(fullScope)
const values = keys.map(key => fullScope[key])
const values = Object.values(fullScope)
// eslint-disable-next-line no-new-func
const fn = new Function(
'_fn',
'React',
...keys,
`${code}

return React.createElement(MDXContent);`
return React.createElement(MDXContent, { components });`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to manually pass components as a prop, otherwise const { components = {} } = this.props in render will override them.

)

return fn({}, React, ...values)
Expand Down
Loading