Uncaught (in promise) - TypeError r(...).onClick is not a function

Hello,

Something weird is happening on my website, on the monitoring tool,
( /dashboard/…/settings/monitoring/site-events ), I can see the errors and warnings from my site, I don’t know what their source is, so I can’t troubleshot it, also, I get an error message that says TypeError r(…).onClick is not a function , when I comment out the line the console indicates to, I get another error Uncaught (in promise) - TypeError r(…).show is not a function , and when commenting this line I get another error and so on, all the errors that I get are functions that return promises.

What’s going on there!?
https://nasriyasoftware.wixsite.com/nasriyaowl/product-page/lace-up-leggings-with-grommet

Also, I get an error in the monitoring tool .expand() is not a function , while it’s not logged to the console. By the way, why there are so many warnings on my site? They’re affecting the loading performance, it’s too bad.

It marks an error on the following line:

$item('#location').onClick(() => { wixLocation.to(countryLink) });	

Are you sure you have such an element on this page (inside the repeater)?

Yes I do, the strange this is when deleting or commenting the line, I get another error as I described in my post above, I keep getting errors on the functions that return promises.

@ahmadnasriya This is not strange because the first error might stop the code and therefore you just do see the next error, but all of them are there.
I don’t see this element in the link you attached above.

@jonatandor35 It’s collapsed automatically because the product didn’t have any reviews, I’ve added a test review, you can take a look now!

Also the way you used this code:

$w('#submitReviewDataset').onReady(async () => {
			await getUserIP();
})

looks problematic. Because you put it after another await, which means that the dataset gets ready before it runs this line.

P.S. you should consider rewrite your code using .then() instead of await. It’ll be easier to debug.

@jonatandor35 That’s because I only need the user IP when users are logged in to reduce the loading time of the page.

What do you mean by problematic? Where’s the ‘other’ await that you’re talking about?

@ahmadnasriya First of all if you run a promise without putting a “return” before, it shouldn’t affect the loading time (That’s the whole point in promises, they don’t stop the other code execution). And any way, you can use if(user.isLoggedIn).
Second, as far as I remember in the documentation they recommend to avoid using async in the $w.onReady() . It’s not that it’s not allowed, but it’s prone to mistakes or problems.
Third, as you have hundreds of lines, it could be difficult to locate the problem, but arranging it in a more readable way can help you locate it. Now that you have so many await’s it’s hard to follow.

  • it looks like you can run some of the promises together using Promise.all()
    This also may improve the performance.

Also it says: “An error occurred when trying to query the Reviews Stats collection”
So check that too.

(I don’t have an answer to what’s going on, but maybe rearranging the code will help you debug it).

@jonatandor35 Thanks for checking out.

I’m a beginner, so I really appreciate your advice, I’ll try to rearrange the code and put your advice in action, then I’ll try to debug it.

If I knew about promise.all() I would have used it, but I didn’t, the code is in fact inside an if(user.isLoggedIn) statement, and the code inside it should only run when the user is logged in, regarding the functions that return promises, I only use the await when the next few line of code need it to prevent getting an errors like cannot read property ._id of undefined , and so on.

I can’t really recommend what to do because I’m not following the logic (it’s a long code). But you can try to comment out some pieces of code (for example the fetch function etc… and see if you still have the issue).

@jonatandor35 will do, thanks for help :kissing_smiling_eyes: I appreciate it a lot.

@jonatandor35 Wrapping the functions that return promises inside an if statement that checks if the item is collapsed or not, and execute the next commands if it’s not, seems to trick the console and prevent it on logging it as an error, I did notice that all the functions that I get errors on are the ones inside the repeater, I thought that it has to be something with the $item selector, so I tried to replace the repeater’s selector with the regular one, but it didn’t work.

Although the code is running perfectly, the console insist to consider it as a serious error.

Regarding the fetch functions’ error, I tried to comment them one after the other, but the console kept logging them as errors, even Wix APIs like wixData and wixLocation were marked as errors on the console.

The only error I get on the site events monitoring tool is a Wix Stores related error.

Here is the error details:

Considering that the code is running as expected, even inside the .onClick() function which was marked as an error, and upon testing the getUserIP() function which relay on an external fetch and end up getting the expected results and did its job, you can assure that the fetches are working just fine, you’ll end up with a conclusion that it’s not a code error, but rather a core error with the API

Turns out that you were right, after hours of debugging, I found that removing the async/await from the repeater onItemReady() function solves the problem.

But I really need to get the reviewer data first before continuing to the next lines, most of them depend on the data that I’ll get from the function, the repeater looks horrible without these data, no name, no image and no profile link. Look what I mean.

Now that we figured out what the reason of the errors, how can I overcome this issue? :thinking: