-
Notifications
You must be signed in to change notification settings - Fork 101
globalScope doesn't work for MDX content loaded with the webpack loader #239
Comments
@ChristopherBiscardi |
@tujoworker only for .mdx files in |
<MDXProvider
components={{ Video: () => <ReactYoutube/> }}
> |
@ChristopherBiscardi - Are you saying that the Is this understanding correct? import { Text, Button } from 'rebass'
const H1 = props => <Text as="h1" fontFamily="sans" {...props} />
// etc...
const LayoutComponents = {
H1,
p: Text,
wrapper: ({ children }) => <>{children}</>,
// etc...
}
// Previously from gatsby-mdx plugin options.globalscope
const GlobalScopeComponents = {
Button,
// etc...
}
export const Boot = ({ element }) => {
return (
<MDXProvider
components={{
...LayoutComponents,
...GlobalScopeComponents
}}
>
<Theme>{element}</Theme>
</MDXProvider>
)
} |
The |
Ah, thanks. FWIW |
hmm, that's not good. Since we have the alternative method in |
@erikdstock have you been able to get it working using the MDXProvider approach? |
@erikdstock Not since 1.0.6, which shipped a different default for the |
see ChristopherBiscardi/gatsby-mdx#239 the `globalScope` config option is deprecated in favor of passing more components into the provider
Oof, this was a tricky solution to adapt to my purposes, but I got it working (at least, mostly working, though with slightly different CSS than before – possibly because I also updated versions of Gatsby and React along with these changes). So, I'm posting my approach here, which was based on code from @erikdstock & @ChristopherBiscardi, above. Hope this isn't either too verbose or too minimal. I know it helps me to see various examples, so hopefully this helps someone else out there! If others see this and see clear flaws, please let me know.
|
I've just upgraded to the latest import { MDXRenderer } from 'gatsby-mdx';
import { MDXProvider } from '@mdx-js/tag';
const components = {
h1: props => <Heading {...props} el={'h1'} />,
h2: props => <Heading {...props} el={'h2'} />,
img: Image,
a: Anchor,
pre: AutomatedCodeBlock,
};
export const scope = {
Icon,
};
// children = mdx.code.body
function Provider({ children }) {
return (
<MDXProvider component={{ ...components, ...scope }}>
<MDXRenderer>{children}</MDXRenderer>
</MDXProvider>
);
} My HTML renders correctly, but never passes through any of my custom components. Going to stick with an older version where I had this working as I'm struggling to keep up with the changes to the API until it's stable I think.
EDIT: Got it working somehow - using |
@Ehesp |
Here's the link: https://mdxjs.com/migrating/v1#pragma FWIW, @Ehesp, the last remaining change that will happen is renaming |
Thanks @millette I've been banging my head on a wall for two days... |
Could be good to update this page and mention MDXProvider 🙂 |
gatsby-mdx is now gatsby-plugin-mdx and published from the Gatsby repo: gatsbyjs/gatsby#14657 |
Describe the bug
globalScope
is a new feature meant to replace "shortcodes" in other platforms. Because we don't consume the MDXScopeProvider when loading MDX content in the mdx-loader,globalScope
doesn't work for .mdx files in src/pagesThe text was updated successfully, but these errors were encountered: