Code Monkey home page Code Monkey logo

Comments (3)

twerkmeister avatar twerkmeister commented on June 28, 2024

brief update, seems wrap root element is working as intended, but there is a second MDX Provider below it in the react component hierarchy without any component prop. So the outermost Provider is being overwritten.

Screenshot 2019-11-28 at 13 48 50

Screenshot 2019-11-28 at 13 49 03

Wondering whether this has something to do with a default layout being applied by the gatsby mdx plugin https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-mdx#default-layouts

from gatsby-starter-blog-mdx.

twerkmeister avatar twerkmeister commented on June 28, 2024

seems gatsby-plugin-mdx is doing its own root wrapping

https://www.christopherbiscardi.com/post/removing-gatsby-mdx-wrappers/

https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-mdx

from gatsby-starter-blog-mdx.

twerkmeister avatar twerkmeister commented on June 28, 2024

I got it to work the following way (also the code examples work now):

I removed wrap-root-elements.js, gatsby-ssr.js and gatsby-browser.js as the root wrapping was being overwritten anyway. What instead helped was defining a custom layout for mdx pages and importing+default exporting it in the mdx file as shown here https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-mdx#default-layouts

src/components/mdx-layout.js

import React from "react"
import { MDXProvider } from "@mdx-js/react"
import { Code } from '../components/code'
import { preToCodeBlock } from 'mdx-utils'
import SCM from '../scm/scm'

// components is its own object outside of render so that the references to
// components are stable
const components = {
  pre: preProps => {
    const props = preToCodeBlock(preProps)
    // if there's a codeString and some props, we passed the test
    if (props) {
      return <Code {...props} />
    } else {
      // it's possible to have a pre without a code in it
      return <pre {...preProps} />
    }
  },
  SCM: props => {return <SCM {...props} />}
}


export default ({ children }) => (
  <MDXProvider components={components}>
    {children}
  </MDXProvider>
)

content/blog/hi-folks/index.mdx

---
title: New Beginnings
date: '2015-05-28T22:40:32.169Z'
---

import PageLayout from './../../../src/components/mdx-layout'

export default PageLayout
...

Unfortunately I didn't get the default layout mechanism in gatsby-config.js to work as outlined in the docs linked above, which would make importing the layout into every mdx file unnecessary. I think the reason is that gatsby-plugin-mdx is quite opinionated and makes a few assumptions that this project isn't making. For example, I assume the right way to compile the mdx files would be to use gatsby-plugin-page-creator and point it at the content directory and to turn the blog-post.js into the default layout for gatsby-plugin-mdx files. However, I wouldn't know how to fill the previous and next fields in this case. In any case, this feels like a bigger change which I am not entirely comfortable making given my limited understanding of the interplay of the different components. Maybe one of the maintainers can take the lead here beyond my quick fix.

from gatsby-starter-blog-mdx.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.