next-safe-action@3.4.0.patch 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. diff --git a/dist/hook.mjs b/dist/hook.mjs
  2. index 4f2ea0f6818194b906590f2467f788e66d3524d9..fcec224f19be119a922734e8a6fb7d1916921d8a 100644
  3. --- a/dist/hook.mjs
  4. +++ b/dist/hook.mjs
  5. @@ -7,7 +7,7 @@ import {
  6. useEffect,
  7. useRef,
  8. useState,
  9. - useTransition
  10. + useTransition,
  11. } from "react";
  12. // src/utils.ts
  13. @@ -17,8 +17,12 @@ var isNextNotFoundError = (e) => isError(e) && e.message === "NEXT_NOT_FOUND";
  14. // src/hook.ts
  15. var getActionStatus = (res) => {
  16. - const hasSucceded = typeof res.data !== "undefined";
  17. - const hasErrored = typeof res.validationError !== "undefined" || typeof res.serverError !== "undefined" || typeof res.fetchError !== "undefined";
  18. + const hasSucceded = typeof res?.data !== "undefined";
  19. + const hasErrored =
  20. + typeof res === "undefined" ||
  21. + typeof res.validationError !== "undefined" ||
  22. + typeof res.serverError !== "undefined" ||
  23. + typeof res.fetchError !== "undefined";
  24. const hasExecuted = hasSucceded || hasErrored;
  25. return { hasExecuted, hasSucceded, hasErrored };
  26. };
  27. @@ -49,12 +53,15 @@ var useAction = (clientCaller, cb) => {
  28. onExecute(input2);
  29. }
  30. return startTransition(() => {
  31. - return executor.current(input2).then((res2) => setRes(res2)).catch((e) => {
  32. - if (isNextRedirectError(e) || isNextNotFoundError(e)) {
  33. - throw e;
  34. - }
  35. - setRes({ fetchError: e });
  36. - });
  37. + return executor
  38. + .current(input2)
  39. + .then((res2) => setRes(res2))
  40. + .catch((e) => {
  41. + if (isNextRedirectError(e) || isNextNotFoundError(e)) {
  42. + throw e;
  43. + }
  44. + setRes({ fetchError: e });
  45. + });
  46. });
  47. }, []);
  48. const reset = useCallback(() => {
  49. @@ -68,17 +75,20 @@ var useAction = (clientCaller, cb) => {
  50. reset,
  51. hasExecuted,
  52. hasSucceded,
  53. - hasErrored
  54. + hasErrored,
  55. };
  56. };
  57. var useOptimisticAction = (clientCaller, initialOptData, cb) => {
  58. const [res, setRes] = useState({});
  59. const [input, setInput] = useState();
  60. - const [optState, syncState] = experimental_useOptimistic({ ...initialOptData, ...res.data, __isExecuting__: false }, (state, newState) => ({
  61. - ...state,
  62. - ...newState,
  63. - __isExecuting__: true
  64. - }));
  65. + const [optState, syncState] = experimental_useOptimistic(
  66. + { ...initialOptData, ...res.data, __isExecuting__: false },
  67. + (state, newState) => ({
  68. + ...state,
  69. + ...newState,
  70. + __isExecuting__: true,
  71. + })
  72. + );
  73. const executor = useRef(clientCaller);
  74. const onExecuteRef = useRef(cb?.onExecute);
  75. const { hasExecuted, hasSucceded, hasErrored } = getActionStatus(res);
  76. @@ -90,12 +100,15 @@ var useOptimisticAction = (clientCaller, initialOptData, cb) => {
  77. if (onExecute) {
  78. onExecute(input2);
  79. }
  80. - return executor.current(input2).then((res2) => setRes(res2)).catch((e) => {
  81. - if (isNextRedirectError(e) || isNextNotFoundError(e)) {
  82. - throw e;
  83. - }
  84. - setRes({ fetchError: e });
  85. - });
  86. + return executor
  87. + .current(input2)
  88. + .then((res2) => setRes(res2))
  89. + .catch((e) => {
  90. + if (isNextRedirectError(e) || isNextNotFoundError(e)) {
  91. + throw e;
  92. + }
  93. + setRes({ fetchError: e });
  94. + });
  95. },
  96. [syncState]
  97. );
  98. @@ -113,11 +126,8 @@ var useOptimisticAction = (clientCaller, initialOptData, cb) => {
  99. reset,
  100. hasExecuted,
  101. hasSucceded,
  102. - hasErrored
  103. + hasErrored,
  104. };
  105. };
  106. -export {
  107. - useAction,
  108. - useOptimisticAction
  109. -};
  110. +export { useAction, useOptimisticAction };
  111. //# sourceMappingURL=hook.mjs.map