Skip to content

Commit 4f92422

Browse files
committedOct 18, 2023
preact: remove deprecated, MDXContext, withMDXComponents
1 parent 5afa48e commit 4f92422

File tree

4 files changed

+6
-113
lines changed

4 files changed

+6
-113
lines changed
 

‎packages/preact/index.js

+1-6
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/preact/lib/index.js

+1-40
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
/**
22
* @typedef {import('mdx/types.js').MDXComponents} Components
33
* @typedef {import('preact').ComponentChildren} ComponentChildren
4-
* @typedef {import('preact').Context<Components>} Context
54
*/
65

76
/**
@@ -25,45 +24,7 @@
2524
import {createContext, h} from 'preact'
2625
import {useContext} from 'preact/hooks'
2726

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

6829
/**
6930
* Get current components from the MDX Context.

‎packages/preact/readme.md

+2-23
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ Preact 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 Preact Context for MDX (`Preact.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/preact/test/index.jsx

+2-44
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import assert from 'node:assert/strict'
88
import {test} from 'node:test'
99
import {evaluate} from '@mdx-js/mdx'
10-
import {MDXProvider, useMDXComponents, withMDXComponents} from '@mdx-js/preact'
10+
import {MDXProvider, useMDXComponents} from '@mdx-js/preact'
1111
import * as runtime_ from 'preact/jsx-runtime'
1212
import {render} from 'preact-render-to-string'
1313

@@ -16,10 +16,8 @@ const runtime = /** @type {RuntimeProduction} */ (runtime_)
1616
test('@mdx-js/preact', async function (t) {
1717
await t.test('should expose the public api', async function () {
1818
assert.deepEqual(Object.keys(await import('@mdx-js/preact')).sort(), [
19-
'MDXContext',
2019
'MDXProvider',
21-
'useMDXComponents',
22-
'withMDXComponents'
20+
'useMDXComponents'
2321
])
2422
})
2523

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

0 commit comments

Comments
 (0)
Please sign in to comment.