mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2026-06-29 18:52:05 +00:00
fix(playground): 调整初始化时序避免历史恢复被覆盖
将本地 magicDSL 的恢复逻辑移动到 restoreHistory 之后,避免页面初始化时覆盖已恢复的历史状态。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
1ade61d62e
commit
bfdaf2b244
@ -105,19 +105,6 @@ const save = () => {
|
||||
|
||||
const { menu, deviceGroup, iframe, previewVisible } = useEditorMenu(value, save);
|
||||
|
||||
try {
|
||||
// eslint-disable-next-line no-eval
|
||||
const magicDSL = eval(`(${localStorage.getItem('magicDSL')})`);
|
||||
if (!magicDSL) {
|
||||
save();
|
||||
} else {
|
||||
value.value = magicDSL;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
save();
|
||||
}
|
||||
|
||||
editorService.usePlugin({
|
||||
beforeDoAdd: (config: MNode, parent: MContainer) => {
|
||||
if (config.type === 'overlay') {
|
||||
@ -174,7 +161,20 @@ editorService.on('root-change', rootChangeHandler);
|
||||
|
||||
onMounted(async () => {
|
||||
await restoreHistory();
|
||||
value.value = dsl;
|
||||
try {
|
||||
// eslint-disable-next-line no-eval
|
||||
const magicDSL = eval(`(${localStorage.getItem('magicDSL')})`);
|
||||
if (!magicDSL) {
|
||||
value.value = dsl;
|
||||
save();
|
||||
} else {
|
||||
value.value = magicDSL;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
save();
|
||||
}
|
||||
|
||||
historyService.on('change', schedulePersist);
|
||||
historyService.on('code-block-history-change', schedulePersist);
|
||||
historyService.on('data-source-history-change', schedulePersist);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user