From 1f0f81081f94fbbc9adc84920e7c3ee316f21fe3 Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Mon, 21 Dec 2020 12:33:20 -0800 Subject: [PATCH 1/3] feat(gatsby): use production React for dev-ssr when CI=true --- .../gatsby/cache-dir/ssr-develop-static-entry.js | 16 ++++++++++++---- packages/gatsby/src/utils/webpack.config.js | 4 ++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/packages/gatsby/cache-dir/ssr-develop-static-entry.js b/packages/gatsby/cache-dir/ssr-develop-static-entry.js index f35cb8a3db0c8..772854b52d305 100644 --- a/packages/gatsby/cache-dir/ssr-develop-static-entry.js +++ b/packages/gatsby/cache-dir/ssr-develop-static-entry.js @@ -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" @@ -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`) +} + // 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. @@ -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 @@ -229,7 +237,7 @@ export default (pagePath, isClientOnlyPage, callback) => {