Updating of localStorage is NOT being saved after AppStudio restart


#1

TestLocalStorage.nsx (25.1 KB)
When the attached test program is run, line 47 (when activated) will print 4 'null’s… which is correct, since no localStorage was available at the start of execution.

If you run it again, without closing AppStudio, and click on one or more of the buttons, the buttons will alternate between white and green… which is correct…

Leave a couple of them green… Line 47 will continue to print out the contents of localStorage… e.g., if you leave buttons 0 and 2 green and 1 and 3 white, the print out will be g w g w in four lines… which is correct.

Run the program again, without quitting AppStudio, and the button will show green, white, green, white… this is correct.

Now quit AppStudio, reopen it, and run the program… all buttons will be white, even though the localStorage (based on line 47 printout) says they should be green, white, green, white. So what happened to localStorage as a result of closing and opening AppStudio?

Tom
PS: Running latest version of AppStudio, Windows 10, Chrome (not tested on iPad nor Android yet.)


#2

Good news, your code is fine and AppStudio is fine.

You may notice that when you deploy to the Desktop, the URL in the browser may look like this:

http://127.0.0.1:51634/TestLocalStorage/

Then, when you close AppStudio and restart it to deploy to Desktop again, the URL port number has changed to something else, such as this:

http://127.0.0.1:51791/TestLocalStorage/

This is normal, and is why your LS vars don’t appear to be saved. They actually have persisted as they should, but over at the first URL, not this new one, which is essentially a new server address. You can enter the “old” URL and you’ll see them there. You’ll also get an AppStudio “Update Unsuccessful: cache error” message, but that’s because of the way AppStudio interacts with the localhost.

All that to say, if you were to deploy to a real server made using a persistent URL, your LS vars will be retained.

I’ll mention here, in case George is reading this, that there appears to be a false positive error in AppStudio’s interpreter at line 10:

FavArray(i)=localStorage.getItem(i)

It returns “Bad Assignment” but runs fine and appears to be valid code. This has nothing to do with your question but may be something George would want to address.

Kind regards,
Doug


#3

Hi Doug… thank you so much for taking the time to respond, and clarification of what is happening.

I have not tested this on Android or iOS… I suspect the same problem will arise, but worth a test.

Is there any documentation on how to “…deploy to a real server made using a persistent URL…”?

Given the problem of non-persistent URL, I don’t understand how LocalStorage could ever be used in an app?

BR… Tom


#4

The non persistent URL only happens when you use the Start in Desktop Browser feature. If you deployed to Volt or to a local folder, this won’t happen.

http://wiki.nsbasic.com/Preferences


#5

Thanks, George… Deploying to Volt solves the problem… The issue, and it’s resolution (using Volt of local folder) would be a useful addition to the write-up on LocalStorage.

Tom