Skip to content
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

draft: feat(jsx): base for supporting more runtimes #236

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

muningis
Copy link
Contributor

@muningis muningis commented Dec 18, 2024

What:
Support JSX runtimes other than react.

Why:
Allow this to be used with other JSX runtimes supported by mdxjs (https://mdxjs.com/docs/getting-started/#jsx) but not limited to. For example, this can work quite fine with https://hono.dev/ too, eventhough it's not mentioned here (thanks to a fact, that Hono is compatible with React's API)

How:
Adjust bundleMDX to accept jsxConfig (which fallbacks to react).
getMDXComponent will have to be adjusted too, still looking for an approach which would have least breaking changes. Second paramter globals could be used for that, as such:

const { code } = bundleMDX({
  jsxConfig: {
    JsxLib: {
      varName: 'HonoJSX',
      package: 'hono/jsx',
    },
    JsxDom: {
      varName: 'HonoDOM',
      package: 'hono/jsx/dom',
    },
    jsxRuntime: {
      varName: '_jsx_runtime',
      package: 'hono/jsx/jsx-runtime',
    },
  }
});

// ...

import * as HonoJSX from "hono/jsx";
import * as HonoDOM from "hono/jsx/dom";
import * as _jsx_runtime from "hono/jsx/jsx-runtime";
const Component = getMDXComponent(code, { HonoJSX, HonoDOM, _jsx_runtime });

Checklist:

  • Documentation
  • Tests - TODO
  • Ready to be merged

Todo:

  • Readme update
  • Preact tests
  • Hono tests (react compatible, not officially supported by mdx-js)
  • Vue tests
  • Solid tests
  • Svelte tests

@muningis muningis force-pushed the support_more_runtimes branch from cb27722 to b301a41 Compare December 18, 2024 14:55
kentcdodds
kentcdodds previously approved these changes Dec 18, 2024
Copy link
Owner

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I think I want to lowercase a few things. Other than that, this is perfect :)

src/index.js Outdated Show resolved Hide resolved
src/types.d.ts Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
src/index.js Outdated Show resolved Hide resolved
src/types.d.ts Outdated Show resolved Hide resolved
kentcdodds
kentcdodds previously approved these changes Dec 18, 2024
Copy link
Owner

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! One last thing. Could you add a note about this in the readme?

@muningis
Copy link
Contributor Author

Of course! Still have to do few things though:

  • add some unit tests for various runtimes (primarly Vue, Solid, Svelte).
  • modify getMDXBudler - will adjust /client import to fallback/default to React, and /client/jsx will allow passing own JSX bindings+runtime.

kentcdodds
kentcdodds previously approved these changes Dec 23, 2024
Copy link
Owner

@kentcdodds kentcdodds left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants