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

Bun & Deno compatibility with react-jsx runtime #159

Open
arthurfiorette opened this issue Mar 25, 2024 · 12 comments
Open

Bun & Deno compatibility with react-jsx runtime #159

arthurfiorette opened this issue Mar 25, 2024 · 12 comments
Assignees
Labels
good first issue Good for newcomers help wanted Extra attention is needed html-runtime Related to @kitajs/html

Comments

@arthurfiorette
Copy link
Member

@arthurfiorette I feel that we should export both jsx and jsxDEV functions from the jsx-runtime file and also create a jsx-dev-runtime file. They should have the same signature, this should be an easy thing to do.

@7f8ddd you should open an issue to Bun about this. Bun should handle the difference between dev and prod when it bundles. For this library, the difference is zero but for something like React you should not use the dev mode in a prod build.

Originally posted by @JacopoPatroclo in #150 (comment)

@arthurfiorette
Copy link
Member Author

arthurfiorette commented Mar 25, 2024

I feel that we should export both jsx and jsxDEV functions from the jsx-runtime file and also create a jsx-dev-runtime file. They should have the same signature, this should be an easy thing to do.

Sure, this is probably the correct way to solve this.

However, I made some tests a week ago, and this scared me a little bit. Bun was rendering objects in production mode, even for KitaJS. Just like as if bun in prod mode was react-only compatible.

More tests using bun should be made, and probably also setup a CI for It.

Originally posted by @arthurfiorette in #150 (comment)

@arthurfiorette
Copy link
Member Author

arthurfiorette commented Mar 25, 2024

More tests using bun should be made, and probably also setup a CI for It.

oven-sh/bun#5090 (comment) and oven-sh/bun#3554.

Running our tests in Bun might be a problem.

@aralroca
Copy link

I think exporting the jsx-runtime could help to make kitajs/html even faster if you prerender the static content with this plugin: https://github.com/aralroca/prerender-macro in fact I tried to do the integration with kitajs/html, I think that with a public jsx-runtime it could be well integrated.

@arthurfiorette
Copy link
Member Author

I think exporting the jsx-runtime could help to make kitajs/html even faster if you prerender the static content with this plugin: https://github.com/aralroca/prerender-macro in fact I tried to do the integration with kitajs/html, I think that with a public jsx-runtime it could be well integrated.

This could indeed work... I'll take a look at it. It's probably just like deno's https://deno.com/blog/v1.38#fastest-jsx-transform

@aralroca
Copy link

I just realized that Deno has JSX precompile! that's amazing! thanks to share it

@arthurfiorette arthurfiorette changed the title Bun compatibility with react-jsx runtime Bun & Deno compatibility with react-jsx runtime Mar 26, 2024
@arthurfiorette arthurfiorette self-assigned this Mar 26, 2024
@arthurfiorette arthurfiorette added good first issue Good for newcomers help wanted Extra attention is needed html-runtime Related to @kitajs/html labels Mar 26, 2024
@arthurfiorette
Copy link
Member Author

arthurfiorette commented Mar 27, 2024

I think exporting the jsx-runtime could help to make kitajs/html even faster if you prerender the static content with this plugin: https://github.com/aralroca/prerender-macro in fact I tried to do the integration with kitajs/html, I think that with a public jsx-runtime it could be well integrated.

I do not have enough time these days to test it, but the link below is pretty much self explanatory if someone would like to help me :) (I'm happy to review and help with any PRs made)

https://github.com/aralroca/prerender-macro?tab=readme-ov-file#add-your-framework-example

@7f8ddd
Copy link

7f8ddd commented Mar 27, 2024

I think exporting the jsx-runtime could help to make kitajs/html even faster if you prerender the static content with this plugin: https://github.com/aralroca/prerender-macro in fact I tried to do the integration with kitajs/html, I think that with a public jsx-runtime it could be well integrated.

I do not have enough time these days to test it, but the link below is pretty much self explanatory if someone would like to help me :) (I'm happy to review and help with any PRs made)

https://github.com/aralroca/prerender-macro?tab=readme-ov-file#add-your-framework-example

I put this together, seems like it's working, not sure, maybe someone here can test it.

import Html from "@kitajs/html";
import prerenderMacroPlugin, { type PrerenderConfig } from "prerender-macro";

export const prerenderConfig = {
  render: async (Component: Html.Component, props: Html.PropsWithChildren) =>
    Html.contentToString(<Component {...props} />),
} satisfies PrerenderConfig;

export const plugin = prerenderMacroPlugin({
  prerenderConfigPath: import.meta.url,
});

await Bun.build({
  plugins: [prerenderMacroPlugin({ prerenderConfigPath: import.meta.url })],
  entrypoints: ["src/index.ts"],
  outdir: "./build",
  target: "bun",
});

@arthurfiorette
Copy link
Member Author

Can you try with:

export const prerenderConfig = { render: Html.createElement } satisfies PrerenderConfig;

@aralroca
Copy link

aralroca commented Mar 27, 2024

@arthurfiorette I tried the tests and it works, but I did a monkey-patch (adding the file jsx-dev-runtime with jsxDEV):

Screenshot 2024-03-27 at 16 41 40

@arthurfiorette
Copy link
Member Author

arthurfiorette commented Mar 27, 2024

@arthurfiorette I tried the tests and it works, but I did a monkey-patch (adding the file jsx-dev-runtime with jsxDEV):

Yeah, we're going to also add the jsx-dev-runtime because of #150 (comment)

nvm just saw your #166. Thanks a lot!!

@arthurfiorette
Copy link
Member Author

Anyone wants to work on supporting this to bun? After #166 I think only adding a CI for it would be enough

@arthurfiorette
Copy link
Member Author

With #166, Bun works fine. I'll let this open when "official" support for Deno will be added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed html-runtime Related to @kitajs/html
Projects
Status: 🔖 Ready
Development

No branches or pull requests

3 participants