With firebase firestore I am used to the library h...
# javascript
With firebase firestore I am used to the library handling the tab being idle so that when the user comes back, realtime info gets fetched and updated automatically. This doesn't happen with supabase-js Does anyone knows if there is just something I am missing like a setting? Or I just need to wait for supabase-js to be improved over time, as it still is in beta
I assume you are referring to firebase snapshot. Also not sure what your definition of "idle" browser tab is. Realtime only reports row changes from the time you subscribe. It uses a websocket and they keep running on idle browser tabs if the the browser is left open and you go to other tabs. Once you close the browser or lose connection for an extended period you have to resubscribe and probably reload table data. Normally when your tab/app/page starts up you have to fetch existing rows of a table you plan to monitor and then the realtime subscription will let you know of changes from that point on as long as the browser is running online. Firebase has an entire caching scheme that snapshot needs to work with (assuming not using the lite version which does not support snapshot) and Supabase has very lite client side code and does no local caching. I've been able to reproduce my Firebase app on Supabase fairly easily, but do have to do my own caching for minimal offline use.
As far as future features, I don't know, but I'm skeptical anything like snapshot is in the works short term based on technology just to pull off realtime on a Postgres database. Although I guess most of the work would be in new client code.
It's likely that Firebase use the page visibility API: https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API Most browsers stop running JS on tabs some time after they go into the background in order to conserve battery life and reduce the performance hit caused by tabs a user isn't looking at. In some situations, they will also reduce the amount of network traffic they process, and many ways around this involve using web-workers (which are able to remain persistent but have their own set of technicalities to contend with). Firebase likely use either the page visibility API, or a web worker, or a combination of both. I'm not 100% sure on the internals, but it's probable that Firebase store a hash of the latest data that was sent via realtime and then when the page/tab becomes active again, it'll send a request to compare the stored hash against a hash hosted on the server-side. If they're different, it'll have a mechanism to retrieve the latest data. You could potentially build something like this yourself - add a Postgres trigger that generates a hash based upon some unique values (e.g. the epoch in ms along with the contents of the record that's inserted) each time a record is inserted, and store this in a dedicated table - perhaps have 1 row for each table in your DB.
thanks for the help yeah, I think that checking the time of the last update received and then running some process to fetch the missing ones should do the trick.