Giter Site home page Giter Site logo

Upgrade Gatsby to v3? about mdx-deck HOT 2 OPEN

karlhorky avatar karlhorky commented on June 14, 2024
Upgrade Gatsby to v3?

from mdx-deck.

Comments (2)

karlhorky avatar karlhorky commented on June 14, 2024 1

And any calls to require() seem to need to be replaced by require().default:

<CodeSurfer
  steps={[
    {
-     code: require('!raw-loader!./exampleTypescript.ts').replace(
+     code: require('!raw-loader!./exampleTypescript.ts').default.replace(
        / *\/\/ prettier-ignore\n/g,
        '',
      ),
      lang: 'ts',
    },
  ]}
  progress={0}
/>

from mdx-deck.

karlhorky avatar karlhorky commented on June 14, 2024

‼️ Ah, hot reloading appears to be broken.

Maybe it has something to do with the usage of @mdx-js/loader in the Gatsby plugin.

Maybe a better way would be to use the approach taken by gatsby-plugin-mdx, with exports.preprocessSource and other methods.


Funny enough, it does appear to recognize the change (below are logs from the browser, which has recognized there is a change):

client.js:241 [HMR] bundle rebuilding
client.js:250 [HMR] bundle rebuilt in 926ms
process-update.js:51 [HMR] Checking for updates on the server...
process-update.js:125 [HMR] Updated modules:
process-update.js:127 [HMR]  - ../../slideDecks/deck25/index.mdx
process-update.js:127 [HMR]  - ./.cache/_this_is_virtual_fs_path_/$virtual/async-requires.js
process-update.js:132 [HMR] App is up to date.

Seems like the issue may be fundamental in the MDX loader 🤔

Currently HMR with fast-refresh doesn't work with mdx files. The reason is that mdx loader generate modules with 2 exports (MDXContent that is actual react component and frontmatter) which doesn't satisfy restrictions of fast refresh for there to be single export.

gatsbyjs/gatsby#31288

Next.js also had to do loader work for Fast Refresh: vercel/next.js#15851


Ahhh, gaearon's comment here is the reason for the hot reloading problems!

Just wanted to add I ran into this and then realized I had export const stuff = ... at the top of my MDX, which caused the bailout. I removed that and it worked.

The problem is my usage of a custom theme:

export { theme } from './theme'

So I'll figure out how to strip that (maybe with a custom webpack loader added after @mdx-js/loader).


Or if I can find a way to override the theme prop that's being passed to the wrapper component that mdx-deck is passing to <MDXProvider />... 🤔

Not sure where this theme prop is magically coming from actually...

After diving through a bunch of @mdx-deck/* and @mdx-js/* packages, closest that I came to finding it was this layoutProps thing here: @mdx/mdx/mdx-hast-to-jsx.js


Actually, maybe a simpler way would be to override the theme globally for all of my slide decks - since I only use a single theme... 🤔


Ended up going with another patch-package patch to patch @mdx-deck/gatsby-plugin/src/theme.js to add in my custom theme 😅

from mdx-deck.

Related Issues (20)

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.