Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pull out MDX to be opt-in #2288

Merged
merged 97 commits into from
Sep 12, 2022
Merged

Pull out MDX to be opt-in #2288

merged 97 commits into from
Sep 12, 2022

Conversation

hasparus
Copy link
Member

@hasparus hasparus commented Aug 5, 2022

Closes #2133.

This PR removes the peer dependency on @mdx-js/react from the main theme-ui package, and changes @theme-ui/mdx to work with any version of @mdx-js/react or a compatible library.

We have 2 reasons to do this.

  1. Not every app using Theme UI needs MDX. Codebases I've seen quite often have a documentation website website and an actual product app in separate packages and often even in separate repositiories.
  2. @mdx-js packages are now ESM-only, so Theme UI is locked on a previous major, what leads to multiple annoying problems.

Although Theme UI might eventually become ESM-only, this PR seems to me like a good move because of the first reason I mentioned.

All credits to johno for the idea.


What's left to do?

Release Notes

Breaking: theme-ui no longer includes @theme-ui/mdx β€” MDX is now opt-in.

If your project is not using MDX or importing Themed, you shouldn't need to
change anything.

  • MDXProvider is no longer included in Theme UI ThemeProvider, and has been
    removed in favour of an useThemedStylesWithMdx hook.

    • Migration: Use useThemedStylesWithMdx together with MDXProvider and useMDXComponents from @mdx-js/react.

      import {
        MDXProvider,
        useMDXComponents,
        Components as MDXComponents,
        MergeComponents as MergeMDXComponents,
      } from '@mdx-js/react'
      import { useThemedStylesWithMdx } from '@theme-ui/mdx'
      import { ThemeProvider, Theme } from 'theme-ui'
      
      interface MyProviderProps {
        theme: Theme
        components?: MDXComponents | MergeMDXComponents
        children: React.ReactNode
      }
      function MyProvider({ theme, components, children }: MyProviderProps) {
        const componentsWithStyles = useThemedStylesWithMdx(useMDXComponents(components))
      
        return (
          <ThemeProvider theme={theme}>
            <MDXProvider components={componentsWithStyles}>
              {children}
            </MDXProvider>
          </ThemeProvider>
        )
      }
  • Themed components dict and other exports from @theme-ui/mdx are no longer reexported from theme-ui.

    • Migration: Import it from @theme-ui/mdx instead.

      -  import { Themed } from 'theme-ui'
      +  import { Themed } from '@theme-ui/mdx'

Version

Published prerelease version: v0.15.0-develop.23

Changelog

πŸŽ‰ This release contains work from new contributors! πŸŽ‰

Thanks for all your work!

❀️ Luke Watts (@thisislawatts)

❀️ Valto Savi (@pointlessrapunzel)

Release Notes

Pull out MDX to be opt-in (#2288)

Breaking: theme-ui no longer includes @theme-ui/mdx β€” MDX is now opt-in.

If your project is not using MDX or importing Themed, you shouldn't need to
change anything.

  • MDXProvider is no longer included in Theme UI ThemeProvider, and has been
    removed in favour of an useThemedStylesWithMdx hook.

    • Migration: Use useThemedStylesWithMdx together with MDXProvider and useMDXComponents from @mdx-js/react.

      import {
        MDXProvider,
        useMDXComponents,
        Components as MDXComponents,
        MergeComponents as MergeMDXComponents,
      } from '@mdx-js/react'
      import { useThemedStylesWithMdx } from '@theme-ui/mdx'
      import { ThemeProvider, Theme } from 'theme-ui'
      
      interface MyProviderProps {
        theme: Theme
        components?: MDXComponents | MergeMDXComponents
        children: React.ReactNode
      }
      function MyProvider({ theme, components, children }: MyProviderProps) {
        const componentsWithStyles = useThemedStylesWithMdx(useMDXComponents(components))
      
        return (
          <ThemeProvider theme={theme}>
            <MDXProvider components={componentsWithStyles}>
              {children}
            </MDXProvider>
          </ThemeProvider>
        )
      }
  • Themed components dict and other exports from @theme-ui/mdx are no longer reexported from theme-ui.

    • Migration: Import it from @theme-ui/mdx instead.

      -  import { Themed } from 'theme-ui'
      +  import { Themed } from '@theme-ui/mdx'

Remove @theme-ui/editor (#2292)

  • Breaking: @theme-ui/editor was removed. Use CSS GUI instead.

Drop support for React 16 + 17 (#2215)

Theme UI 0.15.0 drops support for React 16 and React 17. Your use case may still work, but we don't guarantee it.


πŸš€ Enhancement

πŸ› Bug Fix

πŸ‘¨β€πŸ’» Minor changes

🏠 Internal

Authors: 6

@vercel
Copy link

vercel bot commented Aug 5, 2022

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Updated
theme-ui βœ… Ready (Inspect) Visit Preview Sep 10, 2022 at 11:41PM (UTC)

@codesandbox-ci
Copy link

codesandbox-ci bot commented Aug 5, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit cd66918:

Sandbox Source
next-theme-ui-example Configuration
gatsby-plugin-theme-ui-example Configuration

Please use Themed.div instead. Those two were always the same.
@LekoArts
Copy link
Collaborator

@hasparus I want to try this out but it doesn't seem like this was published on npm? The develop alias stops at .22
https://www.npmjs.com/package/theme-ui

@hasparus
Copy link
Member Author

Thanks for noticing that @LekoArts. I inadvertently broke the auto release when I migrated to PNPM in this PR.

Should be fine now.

@LekoArts
Copy link
Collaborator

Thanks!

@LekoArts
Copy link
Collaborator

@hasparus I think this was still a bad publish if you look at https://unpkg.com/browse/theme-ui@0.15.0-develop.26/dist/theme-ui.cjs.js

My unit tests + trying it out on a live site both fail with:

Error: Cannot find module '../../../node_modules/.pnpm/@preconstruct+hook@0.4.0/node_modules/@preconstruct/hook'
Require stack:
- /Users/lejoe/code/github/gatsby-themes/node_modules/theme-ui/dist/theme-ui.cjs.js

I can bring this into an issue if you want instead of commenting on this PR πŸ˜…

@hasparus
Copy link
Member Author

@LekoArts I created the issue. I'm gonna go back to it on the weekend and test this version properly in my projects.

@LekoArts
Copy link
Collaborator

@hasparus Cool! Don't feel rushed, it's not urgent on my end :)

@hasparus
Copy link
Member Author

@LekoArts I just published 0.15.0-develop.30. Didn't get the MDX functionality in my projects yet, but the preconstruct/hook error is gone.

image

@LekoArts
Copy link
Collaborator

@hasparus Thanks! Also all working fine on my end LekoArts/gatsby-themes#989

@LekoArts LekoArts mentioned this pull request Sep 19, 2022
9 tasks
@lachlanjc lachlanjc added this to the v1.0 milestone Sep 24, 2022
@hasparus
Copy link
Member Author

πŸš€ PR was released in v0.15.0 πŸš€

@hasparus hasparus added released This issue/pull request has been released. and removed prerelease This change is available in a prerelease. labels Sep 26, 2022
NickyMeuleman added a commit to NickyMeuleman/gatsby-theme-nicky-blog that referenced this pull request Oct 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released This issue/pull request has been released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

docs: Specify MDX version to install
4 participants