Skip to content
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

feat(gatsby): use production React for dev-ssr when CI=true #28728

Merged
merged 3 commits into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions packages/gatsby/cache-dir/ssr-develop-static-entry.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import React from "react"
import fs from "fs"
import { renderToString, renderToStaticMarkup } from "react-dom/server"
import { merge } from "lodash"
import { join } from "path"
import apiRunner from "./api-runner-ssr"
Expand All @@ -10,6 +8,16 @@ import syncRequires from "$virtual/ssr-sync-requires"
import { RouteAnnouncerProps } from "./route-announcer-props"
import { ServerLocation, Router, isRedirect } from "@reach/router"

let React
let ReactDom
if (process.env.CI) {
React = require(`react/cjs/react.production.min.js`)
ReactDom = require(`react-dom/cjs/react-dom-server.node.production.min.js`)
} else {
React = require(`react`)
ReactDom = require(`react-dom/server`)
}

KyleAMathews marked this conversation as resolved.
Show resolved Hide resolved
// import testRequireError from "./test-require-error"
// For some extremely mysterious reason, webpack adds the above module *after*
// this module so that when this code runs, testRequireError is undefined.
Expand Down Expand Up @@ -183,7 +191,7 @@ export default (pagePath, isClientOnlyPage, callback) => {
// If no one stepped up, we'll handle it.
if (!bodyHtml) {
try {
bodyHtml = renderToString(bodyComponent)
bodyHtml = ReactDom.renderToString(bodyComponent)
} catch (e) {
// ignore @reach/router redirect errors
if (!isRedirect(e)) throw e
Expand Down Expand Up @@ -229,7 +237,7 @@ export default (pagePath, isClientOnlyPage, callback) => {
<script key={`commons`} src="/commons.js" />,
]),
})
let htmlStr = renderToStaticMarkup(htmlElement)
let htmlStr = ReactDom.renderToStaticMarkup(htmlElement)
htmlStr = `<!DOCTYPE html>${htmlStr}`

callback(null, htmlStr)
Expand Down
4 changes: 4 additions & 0 deletions packages/gatsby/src/utils/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ module.exports = async (
)
}

if (stage === `develop-html`) {
envObject.CI = JSON.stringify(process.env.CI || `false`)
}

const mergedEnvVars = Object.assign(envObject, gatsbyVarObject)

return Object.keys(mergedEnvVars).reduce(
Expand Down