diff --git a/src/App.vue b/src/App.vue index efe6df4112..5ba4789edc 100644 --- a/src/App.vue +++ b/src/App.vue @@ -37,6 +37,7 @@ import LeftSidebar from './components/LeftSidebar/LeftSidebar.vue' import RightSidebar from './components/RightSidebar/RightSidebar.vue' import DefaultPageError from './views/DefaultPageError.vue' +import { initialActionCode, ACTION_CODES } from './helpers/ActionMapping' import LogoLibreSign from '../img/logo-gray.svg' const route = useRoute() @@ -44,7 +45,7 @@ const loading = ref(false) const isRoot = computed(() => route.path === '/') const isSignExternalPage = computed(() => route.path.startsWith('/p/')) -const isDoNothingError = computed(() => (route.params?.action as number | undefined) === 2000) +const isDoNothingError = computed(() => initialActionCode.value === ACTION_CODES.DO_NOTHING) const showLeftSidebar = computed(() => !route.matched.some(record => record.meta?.hideLeftSidebar === true)) diff --git a/src/helpers/ActionMapping.ts b/src/helpers/ActionMapping.ts index 14e7154da0..5257a04aa2 100644 --- a/src/helpers/ActionMapping.ts +++ b/src/helpers/ActionMapping.ts @@ -3,6 +3,8 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ +import { ref } from '@vue/reactivity' + interface ActionCodes { REDIRECT: number CREATE_ACCOUNT: number @@ -53,6 +55,14 @@ export const ACTION_CODE_TO_ROUTE: Readonly = Object.freeze({ [ACTION_CODES.INCOMPLETE_SETUP]: 'Incomplete', }) +/** + * Shared reactive ref for the initial action code injected by the server + * (#initial-state-libresign-action). Written once by router.ts beforeEach, + * read by App.vue. Lives here (not in router.ts) to avoid App.vue triggering + * the router module's side effects (createRouter, generateUrl) on import. + */ +export const initialActionCode = ref(0) + export const REQUIREMENT_TO_MODAL: Readonly = Object.freeze({ identificationDocuments: 'uploadDocuments', emailCode: 'emailToken', diff --git a/src/router/router.ts b/src/router/router.ts index 93868bb297..26344bfa7a 100644 --- a/src/router/router.ts +++ b/src/router/router.ts @@ -8,6 +8,7 @@ import { createRouter, createWebHistory, type Router, type RouteRecordRaw } from import { loadState } from '@nextcloud/initial-state' import { getRootUrl, generateUrl } from '@nextcloud/router' +import { initialActionCode } from '../helpers/ActionMapping' import { isExternal } from '../helpers/isExternal' import { selectAction } from '../helpers/SelectAction' @@ -212,7 +213,7 @@ router.beforeEach((to, from, next) => { let action if (actionElement) { const actionValue = loadState('libresign', 'action', 0) - to.params.action = String(actionValue) + initialActionCode.value = actionValue action = selectAction(actionValue, to, from) document.querySelector('#initial-state-libresign-action')?.remove() } diff --git a/src/tests/App.spec.ts b/src/tests/App.spec.ts index e24df2e259..afa9e28b37 100644 --- a/src/tests/App.spec.ts +++ b/src/tests/App.spec.ts @@ -6,6 +6,8 @@ import { beforeEach, describe, expect, it, vi } from 'vitest' import { mount } from '@vue/test-utils' +import { initialActionCode, ACTION_CODES } from '../helpers/ActionMapping' + type RouteState = { path: string name: string | undefined @@ -56,6 +58,7 @@ describe('App', () => { routeState.name = 'fileslist' routeState.params = {} routeState.matched = [] + initialActionCode.value = 0 }) it('shows left sidebar on regular internal routes', () => { @@ -182,8 +185,8 @@ describe('App', () => { expect(wrapper.find('.nc-content').classes()).not.toContain('sign-external-page') }) - it('shows DefaultPageError when action param is 2000', () => { - routeState.params = { action: 2000 } + it('shows DefaultPageError when initial action code is DO_NOTHING (2000)', () => { + initialActionCode.value = ACTION_CODES.DO_NOTHING const wrapper = mount(App, { global: { @@ -203,8 +206,6 @@ describe('App', () => { }) it('does not show DefaultPageError on normal routes', () => { - routeState.params = {} - const wrapper = mount(App, { global: { stubs: {