Skip to content

Commit a362bb4

Browse files
committed
react: remove deprecated, MDXContext, withMDXComponents
1 parent 4f92422 commit a362bb4

File tree

4 files changed

+6
-111
lines changed

4 files changed

+6
-111
lines changed

β€Žpackages/react/index.js

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
export {
2-
MDXContext,
3-
MDXProvider,
4-
useMDXComponents,
5-
withMDXComponents
6-
} from './lib/index.js'
1+
export {MDXProvider, useMDXComponents} from './lib/index.js'

β€Žpackages/react/lib/index.js

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/**
22
* @typedef {import('mdx/types.js').MDXComponents} Components
3-
* @typedef {import('react').Context<Components>} Context
43
* @typedef {import('react').ReactNode} ReactNode
54
*/
65

@@ -24,42 +23,7 @@
2423

2524
import React from 'react'
2625

27-
/**
28-
* @type {Context}
29-
* @deprecated
30-
* This export is marked as a legacy feature.
31-
* That means it’s no longer recommended for use as it might be removed
32-
* in a future major release.
33-
*
34-
* Please use `useMDXComponents` to get context based components and
35-
* `MDXProvider` to set context based components instead.
36-
*/
37-
export const MDXContext = React.createContext({})
38-
39-
/**
40-
* @param {import('react').ComponentType<any>} Component
41-
* Component.
42-
* @deprecated
43-
* This export is marked as a legacy feature.
44-
* That means it’s no longer recommended for use as it might be removed
45-
* in a future major release.
46-
*
47-
* Please use `useMDXComponents` to get context based components instead.
48-
*/
49-
export function withMDXComponents(Component) {
50-
return boundMDXComponent
51-
52-
/**
53-
* @param {Record<string, unknown> & {components?: Components | null | undefined}} props
54-
* Props.
55-
* @returns {JSX.Element}
56-
* Element.
57-
*/
58-
function boundMDXComponent(props) {
59-
const allComponents = useMDXComponents(props.components)
60-
return React.createElement(Component, {...props, allComponents})
61-
}
62-
}
26+
const MDXContext = React.createContext({})
6327

6428
/**
6529
* Get current components from the MDX Context.

β€Žpackages/react/readme.md

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ React context for MDX.
2121
* [API](#api)
2222
* [`MDXProvider(props?)`](#mdxproviderprops)
2323
* [`useMDXComponents(components?)`](#usemdxcomponentscomponents)
24-
* [`MDXContext`](#mdxcontext)
25-
* [`withMDXComponents(Component)`](#withmdxcomponentscomponent)
2624
* [Types](#types)
2725
* [Security](#security)
2826
* [Contribute](#contribute)
@@ -92,8 +90,8 @@ provider.
9290

9391
## API
9492

95-
This package exports the following identifiers: `MDXContext`, `MDXProvider`,
96-
`useMDXComponents`, and `withMDXComponents`.
93+
This package exports the following identifiers: `MDXProvider` and
94+
`useMDXComponents`.
9795
There is no default export.
9896

9997
### `MDXProvider(props?)`
@@ -135,25 +133,6 @@ Components`).
135133

136134
`Components`.
137135

138-
### `MDXContext`
139-
140-
> πŸͺ¦ **Deprecated**: This export is not recommended for use as it exposes
141-
> internals which should be hidden.
142-
> It might be removed in a future major release.
143-
> Please use `useMDXComponents` to get context based components and
144-
> `MDXProvider` to set context based components instead.
145-
146-
The React Context for MDX (`React.Context`).
147-
148-
### `withMDXComponents(Component)`
149-
150-
> πŸͺ¦ **Deprecated**: This export is not recommended for use.
151-
> It might be removed in a future major release.
152-
> Please use `useMDXComponents` to get context based components instead.
153-
154-
Create a HOC of `Components` which is given the current context based MDX
155-
components.
156-
157136
## Types
158137

159138
This package is fully typed with [TypeScript][].

β€Žpackages/react/test/index.jsx

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import assert from 'node:assert/strict'
66
import {test} from 'node:test'
77
import {evaluate} from '@mdx-js/mdx'
8-
import {MDXProvider, useMDXComponents, withMDXComponents} from '@mdx-js/react'
8+
import {MDXProvider, useMDXComponents} from '@mdx-js/react'
99
import React from 'react'
1010
import * as runtime_ from 'react/jsx-runtime'
1111
import {renderToString} from 'react-dom/server'
@@ -17,10 +17,8 @@ const runtime = /** @type {RuntimeProduction} */ (
1717
test('@mdx-js/react', async function (t) {
1818
await t.test('should expose the public api', async function () {
1919
assert.deepEqual(Object.keys(await import('@mdx-js/preact')).sort(), [
20-
'MDXContext',
2120
'MDXProvider',
22-
'useMDXComponents',
23-
'withMDXComponents'
21+
'useMDXComponents'
2422
])
2523
})
2624

@@ -207,45 +205,4 @@ test('@mdx-js/react', async function (t) {
207205
)
208206
}
209207
)
210-
211-
await t.test('should support `withComponents`', async function () {
212-
const {default: Content} = await evaluate('# hi\n## hello', {
213-
...runtime,
214-
useMDXComponents
215-
})
216-
217-
// Unknown props.
218-
// type-coverage:ignore-next-line
219-
const With = withMDXComponents(function (props) {
220-
// Unknown props.
221-
// type-coverage:ignore-next-line
222-
return props.children
223-
})
224-
225-
// Bug: this should use the `h2` component too, logically?
226-
// As `withMDXComponents` is deprecated, and it would probably be a breaking
227-
// change, we can just remove it later.
228-
assert.equal(
229-
renderToString(
230-
<MDXProvider
231-
components={{
232-
h1(props) {
233-
return <h1 style={{color: 'tomato'}} {...props} />
234-
}
235-
}}
236-
>
237-
<With
238-
components={{
239-
h2(props) {
240-
return <h2 style={{color: 'papayawhip'}} {...props} />
241-
}
242-
}}
243-
>
244-
<Content />
245-
</With>
246-
</MDXProvider>
247-
),
248-
'<h1 style="color:tomato">hi</h1>\n<h2>hello</h2>'
249-
)
250-
})
251208
})

0 commit comments

Comments
 (0)