Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

[Feature]: allow to define custom JSX factories #1633

Closed
jraoult opened this issue Jan 24, 2022 · 1 comment
Closed

[Feature]: allow to define custom JSX factories #1633

jraoult opened this issue Jan 24, 2022 · 1 comment

Comments

@jraoult
Copy link

jraoult commented Jan 24, 2022

What is the new or updated feature that you are suggesting?

To be able to support @emtion/react's css prop on React elements, esbuild's config needs to be slightly tweaked.

I managed to patch Remix's https://github.com/remix-run/remix/blob/main/packages/remix-dev/compiler.ts and https://github.com/remix-run/remix/blob/main/packages/remix-dev/compiler/shims/react.ts to make it work in dev but ideally it we would be possible to configure esbuild from remix.config.js (or similar).

It could be a jsx factory specific thing:

module.exports = {
  [...],
  jsxFactory: "jsx",
  reactShim: "path/to/shim"
}

or just allowing the whole esbuild configuration to be extended:

module.exports = {
  [...],
  esbuildConf: {
    jsxFactory: "jsx",
    inject: ["path/to/shim"]
  }
}

Why should this feature be included?

To be able to support custom JSX factories like emotion's one.

@jraoult
Copy link
Author

jraoult commented Jan 24, 2022

Here's the patch I created for v1.1.3:

diff --git a/compiler/shims/react.ts b/compiler/shims/react.ts
index eb0f102ecb7ea96274f00ad964393c86981dbdf9..a65ef8521b1dedf754adc1013f5c32799b6d5136 100644
--- a/compiler/shims/react.ts
+++ b/compiler/shims/react.ts
@@ -1,2 +1,4 @@
+import { jsx } from "@emotion/react";
 import * as React from "react";
-export { React };
+
+export { jsx, React };
diff --git a/compiler.js b/compiler.js
index 1a6cabc2ae7102055cba88cb57084ba7ec8642b4..3cf652f33445a4b198b5f10b2915300654181e88 100644
--- a/compiler.js
+++ b/compiler.js
@@ -297,6 +297,7 @@ async function createBrowserBuild(config, options) {
     platform: "browser",
     format: "esm",
     external: externals,
+    jsxFactory: "jsx",
     inject: [reactShim],
     loader: loaders.loaders,
     bundle: true,
@@ -329,6 +330,7 @@ async function createServerBuild(config, options) {
     format: config.serverModuleFormat,
     mainFields: config.serverModuleFormat === "esm" ? ["module", "main"] : ["main", "module"],
     target: options.target,
+    jsxFactory: "jsx",
     inject: [reactShim],
     loader: loaders.loaders,
     bundle: true,

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant