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): show @hot-loader installation prompt #26927

Closed
wants to merge 21 commits into from

Conversation

wardpeet
Copy link
Contributor

@wardpeet wardpeet commented Sep 16, 2020

Description

We have a long-standing issue that complains about an HMR warning #11934. It can be resolved by adding @hot-loader/react-dom as an alias to react-dom. It's hard to know that you have to do it.

This PR adds a warning to the cli output so people can install it. We auto-add the webpack aliases. I've also added a section to common errors to clarify this a little bit better.

image

Documentation

I've added a section to common errors to point people towards.

Related Issues

Fixes #11934

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Sep 16, 2020
@wardpeet wardpeet added status: needs core review Currently awaiting review from Core team member status: needs docs review Pull request related to documentation waiting for review and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Sep 18, 2020
Copy link
Contributor

@meganesu meganesu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey Ward! Took a look at the docs part of this, and left a few suggestions.

One broader suggestion: it might help clarify things to split out the example stuff (lines 272-280) under its own header. That way, people don't accidentally just copy the npm install line and all end up with the same version. Let me know what you think!

docs/docs/troubleshooting-common-errors.md Outdated Show resolved Hide resolved
docs/docs/troubleshooting-common-errors.md Outdated Show resolved Hide resolved
docs/docs/troubleshooting-common-errors.md Outdated Show resolved Hide resolved
docs/docs/troubleshooting-common-errors.md Outdated Show resolved Hide resolved
@meganesu meganesu added type: documentation An issue or pull request for improving or updating Gatsby's documentation and removed status: needs docs review Pull request related to documentation waiting for review labels Sep 18, 2020
meganesu
meganesu previously approved these changes Sep 21, 2020
Copy link
Contributor

@meganesu meganesu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! ✨

Copy link
Contributor

@pvdz pvdz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not seeing anything that sticks out but perhaps somebody with better insights into hmr should accept.

docs/docs/troubleshooting-common-errors.md Outdated Show resolved Hide resolved
packages/gatsby/src/utils/webpack.config.js Outdated Show resolved Hide resolved
@wardpeet wardpeet added the bot: merge on green Gatsbot will merge these PRs automatically when all tests passes label Sep 25, 2020
const { version: reactDomVersion } = require(`react-dom/package.json`)
const { major, minor } = semver.parse(reactDomVersion)
console.warn(
`React-Hot-Loader: please install "@hot-loader/react-dom@${major}.${minor}" to make sure all features of React are working.`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

patch part doesn't need to match?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not available for every patch version of react so that's the reason why I didn't do it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What will happen when there is version mismatch between react and @hot-loader/react-dom (given that patch is not available for everything, I guess we could limit question to different minor versions)?

I guess the behaviour itself is undefined - but would users see any warnings about this (that's going from the messaging here that major and minor should be the same for those 2 packages)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added an extra warning to the code, in my tests if your version is higher I haven't found any immediate issue but of course, there are probably some subtle changes.

resolve.alias[`react-dom/server$`] = require.resolve(`react-dom/server`)
resolve.alias[`react-dom`] = require.resolve(`@hot-loader/react-dom`)
} catch (err) {
const { version: reactDomVersion } = require(`react-dom/package.json`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hot-loader/react-dom has versions starting from 16.7.0. Technically we support ^16.4.2 so the warning is not actionable for users on react versions between those 2 - worth silencing the warning if version is below 16.7? There are no hooks there anyway (assuming this is only needed for hooks support)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll do 16.8.0 because that's when hooks are a thing and you'll only need it for hooks.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know specific details but React 16.6+ features may not work. from the error/warning message implies it's not just hooks? (or maybe message is just not updated - not sure if I remember correctly but hooks were expected to land in 16.7 but didn't)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improved semver checks. These are all the patches that they have needed to do https://github.com/gaearon/react-hot-loader/blob/master/src/webpack/patch.js

@wardpeet wardpeet closed this Feb 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bot: merge on green Gatsbot will merge these PRs automatically when all tests passes status: needs core review Currently awaiting review from Core team member type: documentation An issue or pull request for improving or updating Gatsby's documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

React-Hot-Loader: react-🔥-dom patch is not detected. React 16.6+ features may not work.
5 participants