Skip to content

Commit 01d07b3

Browse files
KyleAMathewswardpeetascorbic
authored
fix(gatsby): more reliable way to use prod versions of react/react-dom (#29683)
back port of #29620 to v2 Fix #28138 (comment) Set `NODE_ENV` to `production` in the child worker that does the SSR in dev. Co-authored-by: Ward Peeters <ward@coding-tech.com> Co-authored-by: Matt Kane <matt@gatsbyjs.com>
1 parent 2022f2b commit 01d07b3

File tree

2 files changed

+10
-18
lines changed

2 files changed

+10
-18
lines changed

packages/gatsby/src/utils/dev-ssr/render-dev-html.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import JestWorker from "jest-worker"
22
import fs from "fs-extra"
33
import { joinPath } from "gatsby-core-utils"
44
import report from "gatsby-cli/lib/reporter"
5+
import { isCI } from "gatsby-core-utils"
56

67
import { startListener } from "../../bootstrap/requires-writer"
78
import { findPageByPath } from "../find-page-by-path"
@@ -13,7 +14,15 @@ const startWorker = (): any => {
1314
const newWorker = new JestWorker(require.resolve(`./render-dev-html-child`), {
1415
exposedMethods: [`renderHTML`, `deleteModuleCache`, `warmup`],
1516
numWorkers: 1,
16-
forkOptions: { silent: false },
17+
forkOptions: {
18+
silent: false,
19+
env: {
20+
...process.env,
21+
NODE_ENV: isCI() ? `production` : `development`,
22+
forceColors: true,
23+
GATSBY_EXPERIMENTAL_DEV_SSR: true,
24+
},
25+
},
1726
})
1827

1928
// jest-worker is lazy with forking but we want to fork immediately so the user

packages/gatsby/src/utils/webpack.config.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -697,23 +697,6 @@ module.exports = async (
697697

698698
config.externals = [
699699
function (context, request, callback) {
700-
if (
701-
stage === `develop-html` &&
702-
isCI() &&
703-
process.env.GATSBY_EXPERIMENTAL_DEV_SSR
704-
) {
705-
if (request === `react`) {
706-
callback(null, `react/cjs/react.production.min.js`)
707-
return
708-
} else if (request === `react-dom/server`) {
709-
callback(
710-
null,
711-
`react-dom/cjs/react-dom-server.node.production.min.js`
712-
)
713-
return
714-
}
715-
}
716-
717700
const external = isExternal(request)
718701
if (external !== null) {
719702
callback(null, external)

0 commit comments

Comments
 (0)