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

vue-router causes white screen and hot restart failure | 白屏、热重启失败. #220

Open
jsxiaosi opened this issue Mar 12, 2024 · 2 comments
Labels
good first issue Good for newcomers

Comments

@jsxiaosi
Copy link

jsxiaosi commented Mar 12, 2024

我在示例项目electron-vite-vue中添加[email protected]后会,每次修改热更新主线程文件时会停止运行并保留旧的实例

复现代码:
src/route/index.ts

import { createRouter, createWebHistory } from 'vue-router';
import type { App } from 'vue';

export const router = createRouter({
  history: createWebHistory(''),
  routes: [],
});

export const configMainRouter = async (app: App<Element>) => {
  app.use(router);
  await router.isReady();
};

src/main.ts

import { router } from './router'

createApp(App)
  .use(router)
  .mount('#app')
  .$nextTick(() => {
    postMessage({ payload: 'removeLoading' }, '*')
  })

复现demo

@jsxiaosi jsxiaosi changed the title 热更新修改主线程文件会重复启动窗口 热更新修改主线程文件停止运行并保留旧实例 Mar 12, 2024
@jsxiaosi

This comment was marked as outdated.

@ntdiary
Copy link

ntdiary commented Mar 15, 2024

window.addEventListener("beforeunload", () => {});

如果在 window 上监听了 beforeunload 事件,自动重启时,旧实例会退出失败。vue-router 里就是监听了这个事件
暂时没空去找根本原因,就先用临时办法绕过了

// electron/main/index.ts
app.on('before-quit', () => {
  if (import.meta.env.DEV) {
    app.exit();
  }
})

@caoxiemeihao caoxiemeihao changed the title 热更新修改主线程文件停止运行并保留旧实例 vue-router causes white screen and hot restart failure | 白屏、热重启失败. Mar 19, 2024
@caoxiemeihao caoxiemeihao added the good first issue Good for newcomers label Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants