Skip to content

Commit

Permalink
Upgrade react-hot-loader to 4.6 (gatsbyjs#10455)
Browse files Browse the repository at this point in the history
Fixes gatsbyjs#9489 

~~The docs also [recommend](https://github.com/gaearon/react-hot-loader#react--dom) (but don't require) using a patched `react-dom`, but as I understand it that would override the user's `react-dom` version we have as a peer dependency so I left it out.~~ ➡️ gatsbyjs@3894f0a

/cc @wKovacs64
  • Loading branch information
jgierer12 authored and gpetrioli committed Jan 22, 2019
1 parent 294d0af commit ef1de8b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 18 deletions.
12 changes: 2 additions & 10 deletions packages/gatsby/cache-dir/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import React from "react"
import ReactDOM from "react-dom"
import domReady from "domready"
import { hot, setConfig } from "react-hot-loader"

import socketIo from "./socketIo"
import emitter from "./emitter"
Expand All @@ -13,12 +12,6 @@ import pages from "./pages.json"
window.___emitter = emitter
setApiRunnerForLoader(apiRunner)

// necessary for hot-reloading of react hooks
setConfig({
ignoreSFC: true,
pureRender: true,
})

// Let the site/plugins run code very early.
apiRunnerAsync(`onClientEntry`).then(() => {
// Hook up the client to socket.io on server
Expand Down Expand Up @@ -57,7 +50,8 @@ apiRunnerAsync(`onClientEntry`).then(() => {
loader.addDevRequires(syncRequires)

loader.getResourcesForPathname(window.location.pathname).then(() => {
let Root = hot(module)(preferDefault(require(`./root`)))
const preferDefault = m => (m && m.default) || m
let Root = preferDefault(require(`./root`))
domReady(() => {
renderer(<Root />, rootElement, () => {
apiRunner(`onInitialClientRender`)
Expand All @@ -66,8 +60,6 @@ apiRunnerAsync(`onClientEntry`).then(() => {
})
})

const preferDefault = m => (m && m.default) || m

function supportsServiceWorkers(location, navigator) {
if (location.hostname === `localhost` || location.protocol === `https:`) {
return `serviceWorker` in navigator
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby/cache-dir/root.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { createElement } from "react"
import { Router } from "@reach/router"
import { ScrollContext } from "gatsby-react-router-scroll"

import {
shouldUpdateScroll,
init as navigationInit,
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"raw-loader": "^0.5.1",
"react-dev-utils": "^4.2.1",
"react-error-overlay": "^3.0.0",
"react-hot-loader": "^4.5.1",
"react-hot-loader": "^4.6.0",
"redux": "^4.0.0",
"relay-compiler": "1.5.0",
"request": "^2.85.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,17 @@ const writePages = async () => {
components = _.uniqBy(components, c => c.componentChunkName)

// Create file with sync requires of components/json files.
let syncRequires = `// prefer default export if available
let syncRequires = `const { hot } = require("react-hot-loader/root")
// prefer default export if available
const preferDefault = m => m && m.default || m
\n\n`
syncRequires += `exports.components = {\n${components
.map(
c =>
` "${c.componentChunkName}": preferDefault(require("${joinPath(
` "${c.componentChunkName}": hot(preferDefault(require("${joinPath(
c.component
)}"))`
)}")))`
)
.join(`,\n`)}
}\n\n`
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -15641,10 +15641,10 @@ react-error-overlay@^3.0.0:
resolved "https://registry.yarnpkg.com/react-error-overlay/-/react-error-overlay-3.0.0.tgz#c2bc8f4d91f1375b3dad6d75265d51cd5eeaf655"
integrity sha512-XzgvowFrwDo6TWcpJ/WTiarb9UI6lhA4PMzS7n1joK3sHfBBBOQHUc0U4u57D6DWO9vHv6lVSWx2Q/Ymfyv4hw==

react-hot-loader@^4.5.1:
version "4.5.1"
resolved "https://registry.yarnpkg.com/react-hot-loader/-/react-hot-loader-4.5.1.tgz#4a9cf136542b1db4f948ac74b31fa16a411ceebb"
integrity sha512-aqw8F0ZTCakfTXTj1n3F9vXfEKWWHEpQ3Mq9YmYvrNdHvey5RfkSGv7rz4r9TXjqVLt2mpItqydJQdhboZ/acQ==
react-hot-loader@4.6:
version "4.6.0"
resolved "https://registry.yarnpkg.com/react-hot-loader/-/react-hot-loader-4.6.0.tgz#7a556efea51a3c79e8bffdb094fbe17883a79432"
integrity sha512-ytmtbJB0RlTUqa9HnpVsoZiZ6iRsTzu+O2WovKT++f+tDYOTNZYa7OesVAE+R90e/1w/OJO4G/tw4rNSMYCjFw==
dependencies:
fast-levenshtein "^2.0.6"
global "^4.3.0"
Expand Down

0 comments on commit ef1de8b

Please sign in to comment.