Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ramyodev opened this issue Aug 24, 2024 · 2 comments
Open

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

ramyodev opened this issue Aug 24, 2024 · 2 comments

Comments

@ramyodev
Copy link
Contributor

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

  • React Native version: 0.74.3
  • react-native-picker-select version: ^9.1.3
  • @dialectlabs/blinks version: ^0.8.0
  • @dialectlabs/blinks-react-native version: ^0.2.0
@prsvic
Copy link
Contributor

prsvic commented Aug 28, 2024

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
Copy link
Contributor Author

ramyodev commented Oct 1, 2024

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants