WebThread -> WebContainer.EmbedWithin -> 'Javascript Null Is Not an Object'

Over the weekend, I changed my Web App from using Timers where I had issues with accessing the session reliably. So I updated the code to use WebThreads which does keep the session available and allows for UI updates as stated here: https://forum.xojo.com/36140-webthread-xojo-core-timer-calllater-and-websessio/6#p295704

To get to the point, within the WebThread, I’m having an issue when I use WebContainer.EmbedWithin which is resulting as a Javascript Null Is Not an Object error. It’ll work a random number of times and then I’ll get this:

Here’s the full javascript: http://CampSoftware.com/files/LongTerm/Xojo/JavascriptNullIsNotAnObject/JavascriptNullIsNotAnObject.txt

Here’s a video: http://CampSoftware.com/files/LongTerm/Xojo/JavascriptNullIsNotAnObject/JavascriptNullIsNotAnObject.mp4
In the video, I show it happen and then show how commenting the EmbedWithin prevents the Javascript Null Is Not an Object error.

theRecordContainer.EmbedWithin( XanaduPortalScrollingContainer1, 0, RecordTopNext, XanaduPortalScrollingContainer1.Width, theRecordContainer.Height )

Any ideas? My entire goal is to show a spinner, do stuff, and then hide the spinner.

I forgot to link to the Project with the code: http://CampSoftware.com/files/LongTerm/Xojo/JavascriptNullIsNotAnObject/JavascriptNullIsNotAnObject_Project.zip

@Hal Gumbert - Just running your project I am getting a ThreadAlreadyRunning exception in your DetailLoad method. This means that you’re calling Run on a thread that you’ve previously called it before letting it finish. You should be checking the state of the Thread before calling Run on it again.

I can fix that, but if you wait to click til it’s done updating the contact info it’ll produce a javascript null error.

Thanks for all your attention on this. It’s driving me batty.

The only time I’m getting that error is when I get that exception. It’s from the app trying to update a control that doesn’t exist because of the exception.

Thank you Greg. I’ll update my code and test again. Sorry for the hassle…

I just updated my code that called the thread in my ContactsPage.DetailLoad method:

[code]If DetailLoadDoThread.State = DetailLoadDoThread.NotRunning Then

SpinnerUpdate( "Show" )


End [/code]

It’s still producing the JavaScript Null error. :frowning:

Well, I’m at a loss. I can no longer reproduce the error on my machine. Have you done that in all of the places where you’re calling Run on a thread?

Also, have you tested this in the latest beta?

Thanks Greg. I’ll do some more testing and report back.

@Greg O’Lone ,

Thanks again for spending so much time on this.

Just to rewind a bit, my only reason for using WebThreads and previously WebTimers is to show a spinner and disable controls while my code runs. If there was a call I could make to update the UI during the round trip to the server, I’d be all for it and wouldn’t need WebThreads as my code runs without errors when I take WebThreads and WebTimers out of the equation. Stepping even further back, if WebListboxes could show containers in the rows like iOSTable, I don’t think I’d need scrolling containers.

I took your advice and updated my calling of “DetailLoadDoThread.Run” to check for the thread state. I also added a boolean property as an extra measure. The following is what my ContactsPage.DetailLoad method looks like. This method is the only place I run the WebThread.

[code] If DetailLoadFlag Then
end if
DetailLoadFlag = true

If DetailLoadDoThread.State = DetailLoadDoThread.NotRunning Then

SpinnerUpdate( "Show" )

If true Then
  // Run the WebThread
  // Run same code as the WebThread
  SpinnerUpdate( "Hide" )
  DetailLoadFlag = false
End If

End [/code]

I’ve tried 2016r3 and 2016r4b4. Both result in the same problem. It doesn’t happen every time I click on a contact, but definitely 20 or less clicks. Usually less than 8 clicks.

I’m seeing two types of errors as you can see in the following video. One is the Javascript Null Is Not an Object and the other is the SessionNotAvailableException.

Here’s the project:

I just tried the beta from today and I’m getting “Could not execute returned javascript: null is not an object (evaluating ‘this.object().children’)” when I use a WebThread.

If I run the same code without the WebThread, it works fine.

I tried compiling my app, but it still results in a “Javascript Null Is Not an Object”.

@Greg O’Lone ,

Are you able to reproduce the errors that I show in my vid/project linked three posts above this post?

[quote=297947:@Hal Gumbert]@Greg O’Lone ,

Are you able to reproduce the errors that I show in my vid/project linked three posts above this post?[/quote]
I’ve been looking at this a little every day, mostly to see if I can come up with a way to reliably reproduce it on every click. So far nothing has jumped out at me.

Thanks for the update Greg! Does that mean you can reproduce it, but not every time?


Whew, I thought I was going insane.

So I just did a line-level analysis of this app, trying to figure out what’s going on. The javascript error you’re getting is because there are commands being sent to the browser for one type of control when the control on the browser is of a different type. (commands are for a Button, but the control is actually a popupMenu). I’m guessing that the framework is reusing control IDs too soon and when a user clicks through these items quickly, things get very confused. I’m looking into adding an expiration date to the cache so control IDs will take longer to expire.

Also, if you look in Xanadu.ListboxCellLoad, you’re pushing the results of CacheListBoxJS into an array that you use later. That could cause problems in this same scenario because the javascript you’re creating is specific to a particular control ID. You at least need to add a bit of code to make sure tbody exists before using it.

Wow! That’s super low level and difficult to find. You and Xojo freaking rock! I’d love to test it out when you think you have it squashed.

The CacheListBoxJS isn’t being used anymore or shouldn’t be. I was using that to inject images in a listbox cell. I’ll update Xanadu in GitHub this morning where that code is ripped out.

Thanks you so much for your persistence!