fix render error after build
This commit is contained in:
1 parent
e21c32e800
commit
ef10851e64
3 files changed
+21
-17
No files matched your search
@@ -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]);
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
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,12 +922,9 @@ export class Graph {
|
||||
}
|
||||
|
||||
async refreshSubtree() {
|
||||
if (this._isSubtreeUpdated(this.data.root)) {
|
||||
this.selectNode(null);
|
||||
await this.refresh();
|
||||
this._storeHistory();
|
||||
}
|
||||
}
|
||||
|
||||
async save() {
|
||||
if (b3util.isNewVersion(this.data.version)) {
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user