fix render error after build

This commit is contained in:
codetypes committed 2025-04-22 09:08:34 +08:00
1 parent e21c32e800
commit ef10851e64
3 files changed
+24 -20

No files matched your search

+15 -9
View File
@@ -329,6 +329,20 @@ export const Editor: FC<EditorProps> = ({ onChange, data: editor, ...props }) =>
};
}
const refreshGraph = async () => {
if (graph.hasSubtreeUpdated()) {
await graph.refreshSubtree();
} else {
await graph.refresh();
}
if (editor.focusId) {
graph.focusNode(editor.focusId);
editor.focusId = null;
} else if (graph.selectedId) {
graph.selectNode(graph.selectedId);
}
};
// check should rebuild graph
useEffect(() => {
if (!editorSize || (editorSize.width === 0 && editorSize.height === 0)) {
@@ -341,15 +355,7 @@ export const Editor: FC<EditorProps> = ({ onChange, data: editor, ...props }) =>
if (graph && workspace.editing === editor) {
graph.setSize(editorSize.width, editorSize.height);
graph.refreshSubtree().then(() => {
if (editor.focusId) {
graph.focusNode(editor.focusId);
editor.focusId = null;
} else if (graph.selectedId) {
graph.selectNode(graph.selectedId);
}
});
refreshGraph();
}
}, [editorSize, workspace.editing, graph]);
+9 -10
View File
@@ -137,19 +137,21 @@ export class Graph {
const data = JSON.parse(str) as TreeData;
this.editor.declare.import = data.import.map((v) => ({ path: v, vars: [], depends: [] }));
this.editor.declare.vars = data.vars.map((v) => ({ ...v }));
await this._update(data);
await this._update(data, true, true);
// update tree inspector
this.selectNode(null);
this.onChange?.();
}
private async _update(data: TreeData, refreshId: boolean = true) {
private async _update(data: TreeData, refreshId: boolean = true, refreshVars: boolean = false) {
this.editor.data = data;
if (refreshId) {
b3util.refreshNodeData(this.data.root, 1);
}
workspace.refresh(this.editor.path);
if (refreshVars) {
workspace.refresh(this.editor.path);
}
// clear current target avoid hover error
const graph = this._graph as unknown as IGraph;
@@ -909,9 +911,9 @@ export class Graph {
this._storeHistory();
}
private _isSubtreeUpdated(data: NodeData) {
hasSubtreeUpdated() {
let updated = false;
b3util.dfs(data, (node) => {
b3util.dfs(this.data.root, (node) => {
if (node.path && b3util.files[node.path] !== node.mtime) {
updated = true;
}
@@ -920,11 +922,8 @@ export class Graph {
}
async refreshSubtree() {
if (this._isSubtreeUpdated(this.data.root)) {
this.selectNode(null);
await this.refresh();
this._storeHistory();
}
await this.refresh();
this._storeHistory();
}
async save() {
-1
View File
@@ -519,7 +519,6 @@ export const useWorkspace = create<WorkspaceStore>((set, get) => ({
edit: (path, focusId) => {
const workspace = get();
const setting = useSetting.getState();
const editor = workspace.editors.find((v) => v.path === path);
if (editor) {
editor.focusId = focusId;