Skip to content

Commit

Permalink
fix(gatsby): more reliable way to use prod versions of react/react-dom (
Browse files Browse the repository at this point in the history
#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>
  • Loading branch information
3 people committed Feb 23, 2021
1 parent 2022f2b commit 01d07b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 18 deletions.
11 changes: 10 additions & 1 deletion packages/gatsby/src/utils/dev-ssr/render-dev-html.ts
Expand Up @@ -2,6 +2,7 @@ import JestWorker from "jest-worker"
import fs from "fs-extra"
import { joinPath } from "gatsby-core-utils"
import report from "gatsby-cli/lib/reporter"
import { isCI } from "gatsby-core-utils"

import { startListener } from "../../bootstrap/requires-writer"
import { findPageByPath } from "../find-page-by-path"
Expand All @@ -13,7 +14,15 @@ const startWorker = (): any => {
const newWorker = new JestWorker(require.resolve(`./render-dev-html-child`), {
exposedMethods: [`renderHTML`, `deleteModuleCache`, `warmup`],
numWorkers: 1,
forkOptions: { silent: false },
forkOptions: {
silent: false,
env: {
...process.env,
NODE_ENV: isCI() ? `production` : `development`,
forceColors: true,
GATSBY_EXPERIMENTAL_DEV_SSR: true,
},
},
})

// jest-worker is lazy with forking but we want to fork immediately so the user
Expand Down
17 changes: 0 additions & 17 deletions packages/gatsby/src/utils/webpack.config.js
Expand Up @@ -697,23 +697,6 @@ module.exports = async (

config.externals = [
function (context, request, callback) {
if (
stage === `develop-html` &&
isCI() &&
process.env.GATSBY_EXPERIMENTAL_DEV_SSR
) {
if (request === `react`) {
callback(null, `react/cjs/react.production.min.js`)
return
} else if (request === `react-dom/server`) {
callback(
null,
`react-dom/cjs/react-dom-server.node.production.min.js`
)
return
}
}

const external = isExternal(request)
if (external !== null) {
callback(null, external)
Expand Down

0 comments on commit 01d07b3

Please sign in to comment.