-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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): Support FastRefresh for development hot reloading #21534
Conversation
Can we detect the react version in our webpack config and adjust there? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh this looks awesome! 🎉 I wonder if it would be beneficial to move js process.env.HOT_LOADER !== `fast-refresh`
into a utils functions called isFastRefreshEnabled
or something.
Can we detect the react version in our webpack config and adjust there?
@KyleAMathews I think we want to run it as an experiment first as it's still considered experimental in the webpack ecosystem.
Also this is not only about whether user have 16.10+ react version (so if it will work at all) - |
@pieh I think It is a really good point though. So good call out. I was going to change this to use fast refresh if react is 16.10+. But now i'm questioning that decision. |
@wardpeet it's not considered experimental, it just doesn't have a champion owning it's adoption. It's already built into react native, and facebook uses it internally with haste. And the react-hot-loader repo has this line:
|
Agree about misnomer - it's not technically breaking change. But still if my workflow would "rely" on current behaviour (iterate on code relying on current hot reload behaviour) and we change that behaviour for every user - my workflow is now broken. Was the user code structured using best practices for it to happen - no, but it did work. There are very good reason that |
@blainekasten It's still experimental for react web. All loaders (webpack & parcel) are still considered experimental is what I meant. That's also why I think process.env is the right way to go for now. I also agree with Michal |
I don't want to commit to conversation about ways to improve visibility about feature flags just yet - mostly because this (not enabling by default) is my personal view and it doesn't necessarily reflect view of all the people here ;) |
@wardpeet I looked into this. Unfortunately, part of the changes are from So for now we'll just leave the env var littered throughout the codebase.. |
https://github.com/pmmmwh/react-refresh-webpack-plugin/releases/tag/v0.2.0 is released! This is unblocked and should be mergeable |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good to merge after adding in some comments about where things live!
Hey, I am using gatsby in a monorepo (yarn workspaces), and am seeing this error since the update:
Any idea why? |
@adrienharnay I would try force re-installing dependencies ( |
Tried |
Ah yeah, the |
Of course, thanks for the quick answer! |
@blainekasten is there a way to know if |
@sylvesteraswin right now you can check if the environment variable is set. In the future when we don't have that it'll just be the default. Why do you need to know? |
Description
React development is under iteration with the release of the official React FastRefresh hot reloading approach. Platform integration is under way and this allows Gatsby to be configured with fast refresh as the mechanism for hot reloading.
This feature is currently hidden behind an environment variable
GATSBY_HOT_LOADER=fast-refresh
. The reason we have to do this is because we support a wide semver range of React (16.4+). FastRefresh requires 16.10+. So if we were to change this as the default, it would be a breaking feature for those on previous versions.My proposal is to ship this, and when we update the semver range we can remove the old hot-loader mechanism.
I tested this approach with multiple versions and flags:
Documentation
I don't think this will need any documentation changes unless we have some documentation specifically calling out react-hot-loader. Principally, this is an implementation detail change.
Related Issues