Skip to content

Commit 9a2d24b

Browse files
committed
fix(hooks): navigation callbacks execution
1 parent 8775f84 commit 9a2d24b

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packages/next-safe-action/src/hooks-utils.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,13 @@ export const useActionCallbacks = <ServerError, S extends StandardSchemaV1 | und
105105
break;
106106
}
107107

108-
if (navigationError) {
108+
// Navigation flow.
109+
// If the user redirected to a different page, the `hasNavigated` status never gets set.
110+
// In all the other cases, the `hasNavigated` status is set.
111+
if (!navigationError) return;
112+
const navigationKind = FrameworkErrorHandler.getNavigationKind(navigationError);
113+
114+
if (navigationKind === "redirect" || status === "hasNavigated") {
109115
await Promise.all([
110116
Promise.resolve(
111117
onNavigation?.({
@@ -115,9 +121,9 @@ export const useActionCallbacks = <ServerError, S extends StandardSchemaV1 | und
115121
),
116122
Promise.resolve(onSettled?.({ result, input })),
117123
]);
118-
119-
throw navigationError;
120124
}
125+
126+
throw navigationError;
121127
};
122128

123129
executeCallbacks().catch(console.error);

0 commit comments

Comments
 (0)