-
-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
A way to know if an update has been stored (feedback) #28
Comments
This is news to me. How can I reproduce this? All updates should be stored immediately. A callback should not be necessary. |
Sorry about that, I guess I misunderstood the source code. Apparently this can happen much rarer than I initially thought, but still does. Another thing is to maybe ensure that the changes have been saved to disk. |
y-indexeddb/src/y-indexeddb.js Lines 95 to 98 in 41a5e59
It would be simple to add an |
All updates are stored immediately. The mentioned timeout is only for trimming the updates. Persisting can fail if you close the web-app before the last transaction finishes - this should be extremely unlikely. However, I'd be happy to accept a PR that adds an event. |
Ah, thanks for the correction. Regardless, IndexedDB can be kind of slow. I find myself closing tabs or switching apps before the data gets persisted pretty frequently. I'm considering a synchronous write to localStorage and then flushing to IndexedDB. |
Checklist
[x] Are you reporting a bug? Use github issues for bug reports and feature requests. For general questions, please use https://discuss.yjs.dev/
[x] Try to report your issue in the correct repository. Yjs consists of many modules. When in doubt, report it to https://github.com/yjs/yjs/issues/
Is your feature request related to a problem? Please describe.
Apparently not all updates are guaranteed to be stored (is it itself a bug? This needs to be documented at least). For example, if you do an update and close/reload the tab immediately, it won't show up on the next load.
There's no conventional way to know in what state the document has been stored in
indexedDB
. Has the update that I just made been stored? Is it safe to close the tab now?Describe the solution you'd like
Expose some getter, or method, or add an event (or all at the same time), that lets you determine if the document is stored in indexedDB in the same state as it is in JS right now.
Also I guess this should apply to other persistence adapters (leveldb).
Describe alternatives you've considered
Perhaps additionally a method that upon calling stores the latest update
Additional context
My case:
I'm developing an app that builds the state from a list of updates (like this one). The list is an external thing that persists between page reloads. For performance, I want to store the state of the Y.Doc in browser storage in order to not rebuild it from the list of updates each time. For this I need to remember the index of the last update in the list that has been cached in indexedDB. But I don't know the index because it's not guaranteed that every update made on the doc with the
y-indexeddb
adapter attached will be saved.The text was updated successfully, but these errors were encountered: