mirror of
https://github.com/meienberger/runtipi.git
synced 2024-08-17 08:00:26 +03:00
fix(next-safe-action): patch package to handle network errors
This commit is contained in:
parent
bc8c4bfe88
commit
39e8041a06
@ -148,6 +148,8 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/runtipi/runtipi#readme",
|
"homepage": "https://github.com/runtipi/runtipi#readme",
|
||||||
"pnpm": {
|
"pnpm": {
|
||||||
"patchedDependencies": {}
|
"patchedDependencies": {
|
||||||
|
"next-safe-action@3.4.0": "patches/next-safe-action@3.4.0.patch"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
112
patches/next-safe-action@3.4.0.patch
Normal file
112
patches/next-safe-action@3.4.0.patch
Normal 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
|
1888
pnpm-lock.yaml
1888
pnpm-lock.yaml
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user