-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Make the compiler aware of custom components #2473
Comments
Well, I mean, there are some points. You may know that you are only passing There are some things we can decide at compile time. And some things at runtime. These are different times. What is the point of this change? If the point is to use a particular complex optimization plugin (a fork of |
@remcohaszing this is currently describing a nice to have for faster/smaller code at the loss of useful features. I’d like to reiterate my earlier “What is the point of this change?” — why should this go here and not in a plugin? |
Closing as this is not actionable yet and considerable time has passed. Open to discussing it again, if my above comments are addressed. |
The point is that a lot of content could be static. That would reduce the number of I suppose it could be a plugin. I can give it a try some time. |
Initial checklist
Problem
MDX allows users to inject custom components, either via props or via a provider. The following content:
# Header paragraph
is turned into the following code:
This works great! However, there’s a bit of redundant code. As a user, I know I’m only interested in injecting a specific component type, let’s say the
h1
component. There’s no point in supporting thep
orwrapper
components. What I would really like, is the following output:The intermediate
_createMdxContent
component is even redundant now, but let’s get into details later.Because part of the resulting JSX no longer depends on
props
, it can now be optimized using@babel/plugin-transform-react-constant-elements
. Because MDX typically contains a significant amount of JSX content, this optimization is very applicable to MDX. I imagine this could be a recma plugin, outside of MDX.Solution
Make MDX accept a list of component names at compile time. These names will be skipped by
recma-jsx-rewrite
.If the components are available where
compile()
is called, the user could write something like:Otherwise, the user needs to be a bit more careful specifying the list of component names.
Alternatives
If the user doesn’t use
props.components
, and they don’t use a provider, e.g. when using Next.js’mdx-components
file, then_components
could even be defined outside of_createMdxContent
.The text was updated successfully, but these errors were encountered: