Anyway, another actually blocking issue… With the ...
# support
e
Anyway, another actually blocking issue… With the setup above, when I build and run the app on the iOS simulator, all I get after starting is a
non-std C++ exception
. When I uncomment the
await rudderClient.setup(…)
call, the app starts normally.
✅ 1
m
Hey There! 👋 Your message has been received by the RudderStack team. Our standard customer support hours are 9-6 PM EST, but we will forward this request to your Technical Account Manager, and they will get back to you shortly. Please use the thread for any additional comments.
e
image.png
c
Hey @eager-pizza-76165 can you please confirm if this issue only occurs when you use
"strict": true
, as you mentioned in the previous thread?
the type error is only present with the
"strict": true
option in
tsconfig.json
Once you turn that off, does this issue still occur?
e
yes, unfortunately the issue still occurs without
"strict": true
, it doesn’t seem related and is blocking
the Android build is problematic as well. I’m really not sure what I could have done wrong in the setup as it’s fairly simple
c
Understood, thank you for sharing the information. Can you please raise a separate bug report for this issue: https://github.com/rudderlabs/rudder-sdk-react-native/issues/new?assignees=1abhish[…]2C+open+source&template=bug_report.md&title=BUG+%3A+%3CTitle%3E. One query, have you tried creating a sample React-Native project (e.g., using expo) and then install our React-Native SDK over there?
e
I haven’t. I understand I could probably identify the culprit here that way, but I hoped somebody here could have a good idea of where to look.
👍 1
It seems to be a problem with the top-level await. Removing the
await
keyword allows the app to run. I do have
"module": "esnext",
in
tsconfig.json
, not sure what else is required… This might be a React Native or project setup issue.
c
I suspect that the issue may be specific to your project, as we have tested our React-Native SDK on multiple sample projects built using tools like expo and React-Native CLI on both Android and iOS simulators, and we did not encounter any such issue. By the way, may I ask which tools you used to build your React-Native project? Did you use React-Native CLI?
e
Yes, we don’t use expo.
👍 1
I just noticed your own example doesn’t use top-level await: https://github.com/rudderlabs/rudder-sdk-react-native/blob/develop/apps/example/src/app/App.tsx#L92 It’s wrapped in an async function and called inside a
useEffect
🤔 https://github.com/rudderlabs/rudder-sdk-react-native/blob/develop/apps/example/src/app/App.tsx#L125
I can confirm such an approach works for me, too. It’s the same as removing the
await
keyword, or actually worse, at it’s called only after the first render of the app… It would be nice if you had an example that actually implements the setup commands and recommendations from the docs exactly.
c
Is using the useEffects good enough for you or do you want to initialise the SDK before the root level component mount?
e
I’m not sure whether I could be missing any initial events because of this. A good question would also be: Why is it recommended in the docs? What happens if it’s not done as suggested?
c
Before moving forward, can you please explain which type of events you referred by
any initial events
. The code snippet mentioned in our documentation was intended to be used as part of an asynchronous function:
Copy code
await rudderClient.setup(WRITE_KEY, {
  dataPlaneUrl: DATA_PLANE_URL,
  trackAppLifecycleEvents: true,
  recordScreenViews: true,
})
We apologize for the trouble you faced while referring to our documentation. We will improve the documentation by including both ways to initialize the SDK, i.e., using
useEffect
and using top-level
await
. Meanwhile please refer to below steps to initialise the React-Native SDK using top level await (in case you intend not to initialise the SDK using useEffects): • Create any file (say
rudderinit.ts
) • Copy the following code snippet in above file:
Copy code
import rc, {RUDDER_LOG_LEVEL} from '@rudderstack/rudder-sdk-react-native';
const initRudder = async () => {
  const config = {
    dataPlaneUrl: '<DATA_PLANE_URL>',
    trackAppLifecycleEvents: true,
    autoCollectAdvertId: true,
    recordScreenViews: true,
    logLevel: RUDDER_LOG_LEVEL.VERBOSE,
  };
  await rc.setup('<WRITE_KEY>', config);
};
export {initRudder};
• In your index.js file paste this snippet:
Copy code
import {initRudder} from './rudderinit';
try {
  initRudder();
} catch (e) {
  console.log(e);
}
• Before the
AppRegistry.registerComponent(..);
mount the root component. Regarding the
useEffect
hook, it is expected to work similarly to top level await.
What happens if it’s not done as suggested?
• I think it can be used according to your preference, if you have any specific requirements or preferences, please let us know.
e
I’m so sorry if the “top-level” wording wasn’t mentioned in the docs. I probably imagined it. I thought I’m following the official recommendation and was surprised it doesn’t work, but it seems I brought it too far here by mistake. In no way do I think I need the library to be initiated before the first app mount. Sorry to waste your time here, the
useEffect
approach is surely enough.
👍 1
I think the “Add the following code in your application:” sentence in the docs confused me as it looks like a top-level code.
👍 1
c
Thank you once again for bringing this to our attention. We will take the necessary steps to improve our documentation for a better user experience in the future.