-
-
Notifications
You must be signed in to change notification settings - Fork 523
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
Hot reloading / React Refresh no longer works with default settings #2560
Comments
I've create a minimal reproduction at https://github.com/ehaskins/electron-forge-2560-hmr-broken-reproduction. Steps to reproduce repro repository:
Steps to reproduce bug
Expected behavior, and behavior when disabling live reload
|
Thank you for this. You helped me to get hot reloading working again rather than the whole window refreshing. I set plugins: [
[
'@pmmmwh/react-refresh-webpack-plugin',
{
devServer: { hot: true, liveReload: false }, // Required for @pmmmwh/react-refresh-webpack-plugin
// ... |
I'm migrating from pre-beta.58 with react-refresh and ran into this issue. While the proposed solution does work, I still get one full reload after making the first change (after yarn start). From that point forwards, it seems to work flawlessly, even after a hard reload of the browser window. However, I can definitely work with this and am very happy to have this working again! |
For anyone else finding this issue (manifesting as your code editor losing focus after every change) and using the Electron-Typescript-Webpack template on a Linux operating system, another way to implement @chetbox 's nice solution is to do the following steps:
"config": {
"forge": {
"plugins": [
[
"@electron-forge/plugin-webpack",
{
"devServer": { "liveReload": false }, // <- this line is needed; remove this comment
"mainConfig": "./webpack.main.config.js",
"renderer": {
"config": "./webpack.renderer.config.js",
"entryPoints": [
{
"html": "./src/index.html",
"js": "./src/renderer.ts",
"name": "main_window",
"preload": {
"js": "./src/preload.ts"
}
}
]
}
}
]
],
...
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const ReactRefreshWebpackPlugin = require("@pmmmwh/react-refresh-webpack-plugin");
module.exports = [new ForkTsCheckerWebpackPlugin(), new ReactRefreshWebpackPlugin()]; I found this allowed me to change code without my editor's window losing focus and the state of the Electron application was preserved (insofar as a quick |
@MauricePasternak well played! much thanks! I followed steps:
then added your solution: I made a sample just in case ( Branch with hot reload ) |
if I add - "devServer": { "LiveReload": false }, then "preload, main" will stop restarting. |
As of |
Confirming, the mentioned solution works for me too, with webpack and node integration setting. |
Pre-flight checklist
Electron Forge version
6.0.0-beta.61
Electron version
v15.1.0
Operating system
Ubuntu 20.04 x64
Last known working Electron Forge version
6.0.0-beta.54
Expected behavior
In
6.0.0-beta.54
, I had a working setup using react-refresh-webpack-plugin, which is currently the recommended (and least intrusive) way to add HMR to a React app. Using this plugin, React components can be edited and will hot-reload with minimum latency and without losing their state.Actual behavior
I recently created a new electron-forge project, using version
6.0.0-beta.61
. Using the same approach, hot reloading doesn't work. Instead, the entire application will perform a full, hard reload on every change -- in fact, it'll even sometimes reload when editing entirely unrelated files (for example, files that are in the source tree but not part of Webpack's require tree).After pulling my hair out and digging into electron-forge internals trying to understand what was happening, I finally discovered that setting
liveReload
tofalse
in the forge config inpackage.json
fixes the issue:This allows hot reloading to take place without webpack-dev-server forcing a full refresh on every edit. It'll still perform a complete refresh when a hot update doesn't succeed, which is the expected behaviour.
I've set up webpack-dev-server with HMR before and don't recall having to set
liveReload
to false, which maybe points to an issue in electron-forge's internal configuration. What's more, I suspect this is not a React-specific issue and is suboptimal for any framework or setup where a full renderer reload on every change is not desired. It might be worth offering a higher-level configuration option for hot reloading, autodetecting common hot reload scenarios, or even just documenting this setting very clearly.Steps to reproduce
6.0.0-beta.54
, this should not cause a full refresh.6.0.0-beta.61
, webpack-dev-middleware will warn in the Electron console that.webpack/renderer/main_window/index.html
was changed and that it's performing a full reload. (You may need to open the Devtools console settings and click "Preserve log" for the message not to be lost on reload:)Additional information
No response
The text was updated successfully, but these errors were encountered: