dialectlabs / blinks-react-native

MIT License
14 stars 5 forks source link

TypeError in useAction Hook: finally is not a function #7

Open ramyodev opened 3 months ago

ramyodev commented 3 months ago

Issue Summary

A TypeError occurs within the useAction hook of the Blinks SDK when attempting to use a finally block after a promise chain.

Steps to Reproduce

  1. Integrate the Blinks SDK within a React component using the useAction hook.
  2. Trigger the component that executes the useAction hook.
  3. Observe the console for any errors during the action fetching process.

Error Message

ERROR TypeError: _chunk3VHJSHHRcjs.Action.fetch(a(...)", e); setAction(null); }).finally is not a function (it is undefined)

Code Snippet

useEffect(() => {
  setIsLoading(true);
  if (!isRegistryLoaded || !actionApiUrl) {
    return;
  }
  let ignore = false;
  _chunk3VHJSHHRcjs.Action.fetch(actionApiUrl, void 0, supportStrategy).then((action2) => {
    if (ignore) {
      return;
    }
    setAction(action2);
  }).catch((e) => {
    console.error("[@dialectlabs/blinks] Failed to fetch action", e);
    setAction(null);
  }).finally(() => {
    if (!ignore) {
      setIsLoading(false);
    }
  });
  return () => {
    ignore = true;
  };
}, [actionApiUrl, isRegistryLoaded]);

Suggested Fix

Removing the finally block resolves the error and allows the component to function, but this is not ideal. A better fix would be to ensure that the Promise implementation in the environment includes finally or to add a polyfill.

Environment

prsvic commented 3 months ago

Hmm, that sounds interesting. I wasn’t able to reproduce it using Hermes and the specified version of React Native (0.74.3).

Could you provide more details about your environment? Specifically, which engine you’re using, the Node version, and so on?

ramyodev commented 2 months ago

@prsvic I will try to provide you with a minimal reproducible example asap. For now we patched it like so:

@dialectlabs+blinks-core+0.12.1.patch

diff --git a/node_modules/@dialectlabs/blinks-core/dist/index.cjs b/node_modules/@dialectlabs/blinks-core/dist/index.cjs
index 12ad4e1..9d395d3 100644
--- a/node_modules/@dialectlabs/blinks-core/dist/index.cjs
+++ b/node_modules/@dialectlabs/blinks-core/dist/index.cjs
@@ -1493,11 +1493,7 @@ function useAction({
     }).catch((e) => {
       console.error("[@dialectlabs/blinks-core] Failed to fetch action", e);
       setAction(null);
-    }).finally(() => {
-      if (!ignore) {
-        setIsLoading(false);
-      }
-    });
+    })
     return () => {
       ignore = true;
     };

Will provide you with more info soon.