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

fix(gatsby-cli): add handling to ensure CLI uses same react instance across the board #21508

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/gatsby-cli/package.json
Expand Up @@ -37,7 +37,7 @@
"pretty-error": "^2.1.1",
"progress": "^2.0.3",
"prompts": "^2.3.0",
"react": "^16.12.0",
"react": "^16.8.0",
"redux": "^4.0.4",
"resolve-cwd": "^2.0.0",
"semver": "^6.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-cli/src/reporter/loggers/ink/cli.js
@@ -1,4 +1,4 @@
import React from "react"
import React from "./react-instance-used-by-ink"
import { Box, Static } from "ink"
import isTTY from "../../../util/is-tty"
import { trackBuildError } from "gatsby-telemetry"
Expand Down
@@ -1,4 +1,8 @@
import React, { useContext, useState, useEffect } from "react"
import React, {
useContext,
useState,
useEffect,
} from "../react-instance-used-by-ink"
import { Box, Color, StdoutContext } from "ink"
import StoreStateContext from "../context"

Expand Down
@@ -1,4 +1,4 @@
import React from "react"
import React from "../react-instance-used-by-ink"
import path from "path"
import { Color, Box } from "ink"
import { get } from "lodash"
Expand Down
@@ -1,4 +1,4 @@
import React from "react"
import React from "../react-instance-used-by-ink"
import { Box } from "ink"
import calcElapsedTime from "../../../../util/calc-elapsed-time"

Expand Down
@@ -1,4 +1,4 @@
import React from "react"
import React from "../react-instance-used-by-ink"
import { Box } from "ink"
import Spinner from "ink-spinner"

Expand Down
6 changes: 5 additions & 1 deletion packages/gatsby-cli/src/reporter/loggers/ink/context.js
@@ -1,4 +1,8 @@
import React, { useState, useEffect, createContext } from "react"
import React, {
useState,
useEffect,
createContext,
} from "./react-instance-used-by-ink"

import { getStore, onLogAction } from "../../redux/index"

Expand Down
2 changes: 1 addition & 1 deletion packages/gatsby-cli/src/reporter/loggers/ink/index.js
@@ -1,4 +1,4 @@
import React, { useContext } from "react"
import React, { useContext } from "./react-instance-used-by-ink"
import { render } from "ink"
import StoreStateContext, { StoreStateProvider } from "./context"

Expand Down
@@ -0,0 +1,16 @@
const { createRequireFromPath } = require(`gatsby-core-utils`)

const inkRequire = createRequireFromPath(`ink`)

/*
Make sure we use same "react" instance as "ink" would use to prevent error:

UNHANDLED REJECTION Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.

This should fix case 3. from that error.
/*/
module.exports = inkRequire(`react`)
1 change: 1 addition & 0 deletions renovate.json
Expand Up @@ -11,6 +11,7 @@
},
"masterIssue": true,
"rebaseStalePrs": false,
"excludePackageNames": ["react", "react-dom"],
"rangeStrategy": "bump",
"bumpVersion": null,
"semanticCommitScope": null,
Expand Down