fix(frontend): mount the settings modal only once on /platform/settings
The platform shell always renders <Settings /> and opens it when the path is /platform/settings, but the settings route also rendered Settings.vue into the router outlet. Loading that URL mounted two independent modals: both fetched their data, and a change saved in one left the other stale. Keep the route for bookmarks, redirects and the close behaviour, but give it a component that renders nothing.main
parent
22404e92b7
commit
508048aee9
|
|
@ -1,4 +1,5 @@
|
|||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import { defineComponent } from 'vue'
|
||||
import type { RouteLocationNormalized } from 'vue-router'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
import { useDeploymentCapabilitiesStore } from '@/stores/deploymentCapabilities'
|
||||
|
|
@ -12,6 +13,11 @@ import { isToolboxSection, toolboxLocation } from '@/config/toolbox'
|
|||
/** Lite /桌面 WebView 硬刷新时可能只打开 `/`,用 session 记住上次页面以便恢复 */
|
||||
const LITE_LAST_PATH_KEY = 'weknora_lite_last_path'
|
||||
|
||||
// views/platform/index.vue always mounts the settings modal and opens it when
|
||||
// the path is /platform/settings, so this route only has to own the URL.
|
||||
// Rendering Settings.vue here would mount a second, independent copy.
|
||||
const SettingsRouteOutlet = defineComponent({ name: 'SettingsRouteOutlet', render: () => null })
|
||||
|
||||
function isLiteEdition(authStore: ReturnType<typeof useAuthStore>) {
|
||||
return authStore.isLiteMode || localStorage.getItem('weknora_lite_mode') === 'true'
|
||||
}
|
||||
|
|
@ -99,7 +105,7 @@ const router = createRouter({
|
|||
{
|
||||
path: "settings",
|
||||
name: "settings",
|
||||
component: () => import("../views/settings/Settings.vue"),
|
||||
component: SettingsRouteOutlet,
|
||||
meta: { requiresInit: true, requiresAuth: true }
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
import assert from 'node:assert/strict'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import test from 'node:test'
|
||||
|
||||
const router = readFileSync(new URL('./index.ts', import.meta.url), 'utf8')
|
||||
const platformShell = readFileSync(new URL('../views/platform/index.vue', import.meta.url), 'utf8')
|
||||
|
||||
function routeBlock(name) {
|
||||
const at = router.indexOf(`name: "${name}"`)
|
||||
assert.notEqual(at, -1, `route ${name} not found`)
|
||||
return router.slice(router.lastIndexOf('{', at), router.indexOf('}', at) + 1)
|
||||
}
|
||||
|
||||
test('platform shell is the only place that mounts the settings modal', () => {
|
||||
// Two copies each fetch their own data, so a save in one leaves the other stale.
|
||||
assert.equal(platformShell.match(/<Settings\s*\/>/g)?.length, 1)
|
||||
assert.doesNotMatch(router, /views\/settings\/Settings\.vue/)
|
||||
})
|
||||
|
||||
test('/platform/settings keeps a route but renders nothing into the outlet', () => {
|
||||
const block = routeBlock('settings')
|
||||
assert.match(block, /path: "settings"/)
|
||||
assert.match(block, /component: SettingsRouteOutlet/)
|
||||
assert.match(router, /const SettingsRouteOutlet = defineComponent\(\{[^}]*render: \(\) => null/)
|
||||
})
|
||||
Loading…
Reference in New Issue