fix(next-safe-action): patch package to handle network errors

This commit is contained in:
Nicolas Meienberger 2023-10-12 22:19:18 +02:00
parent bc8c4bfe88
commit 39e8041a06
3 changed files with 128 additions and 1876 deletions

View File

@ -148,6 +148,8 @@
},
"homepage": "https://github.com/runtipi/runtipi#readme",
"pnpm": {
"patchedDependencies": {}
"patchedDependencies": {
"next-safe-action@3.4.0": "patches/next-safe-action@3.4.0.patch"
}
}
}

View File

@ -0,0 +1,112 @@
diff --git a/dist/hook.mjs b/dist/hook.mjs
index 4f2ea0f6818194b906590f2467f788e66d3524d9..b949dd0576477b08958cbf7be91c8c47c57dbe56 100644
--- a/dist/hook.mjs
+++ b/dist/hook.mjs
@@ -7,7 +7,7 @@ import {
useEffect,
useRef,
useState,
- useTransition
+ useTransition,
} from "react";
// src/utils.ts
@@ -17,8 +17,12 @@ var isNextNotFoundError = (e) => isError(e) && e.message === "NEXT_NOT_FOUND";
// src/hook.ts
var getActionStatus = (res) => {
- const hasSucceded = typeof res.data !== "undefined";
- const hasErrored = typeof res.validationError !== "undefined" || typeof res.serverError !== "undefined" || typeof res.fetchError !== "undefined";
+ const hasSucceded = typeof res?.data !== "undefined";
+ const hasErrored =
+ typeof res?.validationError !== "undefined" ||
+ typeof res?.serverError !== "undefined" ||
+ typeof res?.fetchError !== "undefined";
const hasExecuted = hasSucceded || hasErrored;
return { hasExecuted, hasSucceded, hasErrored };
};
@@ -49,12 +53,15 @@ var useAction = (clientCaller, cb) => {
onExecute(input2);
}
return startTransition(() => {
- return executor.current(input2).then((res2) => setRes(res2)).catch((e) => {
- if (isNextRedirectError(e) || isNextNotFoundError(e)) {
- throw e;
- }
- setRes({ fetchError: e });
- });
+ return executor
+ .current(input2)
+ .then((res2) => setRes(res2))
+ .catch((e) => {
+ if (isNextRedirectError(e) || isNextNotFoundError(e)) {
+ throw e;
+ }
+ setRes({ fetchError: e });
+ });
});
}, []);
const reset = useCallback(() => {
@@ -68,17 +75,20 @@ var useAction = (clientCaller, cb) => {
reset,
hasExecuted,
hasSucceded,
- hasErrored
+ hasErrored,
};
};
var useOptimisticAction = (clientCaller, initialOptData, cb) => {
const [res, setRes] = useState({});
const [input, setInput] = useState();
- const [optState, syncState] = experimental_useOptimistic({ ...initialOptData, ...res.data, __isExecuting__: false }, (state, newState) => ({
- ...state,
- ...newState,
- __isExecuting__: true
- }));
+ const [optState, syncState] = experimental_useOptimistic(
+ { ...initialOptData, ...res.data, __isExecuting__: false },
+ (state, newState) => ({
+ ...state,
+ ...newState,
+ __isExecuting__: true,
+ })
+ );
const executor = useRef(clientCaller);
const onExecuteRef = useRef(cb?.onExecute);
const { hasExecuted, hasSucceded, hasErrored } = getActionStatus(res);
@@ -90,12 +100,15 @@ var useOptimisticAction = (clientCaller, initialOptData, cb) => {
if (onExecute) {
onExecute(input2);
}
- return executor.current(input2).then((res2) => setRes(res2)).catch((e) => {
- if (isNextRedirectError(e) || isNextNotFoundError(e)) {
- throw e;
- }
- setRes({ fetchError: e });
- });
+ return executor
+ .current(input2)
+ .then((res2) => setRes(res2))
+ .catch((e) => {
+ if (isNextRedirectError(e) || isNextNotFoundError(e)) {
+ throw e;
+ }
+ setRes({ fetchError: e });
+ });
},
[syncState]
);
@@ -113,11 +126,8 @@ var useOptimisticAction = (clientCaller, initialOptData, cb) => {
reset,
hasExecuted,
hasSucceded,
- hasErrored
+ hasErrored,
};
};
-export {
- useAction,
- useOptimisticAction
-};
+export { useAction, useOptimisticAction };
//# sourceMappingURL=hook.mjs.map

File diff suppressed because it is too large Load Diff