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

components in MdxProvider is not working sometimes #2077

Closed
4 tasks done
citrus327 opened this issue Jul 6, 2022 · 5 comments
Closed
4 tasks done

components in MdxProvider is not working sometimes #2077

citrus327 opened this issue Jul 6, 2022 · 5 comments
Labels
🙋 no/question This does not need any changes

Comments

@citrus327
Copy link

Initial checklist

Affected packages and versions

2.1.2

Link to runnable example

No response

Steps to reproduce

I have a document tool that uses MDX as internal.

Users' markdown file are wrapped in a Document component.

like:

import { ShowCode } from "../../built-in/ShowCode";
import { ApiTable } from "../../built-in/ApiTable";
import { MDXProvider } from "@mdx-js/react";

<MDXProvider
  components={{
    ShowCode,
    ApiTable,
    // and so on
  }}
>
  {children}
</MDXProvider>

Sometimes console says

image

I've checked React Devtools

image

Seems like the Components are correctly inject.

I debugged into the source code, and i found this

image

The props.components is undefined

I didn't dig into MDX codebase that hard.

I've checked #1986 #1988 , but does not likely to be related.

Could anyone give me some hints for this kind of issue?

Expected behavior

The component injected in MDXProvider works as expected.

Actual behavior

Injected Component is undefined.

Runtime

Node v14

Package manager

yarn v1

OS

macOS

Build and bundle tools

Vite

@citrus327 citrus327 changed the title components in MdxProvider not working sometimes components in MdxProvider is not working sometimes Jul 6, 2022
@ChristianMurphy
Copy link
Member

ChristianMurphy commented Jul 6, 2022

@phshy0607 could you share a replication of the issue you are seeing?
It's unclear what package you are using and how you are applying the provider.

Here are some starters which could be used to make a replication quickly:

description codesandbox stackblitz
MDX Loader with Next.js codesandbox stackblitz
MDX Evaluate with Node.js codesandbox stackblitz
MDX Evaluate with Create React App codesandbox stackblitz

@ChristianMurphy ChristianMurphy added the 🙊 open/needs-repro This needs a reproduction label Jul 6, 2022
@citrus327
Copy link
Author

@ChristianMurphy The document package I working on is https://github.com/BlizzBolts/docit

The provider is used like this: https://github.com/BlizzBolts/docit/blob/master/src/client/components/Document/index.tsx

I will try to make a reproduce if I really could. It's not 100% reproducible.

@citrus327
Copy link
Author

@ChristianMurphy
I've checked it again.

It's an issue related to Vite or Esbuild. During vite develop server, vite will do a dependency pre-bundling which pre-bundles @mdx-js/react, I excluded it from pre-bundling by config optimizeDeps.exclude which solves my issue.

I don't know it's related to esbuild which transform deps underneath or vite itself, but my issue is solved. You can close it for now, thanks.

@ChristianMurphy ChristianMurphy added 🙋 no/question This does not need any changes and removed 🙊 open/needs-repro This needs a reproduction labels Jul 7, 2022
@plastic-shurikens

This comment was marked as off-topic.

@ChristianMurphy

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🙋 no/question This does not need any changes
Development

No branches or pull requests

3 participants