I’m working on an app in React Native for IOS which has one App.js with all the RN stuff and one helper.js with all the functions I call. There is this one complex function that calls on a bunch of other functions that I made, and it has to do with making several API calls, editing/parsing/analyzing text which takes 3 to 8 seconds on average. This was all working fine for months, but now there is issue after issue. They are independent issues at different steps of the process. The first one has to do with a request to turn a fetch response into text, which often didn’t work for large text for a few days, but now today it magically works. So even when the API stuff works, in the middle of the large function which calls everything else, when I am finally modifying some small arrays, changing text etc, with a TON of log statements to see where I am, almost every time it stops at some random point. No errors, all the inputs are completely fine. Like for example this loop.
console.log(manualFoundArr)
for (let manual = 0; manual < manualFoundArr.length; manual++) {
if (manualFoundArr[manual] == "") {
console.log("skipped " + manual)
continue;
}
let ingredient = manualFoundArr[manual].trim();
//turn the first letter of every word to uppercase
ingredient = ingredient.charAt(0).toUpperCase() + ingredient.slice(1);
let fromIndex = 0;
console.log(ingredient)
...
manualFoundArr prints as [“”, “”, “”, “”] which is good. Then I am supposed to see skipped 0, skipped 1, skipped 2, skipped 3 as every value in the array is “”. And if that value isnt “”, then I should at least print out ingredient a few lines later, which is just the element at that index with a few modifications. But what I get, for example is:
[“”, “”, “”, “”]
skipped 0
skipped 1
And thats it, and my app UI freezes for some reason . Other times, with the same input, it might finish the for loop and get a bit farther down the code, but still exit. Or even weirder, I once had the function leave in between back to back print statements.
let takePic = async () => {
let options = {
quality: 0.4,
base64: true,
exif: false
};
let newPhoto = await cameraRef.current.takePictureAsync(options);
const output = await largeFunction(...);
}
What’s very weird is that there is no timeout function that makes the large function quit at some time. All I do is const output = await largeFunction(...). And this was all working perfectly fine last week, it wouldn’t stop randomly and it would never freeze.
Any help would be greatly appreciated.