fix(playground): 修复历史恢复后加载 DSL 时缺少页面基线记录

初始 set root 时标记各页面历史栈为已保存,并用 dsl.id 恢复 IndexedDB 历史,避免 restore 后再赋值时走 diff 分支导致无 initial 基线。
This commit is contained in:
roymondchen 2026-06-15 20:43:53 +08:00
parent ffcc734102
commit 4a8289137b

View File

@ -51,10 +51,11 @@ import { computed, onBeforeUnmount, onMounted, ref, shallowRef, toRaw } from 'vu
import { debounce } from 'lodash-es';
import type { MApp, MContainer, MNode } from '@tmagic/core';
import type { DatasourceTypeOption } from '@tmagic/editor';
import type { DatasourceTypeOption, HistoryOpSource, StoreState } from '@tmagic/editor';
import {
editorService,
historyService,
markStackSaved,
propsService,
serializeConfig,
TMagicDialog,
@ -148,16 +149,29 @@ const persistHistory = () => {
// /
const schedulePersist = debounce(persistHistory, 500);
// IndexedDB root DSL id
// app select(defaultSelected) changePage
// IndexedDB root value restore
// DSL id app
// select(defaultSelected) changePage
const restoreHistory = async () => {
try {
await historyService.restoreFromIndexedDB({ appId: value.value?.id });
await historyService.restoreFromIndexedDB({ appId: dsl.id });
} catch (error) {
console.error('恢复历史记录失败', error);
}
};
const rootChangeHandler = (
_v: StoreState['root'],
_pV?: StoreState['root'],
{ historySource }: { historySource?: HistoryOpSource } = {},
) => {
if (historySource === 'initial') {
Object.values(historyService.state.pageSteps).forEach(markStackSaved);
}
};
editorService.on('root-change', rootChangeHandler);
onMounted(async () => {
await restoreHistory();
value.value = dsl;
@ -177,6 +191,7 @@ onBeforeUnmount(() => {
window.removeEventListener('beforeunload', persistHistory);
window.removeEventListener('pagehide', persistHistory);
editorService.removeAllPlugins();
editorService.off('root-change', rootChangeHandler);
});
const propsSubmitErrorHandler = async (e: any) => {