Random TypeError: Cannot read properties of undefined (reading 'datastore1')

Hello. Me again.

Got a new TyperError
No issue with the saving or save-all.

I was going to work with updating datastore1 to add a new var to save.

That was about 2 hrs prior.

Now, returning to the datastore1 issue. Upon clicking on datastore1 is when it produced the below TypeError and the datastore1 had an infinite spinner.
I cannot do anything with datastore1 without rebooting.

Just a observation - Everytime this happens, it has something to do with :

dmxAppConnect_inspect_lib.js
dmxNWApiBridge.js


THis also brought another "posted" bug.
its missing the vars from the list but still works --- I saw post that describe it only as UI data (i'll find that post and just amend). Since it was missing the vars, i did something else.

TypeError: Cannot read properties of undefined (reading 'datastore1') at evalmachine.<anonymous>:1:1037717 at Object.callback 
(file:///C:/Users/XXXXXX/AppData/Local/Wappler%20Beta/resources/app/Shared/DMXzone/dmxAppCreator/UI/dmxAppConnect/dmxAppConnect_inspect_lib.js:46:7) at dmxDWApiBridge.applyCallback 
(file:///C:/Users/XXXXXX/AppData/Local/Wappler%20Beta/resources/app/Shared/DMXzone/dmxAppCreator/dmxDWApiBridge/dmxNWApiBridge.js:1:9512) at file:///C:/Users/XXXXXX/AppData/Local/Wappler%20Beta/resources/app/Shared/DMXzone/dmxAppCreator/dmxDWApiBridge/dmxNWApiBridge.js:1:48081 at FSReqCallback.readFileAfterClose [as oncomplete] 
(node:internal/fs/read/context:68:3)

As usual,
Thanks!
JND

@George @patrick
** REPRODUCEABLE STEPS**

I wanted to dump a var from the datastore1

So, just for HA HA's I created a textarea
in the properties, added a dynamic attribute for Value.
Clicked the dynamic value picker
pick datastore1
BOOM :boom: Error!

Every single time i close and restart this result happens.

Hope this help :smile_cat:
JND

Does your datastore has schema defined?

Sorry for late response @George I was away with family.

Yes, the datastore schema was defined.

Matter fact each time this happen the schema was suddenly wiped out.
I removed, added, did as much housekeeping possible but it did the same.

I moved to just saving into a sqllite db for now.
(needing the page to work in an offline mode when it goes into production)

Thanks
JND

I don't think that a Datastore is the way to go. What you need is the long (by @George) promised Service Worker.

A basic example of a Service Worker:

self.addEventListener('install', event => {
    event.waitUntil(
        caches.open('offline-cache').then(cache => {
            return cache.addAll([
                '/',
                '/index.html',
                '/styles.css',
                '/app.js'
            ]);
        })
    );
});

self.addEventListener('fetch', event => {
    event.respondWith(
        caches.match(event.request).then(response => {
            return response || fetch(event.request);
        })
    );
});

You might need to synchronize data between the local storage (cached data) and the database when the connection is restored.

For more, see

and

1 Like

Hi Ben! (B.T.W loved the nudge to G'man :slight_smile: )

I looked into that a bit - but i am barely at that level - I'm sure I could figure it out eventually.

One of the goals was to limit external JS and - so stay as native Wappler as possible.

I was using Couch/Pouch because of that very behind-the-scene feature - sync'ing when a connection returned. Had to move to MySQL due to deployment issues in Linux using Wappler + Couch. -- I had it working great too.
Then the datastore battle I've been having.

Although, that example code did give me some ideas that maybe a SW might not be so hard after all.

It makes one excited to stay engaged with development when a community like this does their best to help!!! (was that sappy?)

Thanks a lot Ben !

Cheers
JND

1 Like

@ben could you post a separate feature request about service workers with more details and use cases? Not only caching use cases but also other use cases like keeping data in sync or preloading assets? Push events?

All in relation of browser support and how it will fit Wappler exactly.

Also for caching there are many strategies:

and many do's and don'ts that the user should take into account to avoid common pitfalls.

The current service worker implementation in the browser is only useful for caching (offline usage) and push notifications. Syncing data is still not good supported, the sync api is currently only available in chrome/edge. Couch/Pouch is still the best way for syncing data between client and server.

1 Like

According to this article:

We achieve this background synchronization (Post data when internet connection is back) with help of service workers and Indexed-DB.

I will post a feature request once I gather all of the information and tried it out for myself.

So far, I have only created simple PWA's, mainly for the cache and secondly to have an install-app button which my clients love. I have not explored push notifications, or any of the other goodies that come with modern PWA's.

Browser support is huge 97.4% as per:

I think that PWA's are App killers, as they use the languages that we are used to, while they eliminate having to create 3 different apps. Just the one.

Publishing the PWA is a sinch when using

I could go on for hours, but I will leave it at this for the moment. Please give it some thought.

1 Like

Hi patrick,
A comment regarding Couch/Pouch + Linux

This was using Ubuntu Desktop 24.04 and 24.10

I did post in the bug section about how Wappler wont deploy C/P from the resources menu - Even a remote connection was sketchy ... Did the add service -> database -> Couch/Pouch and it would really never complete pulling an image .. docker just did this infinite loading loop (not even timeout).

On Windows i had/have a working beta with Couch/Pouch and it did exactly what i wanted. Sync'd when the device got a connection.

Then the datastore TypeError(s) and it loosing its schema problem.

I'll fiddle with sessions or cookies - something will eventually work.

Cheers
JEFF

P.S Sorry i know few topics at least got discussed here but they all sorta relate.