Confusing JS variable error

Here’s the parts of the script in question:

var eventId = 0;

this.Parameter.onValueChanged(module, function(param) {
	eventId = param.eventId;

	if (param.created != undefined) {
		Created.value = param.created;
	}

	getEvent();
});

function getEvent() {
	Loading.value = true;

	UserContext.getStorageUser().then(function(User) {

		EventContext.getEvent(eventId, User.id).then(function(result) {

			Event = result;
			EventObs.value = result;

			attendanceStatus.value = result.my_attendance;
			
			if (attendanceStatus.value == "host") {

				isHost.value = true;
			}

			var ImgUrl = Event.img_url;

			fileType = ImgUrl.split(".");
			fileType = fileType[1];

			if (fileType == "jpg") {
				fileType = "jpeg";
			}

			ImageContext.UrlToBase64(ImgUrl, "true", "300", "200", fileType).then(function(Base64) {

				EventImageBase64.value = Base64;
				LoadingImage.value = false;
			});

			getMessages();

			Loading.value = false;
		});
	});
}


function getMessages() {
	EventContext.getMessages(eventId).then(function(result) {
		console.log(result);
		Messages.replaceAll(result);
	});
}

GetEvent() worked like a charm until I recently added GetMessages() into the mix. Now after adding it, the code halts at the execution of GetMessages() in GetEvent() and throws this error:

 Error: TypeError: Cannot read property 'eventId' of undefined: Name: TypeError: Cannot read property 'eventId' of undefined
Error message: Uncaught TypeError: Cannot read property 'eventId' of undefined
File name: Pages/EventPages/ViewEventPage.js
Line number: 29
Source line: 	eventId = param.eventId;
JS stack trace: TypeError: Cannot read property 'eventId' of undefined
    at Pages/EventPages/ViewEventPage.js:29:17
    at subscriber (fusejs/Observable.js:417:3)
    at Subscriber.post (fusejs/Observable.js:550:16)
    at fusejs/Observable.js:576:39
    at PumpMessages (fusejs/Observable.js:1063:4)
    at ProxyObservable.Observable._addSubscriber (fusejs/Observable.js:582:3)
    at ProxyObservable.Observable.addSubscriber (fusejs/Observable.js:555:7)
    at ProxyObservable.Observable._addDisposableSubscriber (fusejs/Observable.js:438:7)
    at ProxyObservable.Observable.onValueChanged (fusejs/Observable.js:423:8)
    at Object._tempMethod (Pages/EventPages/ViewEventPage.js:28:16)
 in Fuse.Reactive.JavaScript+DiagnosticSubject<Pages/EventPages/ViewEventPage.js:29>

eventId is not used or manipulated any other places in the script and does not seem to have anything to do with it. When removing GetMessages() from GetEvent() or gut GetMessages() of its contents it works perfectly. I find this very strange and confusing since using eventId works fine in GetEvent()

The new Fuse ‘player’ has been very unstable and freezes a lot as well as being a bit slower at reacting to file changes. When doing UX changes it usually refreshes 3-4 times and sometimes gets stuck in a loop. I recently had another mysterious UX error which eventually was resolved by simply quitting and restarting the player. Can the player be responsible for this error or am I missing something?

Thanks in advance.

Hi Ferdinand,

as the error log says, the problem is in this line eventId = param.eventId;, suggesting that the eventId property is not available on the param object as it changes in .onValueChanged().

Based on my past experience, this usually can happen when you router.push() to a page with some params, and then make some changes to the UX file of the page you landed on, then save and trigger hot reload. At that point, Fuse tries to navigate back to where you had landed, but the pushed param is gone during the reload. If that is the case, I’m not sure there is an easy fix.

If that is not the case, and looking at the other parts of your report, it makes me wonder if you could share the whole project with us for further debugging? If you can’t put it out in public, you could upload it here.

Thank you for the reply!

And thank for the suggestions. However I have looked through it meanwhile and noticed that the error comes from when replacing the Messages Observable array with the JSON array returned by the ``EventContext.getMessages()``` promise. If not, I’ll get back to this thread.

Yup, there was an honest mistake in EventContext.getMessages(). Sorry to bother you!