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

Blank screen on hot reload, devtools disconnect, hang on page reload #1257

Closed
rathboma opened this issue Feb 20, 2021 · 12 comments
Closed

Blank screen on hot reload, devtools disconnect, hang on page reload #1257

rathboma opened this issue Feb 20, 2021 · 12 comments

Comments

@rathboma
Copy link
Contributor

rathboma commented Feb 20, 2021

correction
See below.

I see this behavior when hot reload cannot reload the code I've changed and a full reload is triggered by webpack.

Describe the bug

I upgraded to Electron 9 and vue-cli-plugin-electron-builder 2.0 beta 6.

Since then the electron app loads fine initially, then if I make a change and the app hot-reloads the screen is blank and devtools are disconnected.

  • All the js files seem empty at this point

If I force-reload the page the app comes back fine, but Vue devtools hang.

Here's a gif of it happening
broken-devtools

To Reproduce
Check out Beekeeper Studio

  • yarn install
  • yarn run electron:serve
  • change a file
  • witness

Expected behavior

  • Hot reload should work normally

Environment (please complete the following information):
You can see all the config in the Beekeeper repo (listed above), it's pretty standard.

I know this is probably a problem with one of the other tools in the toolchain, but would appreciate some expert input!

@xieerduos
Copy link

xieerduos commented Feb 23, 2021

我也遇到了此问题,~~~~~~

Reload,Fore-Reload 白屏

  "dependencies": {
    "core-js": "^3.6.5",
    "vue": "^3.0.0",
    "vue-router": "^4.0.0-0",
    "vuex": "^4.0.0-0"
  },

解决方案:
createWebHistory(process.env.BASE_URL), 改为 createWebHashHistory(process.env.BASE_URL),

import {createRouter, createWebHashHistory, createWebHistory} from 'vue-router';
const router = createRouter({
    // history: createWebHistory(process.env.BASE_URL),
    history: createWebHashHistory(process.env.BASE_URL),
    routes
});

export default router;

@rathboma
Copy link
Contributor Author

Thanks for the idea!

unfortunately it's not a router problem - I'm not using the router!

So actually hot reload DOES work fine.

On further investigation, the issue happens when a full reload is forced, when there's a change to a library it can't hot reload.

In Electron 8, this worked fine, we recently upgraded to Electron 9 due to security fixes and it started happening.

We also upgraded to beta6 of the cli plugin if that is related.

@nklayman hoping to get your thoughts.

@nklayman
Copy link
Owner

The plugin version shouldn't have anything to do with it as the logic related to this hasn't changed in a long time. I cloned the repo and spent some time investigating it but I couldn't figure out what the issue is. I googled around and couldn't find anything related either. You could try upgrading to vue cli v5 alpha which uses webpack v5, that might fix it. Other than that, I don't know of any solutions.

@rathboma
Copy link
Contributor Author

Thanks for checking, you rock.

I'll poke around. I'm not sure why upgrading electron and the plug-in would cause this either. It smells like a transitive dependency issue.

I'll report back here if I figure it out.

@rathboma
Copy link
Contributor Author

rathboma commented Feb 25, 2021

So I did a bit of experimentation -- this problem starts when moving from Electron 8.x to >= 9.x.

I know they changed the extension model so that they can't load from a file url, but that's not the problem here, but it's likely related to those changes. Could be webpack HMR setting window.location causing a problem or something like that

I'll see if I can replicate it on a fresh project

@erickximenes
Copy link

To fix this, you may have to disable Vue Devtools by removing the following lines from your src/background.(js|ts) file:

if (isDevelopment && !process.env.IS_TEST) {
  // Install Vue Devtools
  await installExtension(VUEJS_DEVTOOLS)
}

In src/router.(js|ts) change:

Vue2:

if (isDevelopment && !process.env.IS_TEST) {
  await installExtension(VUEJS_DEVTOOLS)
}

Vue 3:

const router = createRouter({
history: process.env.IS_ELECTRON ? createWebHashHistory() : createWebHistory(),
})

@nklayman
Copy link
Owner

nklayman commented Mar 9, 2021

Okay, I managed to reproduce the issue on a smaller app and found what caused it: native modules. If the code imports a native module somewhere, a HMR full reload will cause the page to go blank and devtools to disconnect. I have no idea what causes this, however.

@rathboma
Copy link
Contributor Author

rathboma commented Mar 9, 2021

Thanks for digging in!

I guess I'll file this with electron? Is that the right place in the stack if you had to take a guess?

@nklayman
Copy link
Owner

nklayman commented Mar 9, 2021

If this only started happening after upgrading electron, then it is most definitely electron's fault. When opening the issue, I'd suggest providing a simple app that just imports a native module and nothing else so that they can debug it better. Thanks!

(Closing this since I don't think I can really do anything about it)

@nklayman nklayman closed this as completed Mar 9, 2021
@rathboma
Copy link
Contributor Author

Do you have the source code of the test app you used?

@rathboma
Copy link
Contributor Author

NM. Here's a simple replication - https://github.com/rathboma/electron-hotreload-example

@rathboma
Copy link
Contributor Author

FYI - I fixed this by moving from node-sqlite3 to better-sqlite3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants