瀏覽代碼

chore: achieve v1.6-stable by resolving Vite 6 HMR crashes and devtools-api conflicts

unknown 2 月之前
父節點
當前提交
8f7c15996a
共有 8 個文件被更改,包括 248 次插入543 次删除
  1. 14 0
      index.html
  2. 221 527
      package-lock.json
  3. 6 5
      package.json
  4. 0 1
      src/App.vue
  5. 1 0
      src/i18n.ts
  6. 3 0
      src/main.ts
  7. 0 10
      src/router/index.ts
  8. 3 0
      vite.config.ts

+ 14 - 0
index.html

@@ -2,6 +2,20 @@
 <html lang="en">
   <head>
     <meta charset="UTF-8" />
+    <script>
+      (function() {
+        const noop = () => {};
+        const mockHook = {
+          on: noop, off: noop, emit: noop, set: noop,
+          apps: [], _buffer: [], cleanupBuffer: noop,
+          getInstanceDetails: noop, getComponentDetails: noop,
+          getAppRecord: noop, getApps: () => []
+        };
+        if (!window.__VUE_DEVTOOLS_GLOBAL_HOOK__ || !window.__VUE_DEVTOOLS_GLOBAL_HOOK__.on) {
+          window.__VUE_DEVTOOLS_GLOBAL_HOOK__ = mockHook;
+        }
+      })();
+    </script>
     <link rel="icon" type="image/png" href="/favicon.png" />
     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
     

File diff suppressed because it is too large
+ 221 - 527
package-lock.json


+ 6 - 5
package.json

@@ -6,10 +6,10 @@
   "scripts": {
     "dev": "npm run i18n:generate && vite",
     "build": "npm run i18n:generate && npm run sitemap:generate && vue-tsc && vite build",
-    "i18n:generate": "node -e \"const cp=require('child_process'),fs=require('fs'); let p='python'; if(fs.existsSync('backend/venv/Scripts/python.exe')) p='backend\\\\venv\\\\Scripts\\\\python.exe'; else if(fs.existsSync('backend/venv/bin/python3')) p='backend/venv/bin/python3'; else if(fs.existsSync('backend/venv/bin/python')) p='backend/venv/bin/python'; cp.execSync(p+' scripts/manage_locales.py split', {stdio:'inherit'})\"",
-    "sitemap:generate": "node -e \"const cp=require('child_process'),fs=require('fs'); let p='python'; if(fs.existsSync('backend/venv/Scripts/python.exe')) p='backend\\\\venv\\\\Scripts\\\\python.exe'; else if(fs.existsSync('backend/venv/bin/python3')) p='backend/venv/bin/python3'; else if(fs.existsSync('backend/venv/bin/python')) p='backend/venv/bin/python'; cp.execSync(p+' scripts/generate_sitemap.py', {stdio:'inherit'})\"",
-    "i18n:merge": "node -e \"const cp=require('child_process'),fs=require('fs'); let p='python'; if(fs.existsSync('backend/venv/Scripts/python.exe')) p='backend\\\\venv\\\\Scripts\\\\python.exe'; else if(fs.existsSync('backend/venv/bin/python3')) p='backend/venv/bin/python3'; else if(fs.existsSync('backend/venv/bin/python')) p='backend/venv/bin/python'; cp.execSync(p+' scripts/manage_locales.py merge', {stdio:'inherit'})\"",
-    "i18n:check": "node -e \"const cp=require('child_process'),fs=require('fs'); let p='python'; if(fs.existsSync('backend/venv/Scripts/python.exe')) p='backend\\\\venv\\\\Scripts\\\\python.exe'; else if(fs.existsSync('backend/venv/bin/python3')) p='backend/venv/bin/python3'; else if(fs.existsSync('backend/venv/bin/python')) p='backend/venv/bin/python'; cp.execSync(p+' scripts/manage_locales.py missing', {stdio:'inherit'})\"",
+    "i18n:generate": "node -e \"const cp=require('child_process'),fs=require('fs'); let p='python'; if(fs.existsSync('backend/venv/Scripts/python.exe')) p='backend\\\\venv\\\\Scripts\\python.exe'; else if(fs.existsSync('backend/venv/bin/python3')) p='backend/venv/bin/python3'; else if(fs.existsSync('backend/venv/bin/python')) p='backend/venv/bin/python'; cp.execSync(p+' scripts/manage_locales.py split', {stdio:'inherit'})\"",
+    "sitemap:generate": "node -e \"const cp=require('child_process'),fs=require('fs'); let p='python'; if(fs.existsSync('backend/venv/Scripts/python.exe')) p='backend\\\\venv\\\\Scripts\\python.exe'; else if(fs.existsSync('backend/venv/bin/python3')) p='backend/venv/bin/python3'; else if(fs.existsSync('backend/venv/bin/python')) p='backend/venv/bin/python'; cp.execSync(p+' scripts/generate_sitemap.py', {stdio:'inherit'})\"",
+    "i18n:merge": "node -e \"const cp=require('child_process'),fs=require('fs'); let p='python'; if(fs.existsSync('backend/venv/Scripts/python.exe')) p='backend\\\\venv\\\\Scripts\\python.exe'; else if(fs.existsSync('backend/venv/bin/python3')) p='backend/venv/bin/python3'; else if(fs.existsSync('backend/venv/bin/python')) p='backend/venv/bin/python'; cp.execSync(p+' scripts/manage_locales.py merge', {stdio:'inherit'})\"",
+    "i18n:check": "node -e \"const cp=require('child_process'),fs=require('fs'); let p='python'; if(fs.existsSync('backend/venv/Scripts/python.exe')) p='backend\\\\venv\\\\Scripts\\python.exe'; else if(fs.existsSync('backend/venv/bin/python3')) p='backend/venv/bin/python3'; else if(fs.existsSync('backend/venv/bin/python')) p='backend/venv/bin/python'; cp.execSync(p+' scripts/manage_locales.py missing', {stdio:'inherit'})\"",
     "lint": "eslint . --ext ts,vue --report-unused-disable-directives --max-warnings 0",
     "preview": "vite preview",
     "test": "vitest run"
@@ -55,6 +55,7 @@
     "braces": "3.0.3",
     "micromatch": "4.0.8",
     "http-proxy-middleware": "3.0.5",
-    "html-minifier": "npm:html-minifier-terser@^7.2.0"
+    "html-minifier": "npm:html-minifier-terser@^7.2.0",
+    "@vue/devtools-api": "8.1.1"
   }
 }

+ 0 - 1
src/App.vue

@@ -27,7 +27,6 @@ const route = useRoute();
 
 const canonicalUrl = computed(() => {
   const domain = 'https://radionica3d.me';
-  // Remove trailing slash except for root
   const path = route.path === '/' ? '/' : route.path.replace(/\/$/, '');
   return `${domain}${path}`;
 });

+ 1 - 0
src/i18n.ts

@@ -10,6 +10,7 @@ const i18n = createI18n({
   legacy: false,
   locale: savedLocale,
   fallbackLocale: 'en',
+  enableDevtools: false,
   messages: {
     en,
     me,

+ 3 - 0
src/main.ts

@@ -8,10 +8,12 @@ import i18n from "./i18n";
 import "./index.css";
 
 // Handle dynamic import failures (assets deleted after deploy)
+/* 
 window.addEventListener('vite:preloadError', () => {
   console.warn('Vite preload error detected, reloading page for fresh assets...');
   window.location.reload();
 });
+*/
 
 const app = createApp(App);
 
@@ -24,6 +26,7 @@ app.use(i18n);
 
 // Wait for router to be ready before mounting and rendering
 router.isReady().then(() => {
+  console.log("🚀 Router ready, mounting app...");
   app.mount("#root");
   
   // Dispatch event for prerendering

+ 0 - 10
src/router/index.ts

@@ -43,7 +43,6 @@ router.beforeEach(async (to) => {
   const { useAuthStore } = await import("@/stores/auth");
   const authStore = useAuthStore();
   
-  // 1. Handle Language Prefix
   let lang = to.params.lang as string;
   const savedLang = localStorage.getItem('locale') || 'en';
   
@@ -51,34 +50,26 @@ router.beforeEach(async (to) => {
     const segments = to.path.split('/').filter(Boolean);
     const firstSegment = segments[0];
     
-    // Check if first segment looks like a language code but isn't supported
     if (firstSegment && firstSegment.length === 2 && !supportedLangs.includes(firstSegment)) {
-      // It's a fake lang like /fr/auth -> redirect to /ru/auth
       const remainingPath = segments.slice(1).join('/');
       return { path: `/${savedLang}/${remainingPath}`, query: to.query, hash: to.hash };
     }
     
-    // Skip redirect during prerendering to allow capturing the root page or specific routes
     if ((window as any).__PRERENDER_INJECTED) {
       return;
     }
     
-    // Simple path like /auth -> /ru/auth
     return { path: `/${savedLang}${to.fullPath}` };
   }
 
-  // 2. Sync i18n
   if (supportedLangs.includes(lang)) {
     if (i18n.global.locale.value !== lang) {
       await setLanguage(lang);
     }
   } else {
-    // This part should technically not be reached with the current regex
-    // but as a safety measure:
     return { path: `/${savedLang}/`, query: to.query };
   }
 
-  // 3. Auth Guards
   const isPrerendering = (window as any).__PRERENDER_INJECTED !== undefined;
   if (!isPrerendering && !authStore.user && localStorage.getItem("token")) {
     await authStore.init();
@@ -95,5 +86,4 @@ router.beforeEach(async (to) => {
   }
 });
 
-
 export default router;

+ 3 - 0
vite.config.ts

@@ -9,6 +9,9 @@ export default defineConfig(({ mode }) => {
   console.log(`🔨 Vite build mode: ${mode}`);
   const outDir = process.env.VITE_OUT_DIR || 'dist';
   return {
+    server: {
+      hmr: false
+    },
     plugins: [
       vue(),
       ...(mode === 'production' ? [

Some files were not shown because too many files changed in this diff