Skip to content

Commit 97b9d59

Browse files
authored
Refactor to improve docs
* Update dates * Update a bunch of examples * Refactor some wording * Update examples around `development` for `evaluate` Closes GH-2204. Closes GH-2254.
1 parent ea7fd0b commit 97b9d59

15 files changed

+138
-95
lines changed

docs/community/sponsor.server.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const info = {
44
{name: 'Titus Wormer', github: 'wooorm', twitter: 'wooorm'}
55
],
66
published: new Date('2021-10-06'),
7-
modified: new Date('2022-01-25')
7+
modified: new Date('2022-02-01')
88
}
99

1010
# Sponsor

docs/community/support.server.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const info = {
55
{name: 'Titus Wormer', github: 'wooorm', twitter: 'wooorm'}
66
],
77
published: new Date('2019-07-03'),
8-
modified: new Date('2022-01-25')
8+
modified: new Date('2022-02-01')
99
}
1010

1111
# Support

docs/docs/extending-mdx.server.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const info = {
55
{name: 'Titus Wormer', github: 'wooorm', twitter: 'wooorm'}
66
],
77
published: new Date('2021-10-06'),
8-
modified: new Date('2023-01-18')
8+
modified: new Date('2023-01-19')
99
}
1010

1111
# Extending MDX

docs/docs/getting-started.server.mdx

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const info = {
55
{name: 'Titus Wormer', github: 'wooorm', twitter: 'wooorm'}
66
],
77
published: new Date('2021-10-05'),
8-
modified: new Date('2022-06-17')
8+
modified: new Date('2022-12-14')
99
}
1010

1111
# Getting started
@@ -193,7 +193,7 @@ You can also import several types about the API of MDX files from `@types/mdx`.
193193
For example:
194194

195195
```js path="example.ts"
196-
import type {MDXComponents} from 'mdx/types'
196+
import type {MDXComponents} from 'mdx/types.js'
197197
```
198198

199199
### Security
@@ -514,33 +514,42 @@ Which in turn lets us choose whether to use the `@mdx-js/mdx` or
514514

515515
#### Astro
516516

517-
[Astro](https://astro.build/) has an [official MDX integration](https://docs.astro.build/guides/integrations-guide/mdx/).
517+
[Astro](https://astro.build/) has their own MDX integration.
518518
You can add the integration with the Astro CLI (recommended):
519519

520520
```sh
521521
npx astro add mdx
522522
```
523523

524-
This base setup allows you to import markdown, Astro components,
525-
and other MDX files as components. To use
526-
other UI framework components in your MDX files
527-
(e.g. Preact, Vue, Svelte and more),
528-
see Astro’s [Framework components](https://docs.astro.build/en/core-concepts/framework-components/) guide.
524+
This base setup allows you to import markdown, Astro components, and other MDX
525+
files as components.
526+
To use components from frameworks in your MDX files, see Astro’s
527+
[Framework components](https://docs.astro.build/core-concepts/framework-components/)
528+
guide.
529529

530-
To learn how to configure layouts, YAML frontmatter, and set up Astro’s
531-
syntax highlighting, [see their MDX
530+
For more on how to combine Astro and MDX, see [their MDX
532531
integration docs](https://docs.astro.build/guides/integrations-guide/mdx/).
533532

534533
#### Create React App (CRA)
535534

536535
<Note type="info">
537-
**Note**: rewiring with CRACO (see below) is currently required for CRA 5,
538-
due to a bug in `react-scripts`
536+
**Note**: it’s currently probably not a good idea to use CRA.
537+
</Note>
538+
539+
<Note type="info">
540+
**Note**: rewiring with CRACO is currently required for CRA 5, due to a bug
541+
in `react-scripts`
539542
([`facebook/create-react-app#12166`](https://github.com/facebook/create-react-app/issues/12166)),
540543
which is also tracked at
541544
[`mdx-js/mdx#1870`](https://github.com/mdx-js/mdx/discussions/1870).
542545
</Note>
543546

547+
<Note type="info">
548+
**Note**: warnings about CRACO having
549+
`incorrect peer dependency "react-scripts@^4.0.0"`
550+
can currently be ignored.
551+
</Note>
552+
544553
<details>
545554
<summary>Expand example</summary>
546555

@@ -560,11 +569,6 @@ integration docs](https://docs.astro.build/guides/integrations-guide/mdx/).
560569
```
561570
</details>
562571

563-
[CRA](https://github.com/facebook/create-react-app) supports webpack loaders
564-
through webpack loader syntax in imports.
565-
566-
Install the webpack loader [`@mdx-js/loader`][mdx-loader].
567-
568572
<details>
569573
<summary>Expand CRACO example</summary>
570574

@@ -593,16 +597,15 @@ Install the webpack loader [`@mdx-js/loader`][mdx-loader].
593597
```
594598
</details>
595599

600+
[CRA](https://github.com/facebook/create-react-app) supports webpack loaders
601+
through webpack loader syntax in imports.
602+
603+
Install the webpack loader [`@mdx-js/loader`][mdx-loader].
604+
596605
For importing MDX without the `!@mdx-js/loader!` prefix, you can add
597606
the loader to the webpack config, by rewiring `react-scripts` using
598607
[CRACO](http://github.com/gsoft-inc/craco).
599608

600-
<Note type="info">
601-
**Note**: warnings about CRACO having
602-
`incorrect peer dependency "react-scripts@^4.0.0"`
603-
can be ignored for the above to work.
604-
</Note>
605-
606609
See also [¶ Webpack][webpack], which is used in CRA, and see [¶ React][react],
607610
which you’re likely using, for more info.
608611

@@ -624,15 +627,15 @@ on how to use MDX with Gatsby.
624627
<summary>Expand example</summary>
625628

626629
```js path="next.config.js"
627-
import nextMDX from '@next/mdx'
630+
import nextMdx from '@next/mdx'
628631

629-
const withMDX = nextMDX({
632+
const withMdx = nextMdx({
630633
// By default only the .mdx extension is supported.
631634
extension: /\.mdx?$/,
632635
options: {/* providerImportSource: …, otherOptions… */}
633636
})
634637

635-
export default withMDX({
638+
export default withMdx({
636639
// Support MDX files as pages:
637640
pageExtensions: ['md', 'mdx', 'tsx', 'ts', 'jsx', 'js'],
638641
})
@@ -649,18 +652,18 @@ In order to use it, you need to configure the `providerImportSource` as
649652
well.
650653

651654
<details>
652-
<summary>Expand example</summary>
655+
<summary>Expand provider example</summary>
653656

654657
```js path="next.config.js"
655-
import nextMDX from '@next/mdx'
658+
import nextMdx from '@next/mdx'
656659

657-
const withMDX = nextMDX({
660+
const withMdx = nextMdx({
658661
// By default only the .mdx extension is supported.
659662
extension: /\.mdx?$/,
660663
options: {providerImportSource: '@mdx-js/react', /* otherOptions… */}
661664
})
662665

663-
export default withMDX({
666+
export default withMdx({
664667
// Support MDX files as pages:
665668
pageExtensions: ['md', 'mdx', 'tsx', 'ts', 'jsx', 'js'],
666669
})

docs/docs/troubleshooting-mdx.server.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const info = {
55
{name: 'Titus Wormer', github: 'wooorm', twitter: 'wooorm'}
66
],
77
published: new Date('2021-10-18'),
8-
modified: new Date('2021-11-01')
8+
modified: new Date('2022-02-01')
99
}
1010

1111
{/* lint disable maximum-heading-length */}

docs/docs/using-mdx.server.mdx

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ import React from 'react'
112112
import ReactDom from 'react-dom'
113113
import Example from './example.mdx' // Assumes an integration is used to compile MDX -> JS.
114114

115-
ReactDom.render(<Example />, document.querySelector('#root'))
115+
const root = ReactDom.createRoot(document.getElementById('root'))
116+
root.render(<Example />)
116117
```
117118

118119
The main content is exported as the default export.
@@ -290,7 +291,9 @@ precedence).
290291

291292
## MDX provider
292293

294+
You probably don’t need a provider.
293295
Passing components is typically fine.
296+
Providers often only add extra weight.
294297
Take for example this file:
295298

296299
```mdx path="post.mdx"
@@ -311,12 +314,12 @@ const components = {
311314
table: Table
312315
}
313316

314-
ReactDom.render(
315-
<Post components={components} />,
316-
document.querySelector('#root')
317-
)
317+
const root = ReactDom.createRoot(document.getElementById('root'))
318+
root.render(<Post components={components} />)
318319
```
319320

321+
That works, those components are used.
322+
320323
But when you’re nesting MDX files (importing them into each other) it can become
321324
cumbersome.
322325
Like so:
@@ -363,13 +366,13 @@ Set it up like so:
363366
table: Table
364367
}
365368

366-
ReactDom.render(
367-
- <Post components={components} />,
369+
const root = ReactDom.createRoot(document.getElementById('root'))
370+
-root.render(<Post components={components} />)
371+
+root.render(
368372
+ <MDXProvider components={components}>
369373
+ <Post />
370-
+ </MDXProvider>,
371-
document.querySelector('#root')
372-
)
374+
+ </MDXProvider>
375+
+)
373376
```
374377

375378
Now you can remove the explicit and verbose component passing:
@@ -423,6 +426,9 @@ In this example the current context components are discarded:
423426
…which results in `h2`s using `Component3` and `h3`s using `Component4`.
424427
No component is used for `h1`.
425428

429+
If you’re not nesting MDX files, or not nesting them often, don’t use
430+
providers: pass components explicitly.
431+
426432
[context]: https://reactjs.org/docs/context.html
427433

428434
[start]: /docs/getting-started/

docs/docs/what-is-mdx.server.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const info = {
66
{name: 'Titus Wormer', github: 'wooorm', twitter: 'wooorm'}
77
],
88
published: new Date('2018-08-11'),
9-
modified: new Date('2021-11-01')
9+
modified: new Date('2023-01-06')
1010
}
1111

1212
# What is MDX?

docs/guides/frontmatter.server.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const info = {
44
{name: 'Titus Wormer', github: 'wooorm', twitter: 'wooorm'}
55
],
66
published: new Date('2021-10-06'),
7-
modified: new Date('2022-06-17')
7+
modified: new Date('2022-12-14')
88
}
99

1010
# Frontmatter

docs/guides/gfm.server.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const info = {
44
{name: 'Titus Wormer', github: 'wooorm', twitter: 'wooorm'}
55
],
66
published: new Date('2021-10-06'),
7-
modified: new Date('2022-06-17')
7+
modified: new Date('2022-12-14')
88
}
99

1010
# GitHub flavored markdown (GFM)

docs/guides/math.server.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const info = {
55
{name: 'Titus Wormer', github: 'wooorm', twitter: 'wooorm'}
66
],
77
published: new Date('2021-10-06'),
8-
modified: new Date('2022-06-17')
8+
modified: new Date('2022-12-14')
99
}
1010

1111
# Math

docs/guides/mdx-on-demand.server.mdx

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const info = {
55
{name: 'Titus Wormer', github: 'wooorm', twitter: 'wooorm'}
66
],
77
published: new Date('2021-11-13'),
8-
modified: new Date('2021-11-13')
8+
modified: new Date('2021-11-14')
99
}
1010

1111
# MDX on demand
@@ -28,15 +28,23 @@ On the server:
2828
```js path="server.js"
2929
import {compile} from '@mdx-js/mdx'
3030

31-
const code = String(await compile('# hi', {outputFormat: 'function-body' /* …otherOptions */ }))
31+
const code = String(await compile('# hi', {
32+
outputFormat: 'function-body',
33+
development: false
34+
// ^-- Generate code for production.
35+
// `false` if you use `/jsx-runtime` on client, `true` if you use
36+
// `/jsx-dev-runtime`.
37+
/* …otherOptions */
38+
}))
3239
// To do: send `code` to the client somehow.
3340
```
3441

3542
On the client:
3643

3744
```js path="client.js"
3845
import {run} from '@mdx-js/mdx'
39-
import * as runtime from 'react/jsx-runtime'
46+
import * as runtime from 'react/jsx-runtime' // Production.
47+
// import * as runtime from 'react/jsx-dev-runtime' // Development.
4048

4149
const code = '' // To do: get `code` from server somehow.
4250

@@ -64,7 +72,8 @@ Next.
6472

6573
```js path="pages/hello.js"
6674
import {useState, useEffect, Fragment} from 'react'
67-
import * as runtime from 'react/jsx-runtime'
75+
import * as runtime from 'react/jsx-runtime' // Production.
76+
// import * as runtime from 'react/jsx-dev-runtime' // Development.
6877
import {compile, run} from '@mdx-js/mdx'
6978

7079
export default function Page({code}) {
@@ -82,7 +91,14 @@ export default function Page({code}) {
8291

8392
export async function getStaticProps() {
8493
const code = String(
85-
await compile('# hi', {outputFormat: 'function-body' /* …otherOptions */})
94+
await compile('# hi', {
95+
outputFormat: 'function-body',
96+
development: false,
97+
// ^-- Generate code for production.
98+
// `false` if you use `/jsx-runtime` on client, `true` if you use
99+
// `/jsx-dev-runtime`.
100+
/* …otherOptions */
101+
})
86102
)
87103
return {props: {code}}
88104
}

docs/guides/syntax-highlighting.server.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const info = {
55
{name: 'Titus Wormer', github: 'wooorm', twitter: 'wooorm'}
66
],
77
published: new Date('2021-10-06'),
8-
modified: new Date('2022-06-17')
8+
modified: new Date('2022-08-27')
99
}
1010

1111
# Syntax highlighting

docs/migrating/v1.server.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export const info = {
55
{name: 'John Otander', github: 'johno', twitter: '4lpine'}
66
],
77
published: new Date('2019-04-04'),
8-
modified: new Date('2021-11-01')
8+
modified: new Date('2021-10-17')
99
}
1010

1111
<Note type="legacy">

docs/migrating/v2.server.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ You can update your code as follows:
387387

388388
const components = {/**/}
389389
const value = '# hi'
390-
const {default: Content} = await evaluate(value, {...provider, ...runtime})
390+
const {default: Content} = await evaluate(value, {...provider, ...runtime, development: false})
391391

392392
export default () => (
393393
<Content components={components} />

0 commit comments

Comments
 (0)