-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix loading react-jsxdev instead of react-jsx (#17013)
Co-authored-by: chloe caruso <[email protected]>
- Loading branch information
1 parent
7bef462
commit 7a918d2
Showing
18 changed files
with
304 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { renderToReadableStream } from "react-dom/server.browser"; | ||
|
||
const HelloWorld = () => { | ||
return <div>Hello World</div>; | ||
}; | ||
|
||
const stream = new Response(await renderToReadableStream(<HelloWorld />)); | ||
|
||
console.log(await stream.text()); | ||
|
||
if (!process.env.NO_BUILD) { | ||
const self = await Bun.build({ | ||
entrypoints: [import.meta.path], | ||
define: { | ||
"process.env.NODE_ENV": JSON.stringify(process.env.CHILD_NODE_ENV), | ||
"process.env.NO_BUILD": "1", | ||
}, | ||
}); | ||
const code = await self.outputs[0].text(); | ||
let shouldHaveJSXDev = process.env.CHILD_NODE_ENV === "development"; | ||
let shouldHaveJSX = process.env.CHILD_NODE_ENV === "production"; | ||
|
||
if (shouldHaveJSXDev) { | ||
if (!code.includes("jsx_dev_runtime.jsxDEV")) { | ||
throw new Error("jsxDEV is not included"); | ||
} | ||
} | ||
|
||
if (shouldHaveJSX) { | ||
if (!code.includes("jsx_runtime.jsx")) { | ||
throw new Error("Jsx is not included"); | ||
} | ||
} | ||
|
||
const url = URL.createObjectURL(self.outputs[0]); | ||
await import(url); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"compilerOptions": { | ||
"jsx": "react-jsxdev" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import "./jsx-production"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { describe, expect, test, afterAll } from "bun:test"; | ||
import path from "path"; | ||
import { bunExe, bunEnv } from "harness"; | ||
|
||
const original_node_env = bunEnv.NODE_ENV; | ||
|
||
// https://github.com/oven-sh/bun/issues/3768 | ||
describe("jsx", () => { | ||
for (const node_env of ["production", "development", "test", ""]) { | ||
for (const child_node_env of ["production", "development", "test", ""]) { | ||
test(`react-jsxDEV parent: ${node_env} child: ${child_node_env} should work`, async () => { | ||
bunEnv.NODE_ENV = node_env; | ||
bunEnv.CHILD_NODE_ENV = child_node_env; | ||
bunEnv.TSCONFIG_JSX = "react-jsxdev"; | ||
expect([path.join(import.meta.dirname, "jsx-dev", "jsx-dev.tsx")]).toRun( | ||
"<div>Hello World</div>" + "\n" + "<div>Hello World</div>" + "\n", | ||
); | ||
}); | ||
|
||
test(`react-jsx parent: ${node_env} child: ${child_node_env} should work`, async () => { | ||
bunEnv.NODE_ENV = node_env; | ||
bunEnv.CHILD_NODE_ENV = child_node_env; | ||
bunEnv.TSCONFIG_JSX = "react-jsx"; | ||
expect([path.join(import.meta.dirname, "jsx-production-entry.ts")]).toRun( | ||
"<div>Hello World</div>" + "\n" + "<div>Hello World</div>" + "\n", | ||
); | ||
}); | ||
} | ||
} | ||
|
||
afterAll(() => { | ||
bunEnv.NODE_ENV = original_node_env; | ||
delete bunEnv.CHILD_NODE_ENV; | ||
delete bunEnv.TSCONFIG_JSX; | ||
}); | ||
}); |
Oops, something went wrong.