react-flow updates: allow one in current render cycle; defer rest to … (#3213)
This commit is contained in:
@@ -79,6 +79,8 @@ import {
|
|||||||
} from "./workflowEditorUtils";
|
} from "./workflowEditorUtils";
|
||||||
import { useAutoPan } from "./useAutoPan";
|
import { useAutoPan } from "./useAutoPan";
|
||||||
|
|
||||||
|
const nextTick = () => new Promise((resolve) => setTimeout(resolve, 0));
|
||||||
|
|
||||||
function convertToParametersYAML(
|
function convertToParametersYAML(
|
||||||
parameters: ParametersState,
|
parameters: ParametersState,
|
||||||
): Array<
|
): Array<
|
||||||
@@ -619,13 +621,20 @@ function FlowRenderer({
|
|||||||
) {
|
) {
|
||||||
workflowChangesStore.setHasChanges(true);
|
workflowChangesStore.setHasChanges(true);
|
||||||
}
|
}
|
||||||
// defer update to next tick to prevent max recursion errors;
|
|
||||||
// NOTE: deferring too long causes node updates to be skipped
|
// only allow one update in _this_ render cycle
|
||||||
if (onNodesChangeTimeoutRef.current === null) {
|
if (onNodesChangeTimeoutRef.current === null) {
|
||||||
onNodesChange(changes);
|
onNodesChange(changes);
|
||||||
onNodesChangeTimeoutRef.current = setTimeout(() => {
|
onNodesChangeTimeoutRef.current = setTimeout(() => {
|
||||||
onNodesChangeTimeoutRef.current = null;
|
onNodesChangeTimeoutRef.current = null;
|
||||||
}, 0);
|
}, 0);
|
||||||
|
} else {
|
||||||
|
// if we have an update in this render cycle already, then to
|
||||||
|
// prevent max recursion errors, defer the update to next render
|
||||||
|
// cycle
|
||||||
|
nextTick().then(() => {
|
||||||
|
onNodesChange(changes);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onEdgesChange={onEdgesChange}
|
onEdgesChange={onEdgesChange}
|
||||||
|
|||||||
Reference in New Issue
Block a user