Skip to content

Commit

Permalink
chore(deps): bump esbuild to latest, remove shim (#3860)
Browse files Browse the repository at this point in the history
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
  • Loading branch information
mcansh and kentcdodds committed Aug 24, 2022
1 parent 99329de commit cf1f2d8
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 112 deletions.
10 changes: 10 additions & 0 deletions .changeset/gold-mice-pretend.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
"remix": patch
"@remix-run/dev": patch
---

use esbuild's new automatic jsx transform

there are no code changes from your end, but by using the new transform, we can prevent duplicate React imports from appearing in your build (#2987)

the automatic jsx transform was introduced in React 17 and allows you to write your React code without ever needing to import React to just write jsx, if you used `useState` or other hooks, you still needed it. However up until now, esbuild didnt support this and instead recommended you to use a "shim" to add `import React from 'react'` to your files to get the same affect. This unfortantely has caused some pain points with some external libraries resulting in React being declared multiple times, but no more! (Chance said so himself, so... go tell him if it's busted)
11 changes: 4 additions & 7 deletions packages/remix-dev/compiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@ import { serverRouteModulesPlugin } from "./compiler/plugins/serverRouteModulesP
import { writeFileSafe } from "./compiler/utils/fs";
import { urlImportsPlugin } from "./compiler/plugins/urlImportsPlugin";

// When we build Remix, this shim file is copied directly into the output
// directory in the same place relative to this file. It is eventually injected
// as a source file when building the app.
const reactShim = path.resolve(__dirname, "compiler/shims/react.ts");

interface BuildConfig {
mode: BuildMode;
target: BuildTarget;
Expand Down Expand Up @@ -366,7 +361,6 @@ async function createBrowserBuild(
platform: "browser",
format: "esm",
external: externals,
inject: config.serverBuildTarget === "deno" ? [] : [reactShim],
loader: loaders,
bundle: true,
logLevel: "silent",
Expand All @@ -387,6 +381,8 @@ async function createBrowserBuild(
config.devServerPort
),
},
jsx: "automatic",
jsxDev: options.mode !== BuildMode.Production,
plugins,
});
}
Expand Down Expand Up @@ -459,7 +455,6 @@ function createServerBuild(
? ["module", "main"]
: ["main", "module"],
target: options.target,
inject: config.serverBuildTarget === "deno" ? [] : [reactShim],
loader: loaders,
bundle: true,
logLevel: "silent",
Expand All @@ -475,6 +470,8 @@ function createServerBuild(
config.devServerPort
),
},
jsx: "automatic",
jsxDev: options.mode !== BuildMode.Production,
plugins,
})
.then(async (build) => {
Expand Down
3 changes: 0 additions & 3 deletions packages/remix-dev/compiler/shims/react.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/remix-dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"chalk": "^4.1.2",
"chokidar": "^3.5.1",
"dotenv": "^16.0.0",
"esbuild": "0.14.22",
"esbuild": "0.14.51",
"exit-hook": "2.2.1",
"express": "^4.17.1",
"fast-glob": "3.2.11",
Expand Down
Loading

0 comments on commit cf1f2d8

Please sign in to comment.