Skip to content

Automate browser based workflows with AI

fix(SKY-9723): guard react-router blocker proceed/reset on state (#5929)

Aaron Perezc5b4f68765ae
diff --git a/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx b/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx
index dab6bdcdd..513c7fe78 100644
--- a/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx
+++ b/skyvern-frontend/src/routes/workflows/editor/FlowRenderer.tsx
@@ -388,6 +388,8 @@ function FlowRenderer({
nextLocation.pathname !== currentLocation.pathname
);
});
+ const blockerRef = useRef(blocker);
+ blockerRef.current = blocker;
const doLayout = useCallback(
(nodes: Array<AppNode>, edges: Array<Edge>) => {
@@ -953,7 +955,10 @@ function FlowRenderer({
open={blocker.state === "blocked"}
onOpenChange={(open) => {
if (!open) {
- blocker.reset?.();
+ const current = blockerRef.current;
+ if (current.state === "blocked") {
+ current.reset?.();
+ }
}
}}
>
@@ -969,7 +974,10 @@ function FlowRenderer({
<Button
variant="secondary"
onClick={() => {
- blocker.proceed?.();
+ const current = blockerRef.current;
+ if (current.state === "blocked") {
+ current.proceed?.();
+ }
}}
>
Continue without saving
@@ -977,8 +985,9 @@ function FlowRenderer({
<Button
onClick={() => {
handleSave().then((ok) => {
- if (ok) {
- blocker.proceed?.();
+ const current = blockerRef.current;
+ if (ok && current.state === "blocked") {
+ current.proceed?.();
}
});
}}