Debugging and mismatch between Preview and Published code (not user registration issue)

Hello Wix Forum,

I am using wix-storage library to pass around some local and session variables to make my user experience a little more comfy. I deal with these values on the global page (site page/site.js) and at the page level (ie where the page onReady handler is defined). My preview code works like a charm, however it is my published live code that does not conform.

Live code being less verbose and more obscure, I have no idea how to debug my problem. I just got a cryptic:
Uncaught (in promise) TypeError: Cannot read property ‘4961d984-96b4-372d-bc22-aba921a9cb29’ of undefined in reducer.js and an uglier stacktrace. I also believe this is the error that is silencing all the console logs I have stuffed in my code (because none of them appear, to state the obvious :).

My questions:

  • Any ideas how to debug this?
  • What is reducer.js?
  • How do I work my way back from ‘4961d984-96b4-372d-bc22-aba921a9cb29’ to the real property name? is it through the “maps” (not sure, I believe reading about them recently)?
  • How do I get a hold of this cheeky “undefined” object to make it defined? :slight_smile:
  • Is this a common problem that is or could be documented somewhere? (I would be happy to do so)
  • How to handle the differences between preview and published code? This is potentially problematic…

Thank you very much :slight_smile:

Martin

Hey
Uncaught (in promise) TypeError: Cannot read property ‘4961d984-96b4-372d-bc22-aba921a9cb29’ of undefined means that you are trying to read out the string above from a variable that is undefined. Probably you have some variable or object in your code that is not checked if it is undefined or null before trying to use it.

Make sure to always check all variables and objects that you are trying to parse or use in code before using them so that you can handle when that is undefined or null.

Like below

if (yourVariable && yourVariable !== undefined) {
 // work with the variable in here
} else {
  // your variable is not usable so handle that here
}

If you do that you won’t get any nasty errors in your code. Also make sure you always have synced your data collections before testing code in a published site so that is not the cause of errors.

Hi @andreas-kviby ,

Thanks for the tips, they are very sensible. I had totally not thought about the data collection sync issue and I’ll sure take that into account in my future devs. I guess I’ll need to go variable hunting in my code base now, haha. Will take a day or two before I am done with this one.

Best Regards,

Martin