Skip to content

Commit

Permalink
Remove layout props in compiled jsx (#1199)
Browse files Browse the repository at this point in the history
Closes #742
  • Loading branch information
johno authored Jul 31, 2020
1 parent b6f3fdf commit b8bedc9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 25 deletions.
11 changes: 1 addition & 10 deletions packages/mdx/mdx-hast-to-jsx.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function serializeRoot(node, options) {

const fn = `function MDXContent({ components, ...props }) {
return (
<MDXLayout {...layoutProps} {...props} components={components}>
<MDXLayout {...props} components={components}>
${doc}
</MDXLayout>
)
Expand Down Expand Up @@ -144,14 +144,6 @@ MDXContent.isMDXComponent = true`
]
}).code

let layoutProps = 'const layoutProps = {'

if (exportNames.length !== 0) {
layoutProps += '\n ' + exportNames.join(',\n ') + '\n'
}

layoutProps += '};'

const allJsxNames = [
...babelPluginApplyMdxPropInstance.state.names,
...babelPluginApplyMdxPropToExportsInstance.state.names
Expand All @@ -173,7 +165,6 @@ MDXContent.isMDXComponent = true`
const moduleBase = `${importStatements}
${exportStatementsPostMdxTypeProps}
${fakedModulesForGlobalScope}
${layoutProps}
${mdxLayout}`

if (skipExport) {
Expand Down
13 changes: 2 additions & 11 deletions packages/mdx/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,10 @@ it('Should match sample blog post snapshot', async () => {
return <div {...props} />;
};
const layoutProps = {};
const MDXLayout = \\"wrapper\\";
export default function MDXContent({ components, ...props }) {
return (
<MDXLayout
{...layoutProps}
{...props}
components={components}
mdxType=\\"MDXLayout\\"
>
<MDXLayout {...props} components={components} mdxType=\\"MDXLayout\\">
<h1>{\`Hello World\`}</h1>
</MDXLayout>
);
Expand Down Expand Up @@ -340,15 +334,12 @@ test('Should handle layout props', () => {
};
const Foo = makeShortcode(\\"Foo\\");
const Bar = makeShortcode(\\"Bar\\");
const layoutProps = {
foo
};
const MDXLayout = ({children}) => <div>{children}</div>
export default function MDXContent({
components,
...props
}) {
return <MDXLayout {...layoutProps} {...props} components={components} mdxType=\\"MDXLayout\\">
return <MDXLayout {...props} components={components} mdxType=\\"MDXLayout\\">
<h1>{\`Hello, world!\`}</h1>
<p>{\`I'm an awesome paragraph.\`}</p>
{
Expand Down
5 changes: 1 addition & 4 deletions packages/remark-mdxjs/test/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@ const makeShortcode = name => function MDXDefaultShortcode(props) {
};
const Paragraph = makeShortcode(\\"Paragraph\\");
const Button = makeShortcode(\\"Button\\");
const layoutProps = {
Baz
};
const MDXLayout = Foo
export default function MDXContent({
components,
...props
}) {
return <MDXLayout {...layoutProps} {...props} components={components} mdxType=\\"MDXLayout\\">
return <MDXLayout {...props} components={components} mdxType=\\"MDXLayout\\">
<h1>{\`Hello, world! \`}
<Foo bar={{
baz: 'qux'
Expand Down

0 comments on commit b8bedc9

Please sign in to comment.