From 4f9242278e8939b8523f40a48e1c16648e67f4e7 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 18 Oct 2023 15:59:01 +0200 Subject: [PATCH] preact: remove deprecated, `MDXContext`, `withMDXComponents` --- packages/preact/index.js | 7 +----- packages/preact/lib/index.js | 41 +----------------------------- packages/preact/readme.md | 25 ++---------------- packages/preact/test/index.jsx | 46 ++-------------------------------- 4 files changed, 6 insertions(+), 113 deletions(-) diff --git a/packages/preact/index.js b/packages/preact/index.js index 7888697bb..e686091e3 100644 --- a/packages/preact/index.js +++ b/packages/preact/index.js @@ -1,6 +1 @@ -export { - MDXContext, - MDXProvider, - useMDXComponents, - withMDXComponents -} from './lib/index.js' +export {MDXProvider, useMDXComponents} from './lib/index.js' diff --git a/packages/preact/lib/index.js b/packages/preact/lib/index.js index ed9b1fd7e..8bb5b9ae0 100644 --- a/packages/preact/lib/index.js +++ b/packages/preact/lib/index.js @@ -1,7 +1,6 @@ /** * @typedef {import('mdx/types.js').MDXComponents} Components * @typedef {import('preact').ComponentChildren} ComponentChildren - * @typedef {import('preact').Context} Context */ /** @@ -25,45 +24,7 @@ import {createContext, h} from 'preact' import {useContext} from 'preact/hooks' -/** - * @type {Context} - * Context. - * @deprecated - * This export is marked as a legacy feature. - * That means it’s no longer recommended for use as it might be removed - * in a future major release. - * - * Please use `useMDXComponents` to get context based components and - * `MDXProvider` to set context based components instead. - */ -export const MDXContext = createContext({}) - -/** - * @param {import('preact').ComponentType} Component - * Component. - * @deprecated - * This export is marked as a legacy feature. - * That means it’s no longer recommended for use as it might be removed - * in a future major release. - * - * Please use `useMDXComponents` to get context based components instead. - * @returns - * Bound component. - */ -export function withMDXComponents(Component) { - return boundMDXComponent - - /** - * @param {Record & {components?: Components | null | undefined}} props - * Props. - * @returns {JSX.Element} - * Element. - */ - function boundMDXComponent(props) { - const allComponents = useMDXComponents(props.components) - return h(Component, {...props, allComponents}) - } -} +const MDXContext = createContext({}) /** * Get current components from the MDX Context. diff --git a/packages/preact/readme.md b/packages/preact/readme.md index cf4ef0e16..ba16ab9d8 100644 --- a/packages/preact/readme.md +++ b/packages/preact/readme.md @@ -21,8 +21,6 @@ Preact context for MDX. * [API](#api) * [`MDXProvider(props?)`](#mdxproviderprops) * [`useMDXComponents(components?)`](#usemdxcomponentscomponents) - * [`MDXContext`](#mdxcontext) - * [`withMDXComponents(Component)`](#withmdxcomponentscomponent) * [Types](#types) * [Security](#security) * [Contribute](#contribute) @@ -92,8 +90,8 @@ provider. ## API -This package exports the following identifiers: `MDXContext`, `MDXProvider`, -`useMDXComponents`, and `withMDXComponents`. +This package exports the following identifiers: `MDXProvider` and +`useMDXComponents`. There is no default export. ### `MDXProvider(props?)` @@ -135,25 +133,6 @@ Components`). `Components`. -### `MDXContext` - -> 🪦 **Deprecated**: This export is not recommended for use as it exposes -> internals which should be hidden. -> It might be removed in a future major release. -> Please use `useMDXComponents` to get context based components and -> `MDXProvider` to set context based components instead. - -The Preact Context for MDX (`Preact.Context`). - -### `withMDXComponents(Component)` - -> 🪦 **Deprecated**: This export is not recommended for use. -> It might be removed in a future major release. -> Please use `useMDXComponents` to get context based components instead. - -Create a HOC of `Components` which is given the current context based MDX -components. - ## Types This package is fully typed with [TypeScript][]. diff --git a/packages/preact/test/index.jsx b/packages/preact/test/index.jsx index cd9c7c28a..c2410f0e2 100644 --- a/packages/preact/test/index.jsx +++ b/packages/preact/test/index.jsx @@ -7,7 +7,7 @@ import assert from 'node:assert/strict' import {test} from 'node:test' import {evaluate} from '@mdx-js/mdx' -import {MDXProvider, useMDXComponents, withMDXComponents} from '@mdx-js/preact' +import {MDXProvider, useMDXComponents} from '@mdx-js/preact' import * as runtime_ from 'preact/jsx-runtime' import {render} from 'preact-render-to-string' @@ -16,10 +16,8 @@ const runtime = /** @type {RuntimeProduction} */ (runtime_) test('@mdx-js/preact', async function (t) { await t.test('should expose the public api', async function () { assert.deepEqual(Object.keys(await import('@mdx-js/preact')).sort(), [ - 'MDXContext', 'MDXProvider', - 'useMDXComponents', - 'withMDXComponents' + 'useMDXComponents' ]) }) @@ -209,44 +207,4 @@ test('@mdx-js/preact', async function (t) { ) } ) - - await t.test('should support `withComponents`', async function () { - const {default: Content} = await evaluate('# hi\n## hello', { - ...runtime, - useMDXComponents - }) - // Unknown props. - // type-coverage:ignore-next-line - const With = withMDXComponents(function (props) { - // Unknown props. - // type-coverage:ignore-next-line - return props.children - }) - - // Bug: this should use the `h2` component too, logically? - // As `withMDXComponents` is deprecated, and it would probably be a breaking - // change, we can just remove it later. - assert.equal( - render( - - } - }} - > - - } - }} - > - - - - ), - '

hi

\n

hello

' - ) - }) })