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

[docs] Update on-demand docs to avoid DEV JSX runtime #2204

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions docs/guides/mdx-on-demand.server.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ On the server:
```js path="server.js"
import {compile} from '@mdx-js/mdx'

const code = String(await compile('# hi', {outputFormat: 'function-body' /* …otherOptions */ }))
const code = String(await compile('# hi', {
outputFormat: 'function-body',
development: false, // Avoid use of the jsxDEV runtime
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m thinking maybe something like this? It’s a bit annoying, because it’s all very situational.

Suggested change
development: false, // Avoid use of the jsxDEV runtime
// development: false, // Use this to avoid use of jsx-dev-runtime during development

Maybe for the client we can use:

import {run} from '@mdx-js/mdx'
import * as runtime from 'react/jsx-runtime'
import * as devRuntime from 'react/jsx-dev-runtime'

const code = '' // To do: get `code` from server somehow.
const deveopment = process.env.NODE_ENV // To do: determine development mode for your setup.

const {default: Content} = await run(code, development ? devRuntime : runtime)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
development: false, // Avoid use of the jsxDEV runtime
development: false, // Generate code for production.

I’d suggest this: better to document what this does, instead of double negatives.

Alternatively, you can show both dev and prod versions

Suggested change
development: false, // Avoid use of the jsxDEV runtime
development: false, // Generate code for production.
// developmment: true, // Pass this to generate development code.

And then use the following below:

import * as runtime from 'react/jsx-runtime' // Production.
// import * as runtime from 'react/jsx-dev-runtime' // Development.

/* …otherOptions */
}))
// To do: send `code` to the client somehow.
```

Expand Down Expand Up @@ -82,7 +86,11 @@ export default function Page({code}) {

export async function getStaticProps() {
const code = String(
await compile('# hi', {outputFormat: 'function-body' /* …otherOptions */})
await compile('# hi', {
outputFormat: 'function-body',
development: false, // Avoid use of the jsxDEV runtime
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

/* …otherOptions */
})
)
return {props: {code}}
}
Expand Down