-
-
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
Add run
, runSync
exports
#1792
Add run
, runSync
exports
#1792
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/mdx/mdx/2MvNwNBQiUTQrJERbDvg8AGpCDBh |
Sorry, was too late so I had to stop, I will continue the work today |
MADE IT TO WORK 🚀 🥳 🎂 🎈 P.S: Never done Preact, but will try to make it work there as well |
Should I create a separate PR for preact? probably so |
CI is failing but I haven't touch |
The problem with CI is indeed unrelated to your work, it instead has to do with Node 17 breaking an experimental feature! Some questions:
|
@wooorm yeah for sure, let me get back to you on that one btw. It is pending from my side, trying my best to find some time to do things little by little. |
@wooorm I updated the docs, please help me to clarify the situation if you don't understand it, I am not attached to anything, just finding the way I could build something docusaurus-like at the end. |
Hi again Yordis, thanks for answering my questions! So, I can understand the need to compile on the server and eval code on the client. Is it often the right way to do it? I have my doubts.
The problem I have with placing it here is that we now need this same function for every framework. React, Preact, Emotion, Theme UI, etc. This particular solution is also limited: it’s sync only. The proper way to do it would in my opinion be, similar to
Yep, it’s intended! What if instead:
|
What would be the value of making that async? Are we talking about the evaluation or execution of the function? I am not sure what would be the vale, would like to understand the intention.
Yeah ... don't disagree on that one, I am not what else to do when most people do such implementation
I didn't know that it exists, as long as people understand what
Love it |
Several things about MDX are async. In some cases things can be sync, but I think it’s best to default to async so that it’ll always work. import Something from 'https://example.com/things.js' into: const {default: Something} = await import('https://example.com/things.js')
On the server: import {compile} from '@mdx-js/mdx'
const code = await compile(file, {outputFormat: 'function-body', ...otherCompileOptions}) On the client: import {run} from '@mdx-js/mdx'
import * as runtime from 'react/jsx-runtime'
const code = '' // get the code somewhow from the server
const {default: Component} = await run(code, runtime) |
Say no more! Thank you so much for explaining, it will pay forward, TIL that I had to break an old thinking pattern |
import {run} from '@mdx-js/mdx'
import * as runtime from 'react/jsx-runtime'
const code = '' // get the code somewhow from the server
const {default: Component} = await run(code, runtime) How do you pass more global things to the context other than Last-mile, I am leaning towards documenting things at this point |
You can‘t! I understand you want to, but there are some downsides to globals. You can pass |
That works! Given the context, I don't see an issue, and I actually LOVE that I cant |
So, documentation and exposing |
Before I removed the react to stuff that I added, I replaced the implementation with @wooorm I would love to get your guidelines in terms of documentation. I feel I am not as good you are, so I feel a bit impostor on this one. Gonna try to do my best. |
Do I need to maintain the |
Yep, Here’s how I applied your idea to xdm: wooorm/xdm@710ef5f, I think you’d be able to reuse most of that prose. Then I’ll work on the guide in a separate PR and ping you? |
Please do
In bed I thought about moving the content the way you did 😆 , well, I am happy to see this becoming real. Thank you so much! |
run
, runSync
exports
Can you expand on the problem you’re having
I was replacing
mdx-bundler
, where I used the following feature:In the setup I have the following routing in NextJS:
Notice the
[slug]
, which means that part of the routing is dynamic. I am doingthe following in my
getStaticProps
:So then in the client, I can use
props.post.code
eventually in my client.How this solves that, and whether there are potential alternatives?
I am not sure if there is a better alternative and way to do this.
The directory containing
the ADRs will be outside my app
, so I am not sureif I should use
import(...)
directlyfrom the client side
. How does the file system lookup would work? I am not sureHappy to hear from alternatives, the end-goal is to allow people to use such
setup for documentation like
docusaurus
but specific to ADRs and the tool.Should this feature be here? In this package? Could it be somewhere else? Where?
Since everything is related to MDX and React, it feels the right place. And
it feels that
mdx@v2
was definitely taking into consideration this since at least I foundfunction-body
in it that feels it could be used for use cases(I would like to understand why it is there for you don't mind.)
I am personally biased towards adding it to the package because it is
tree-shaking friendly, and the code shouldn't change much, and it was quite
handy for those few cases that people want to reach for sending the string from
SSR.
It could be definitely in another package, the complexity is to know that you
need to pass
react/jsx-runtime
and do the trick withnew Function
, onceyou know how to do it, it is simple, but probably a lot of time researching.
I can take the lead on publishing a package, but my personal bias is more about
helping the future person that didn't know how to solve the problem or that
such an external package exists.
No preferences in the grand scheme of things
Full credit to: https://github.com/kentcdodds/mdx-bundler and @kentcdodds on this one.