This commit is contained in:
syuilo
2025-03-10 15:14:21 +09:00
parent 9e91f85370
commit f1014bc7f7
4 changed files with 36 additions and 20 deletions

View File

@@ -4,22 +4,18 @@ SPDX-License-Identifier: AGPL-3.0-only
--> -->
<template> <template>
<KeepAlive <Suspense :timeout="0">
:max="prefer.s.numberOfPageCache" <component :is="currentPageComponent" :key="key" v-bind="Object.fromEntries(currentPageProps)"/>
:exclude="pageCacheController"
>
<Suspense :timeout="0">
<component :is="currentPageComponent" :key="key" v-bind="Object.fromEntries(currentPageProps)"/>
<template #fallback> <template #fallback>
<MkLoading/> <MkLoading/>
</template> </template>
</Suspense> </Suspense>
</KeepAlive>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { inject, onBeforeUnmount, provide, ref, shallowRef, computed, nextTick } from 'vue'; import { inject, onBeforeUnmount, provide, ref, shallowRef, computed, nextTick } from 'vue';
import { v4 as uuid } from 'uuid';
import type { IRouter, Resolved, RouteDef } from '@/nirax.js'; import type { IRouter, Resolved, RouteDef } from '@/nirax.js';
import { prefer } from '@/preferences.js'; import { prefer } from '@/preferences.js';
import { globalEvents } from '@/events.js'; import { globalEvents } from '@/events.js';
@@ -40,6 +36,11 @@ if (router == null) {
const currentDepth = inject(DI.routerCurrentDepth, 0); const currentDepth = inject(DI.routerCurrentDepth, 0);
provide(DI.routerCurrentDepth, currentDepth + 1); provide(DI.routerCurrentDepth, currentDepth + 1);
provide(DI.viewId, uuid());
const viewTransitionId = ref(uuid());
provide(DI.viewTransitionId, viewTransitionId);
function resolveNested(current: Resolved, d = 0): Resolved | null { function resolveNested(current: Resolved, d = 0): Resolved | null {
if (!props.nested) return current; if (!props.nested) return current;
@@ -59,18 +60,29 @@ const currentPageComponent = shallowRef('component' in current.route ? current.r
const currentPageProps = ref(current.props); const currentPageProps = ref(current.props);
const key = ref(router.getCurrentKey() + JSON.stringify(Object.fromEntries(current.props))); const key = ref(router.getCurrentKey() + JSON.stringify(Object.fromEntries(current.props)));
function onChange({ resolved, key: newKey }) { async function onChange({ resolved, key: newKey }) {
const current = resolveNested(resolved); const current = resolveNested(resolved);
if (current == null || 'redirect' in current.route) return; if (current == null || 'redirect' in current.route) return;
currentPageComponent.value = current.route.component;
currentPageProps.value = current.props;
key.value = newKey + JSON.stringify(Object.fromEntries(current.props));
viewTransitionId.value = uuid();
await new Promise(resolve => setTimeout(resolve, 100));
nextTick(() => { nextTick(() => {
// ページ遷移完了後に再びキャッシュを有効化 console.log('onChange', viewTransitionId.value);
if (clearCacheRequested.value) { document.startViewTransition(() => new Promise((res) => {
clearCacheRequested.value = false; currentPageComponent.value = current.route.component;
} currentPageProps.value = current.props;
key.value = newKey + JSON.stringify(Object.fromEntries(current.props));
nextTick(async () => {
res();
//setTimeout(res, 1000);
// ページ遷移完了後に再びキャッシュを有効化
if (clearCacheRequested.value) {
clearCacheRequested.value = false;
}
});
}));
}); });
} }

View File

@@ -9,4 +9,6 @@ import type { IRouter } from '@/nirax.js';
export const DI = { export const DI = {
routerCurrentDepth: Symbol() as InjectionKey<number>, routerCurrentDepth: Symbol() as InjectionKey<number>,
router: Symbol() as InjectionKey<IRouter>, router: Symbol() as InjectionKey<IRouter>,
viewId: Symbol() as InjectionKey<string>,
viewTransitionId: Symbol() as InjectionKey<Ref<string>>,
}; };

View File

@@ -9,6 +9,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkSpacer :contentMax="800"> <MkSpacer :contentMax="800">
<MkHorizontalSwipe v-model:tab="tab" :tabs="headerTabs"> <MkHorizontalSwipe v-model:tab="tab" :tabs="headerTabs">
<div v-if="tab === 'all'" key="all"> <div v-if="tab === 'all'" key="all">
<div style="view-transition-name: a; padding: 64px;">BBBBBBBBB</div>
<XNotifications :class="$style.notifications" :excludeTypes="excludeTypes"/> <XNotifications :class="$style.notifications" :excludeTypes="excludeTypes"/>
</div> </div>
<div v-else-if="tab === 'mentions'" key="mention"> <div v-else-if="tab === 'mentions'" key="mention">
@@ -24,13 +25,13 @@ SPDX-License-Identifier: AGPL-3.0-only
<script lang="ts" setup> <script lang="ts" setup>
import { computed, ref } from 'vue'; import { computed, ref } from 'vue';
import { notificationTypes } from '@@/js/const.js';
import XNotifications from '@/components/MkNotifications.vue'; import XNotifications from '@/components/MkNotifications.vue';
import MkNotes from '@/components/MkNotes.vue'; import MkNotes from '@/components/MkNotes.vue';
import MkHorizontalSwipe from '@/components/MkHorizontalSwipe.vue'; import MkHorizontalSwipe from '@/components/MkHorizontalSwipe.vue';
import * as os from '@/os.js'; import * as os from '@/os.js';
import { i18n } from '@/i18n.js'; import { i18n } from '@/i18n.js';
import { definePage } from '@/page.js'; import { definePage } from '@/page.js';
import { notificationTypes } from '@@/js/const.js';
const tab = ref('all'); const tab = ref('all');
const includeTypes = ref<string[] | null>(null); const includeTypes = ref<string[] | null>(null);

View File

@@ -9,6 +9,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkSpacer :contentMax="800"> <MkSpacer :contentMax="800">
<MkHorizontalSwipe v-model:tab="src" :tabs="$i ? headerTabs : headerTabsWhenNotLogin"> <MkHorizontalSwipe v-model:tab="src" :tabs="$i ? headerTabs : headerTabsWhenNotLogin">
<div :key="src" ref="rootEl"> <div :key="src" ref="rootEl">
<div style="view-transition-name: a;">AAAAAAAAAA</div>
<MkInfo v-if="isBasicTimeline(src) && !store.r.timelineTutorials.value[src]" style="margin-bottom: var(--MI-margin);" closable @close="closeTutorial()"> <MkInfo v-if="isBasicTimeline(src) && !store.r.timelineTutorials.value[src]" style="margin-bottom: var(--MI-margin);" closable @close="closeTutorial()">
{{ i18n.ts._timelineDescription[src] }} {{ i18n.ts._timelineDescription[src] }}
</MkInfo> </MkInfo>