Skip to content

Remove the type casting of JSX runtimes #2604

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

Merged
merged 1 commit into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
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
4 changes: 0 additions & 4 deletions docs/migrating/v3.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ You will get a runtime error if these features are used in MDX without
If you passed the `useDynamicImport` option before, remove it, the behavior
is now the default.

If you use `react/jsx-runtime`, you might get a TypeScript error (such as
`Property 'Fragment' is missing in type`), because it is typed incorrectly.
To remediate this, do:

```tsx
import * as runtime from 'react/jsx-runtime'

Expand Down
7 changes: 1 addition & 6 deletions packages/preact/test/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,16 @@
/* @jsxImportSource preact */

/**
* @import {Fragment, Jsx} from '@mdx-js/mdx'
* @import {ComponentProps} from 'preact'
*/

import assert from 'node:assert/strict'
import {test} from 'node:test'
import {evaluate} from '@mdx-js/mdx'
import {MDXProvider, useMDXComponents} from '@mdx-js/preact'
import * as runtime_ from 'preact/jsx-runtime'
import * as runtime from 'preact/jsx-runtime'
import {render} from 'preact-render-to-string'

const runtime = /** @type {{Fragment: Fragment, jsx: Jsx, jsxs: Jsx}} */ (
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(), [
Expand Down
7 changes: 1 addition & 6 deletions packages/react/test/index.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/**
* @import {Fragment, Jsx} from '@mdx-js/mdx'
* @import {ComponentProps} from 'react'
*/

Expand All @@ -8,13 +7,9 @@ import {test} from 'node:test'
import {evaluate} from '@mdx-js/mdx'
import {MDXProvider, useMDXComponents} from '@mdx-js/react'
import React from 'react'
import * as runtime_ from 'react/jsx-runtime'
import * as runtime from 'react/jsx-runtime'
import {renderToString} from 'react-dom/server'

const runtime = /** @type {{Fragment: Fragment, jsx: Jsx, jsxs: Jsx}} */ (
/** @type {unknown} */ (runtime_)
)

test('@mdx-js/react', async function (t) {
await t.test('should expose the public api', async function () {
assert.deepEqual(Object.keys(await import('@mdx-js/preact')).sort(), [
Expand Down
18 changes: 6 additions & 12 deletions packages/vue/test/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/**
* @import {Fragment, Jsx} from '@mdx-js/mdx'
* @import {MDXModule} from 'mdx/types.js'
* @import {Component} from 'vue'
*/
Expand All @@ -8,18 +7,10 @@ import assert from 'node:assert/strict'
import test from 'node:test'
import {compile, run} from '@mdx-js/mdx'
import {MDXProvider, useMDXComponents} from '@mdx-js/vue'
import * as runtime_ from 'vue/jsx-runtime'
import serverRenderer from '@vue/server-renderer'
import * as runtime from 'vue/jsx-runtime'
import * as vue from 'vue'

const runtime = /** @type {{Fragment: Fragment, jsx: Jsx, jsxs: Jsx}} */ (
/** @type {unknown} */ (runtime_)
)

// Note: a regular import would be nice but that completely messes up the JSX types.
const name = '@vue/server-renderer'
/** @type {{default: {renderToString(node: unknown): string}}} */
const {default: serverRenderer} = await import(name)

test('@mdx-js/vue', async function (t) {
await t.test('should expose the public api', async function () {
assert.deepEqual(Object.keys(await import('@mdx-js/vue')).sort(), [
Expand Down Expand Up @@ -133,7 +124,10 @@ async function evaluate(value) {
outputFormat: 'function-body',
providerImportSource: '#'
})
return run(file, {...runtime, useMDXComponents})
return run(file, {
...runtime,
useMDXComponents
})
}

/**
Expand Down