simolus3 / drift

Drift is an easy to use, reactive, typesafe persistence library for Dart & Flutter.
https://drift.simonbinder.eu/
MIT License
2.66k stars 372 forks source link

drift on flutter web not persisting data #3288

Closed attouab closed 3 weeks ago

attouab commented 1 month ago

I am using drift with flutter web, when I test locally (both release and debug) the saved data is lost when refreshing or opening a new tab. I can see that data is being saved and read from the database, however, I am not sure where the sql lite db file is created and I am not sure whey it is not persisted across different sessions

simolus3 commented 1 month ago

How are you opening the database? The default setup here prints the chosen storage implementation, can you check which one is chosen?

attouab commented 1 month ago

Thanks @simolus3 , it saysit is using WasmStorageImplementation.inMemory, it doesnt report any missing features

attouab commented 1 month ago

it turned out I was missing the drift_worker.js file, and didnt get any error message to warn me about it, now its using WasmStorageImplementation.sharedIndexedDb

dickermoshe commented 3 weeks ago

@simolus3 Should we add a error for this?

simolus3 commented 3 weeks ago

Yes I wanted to look into this - we're listening on errors already so we should have a way to detect this properly.

simolus3 commented 3 weeks ago

I've changed the detection logic to report worker errors explicitly in 97e16fd9d0d527c72436e03a16dae63ccde2bdc2.

I'm not sure if we should actively throw in that scenario. We can probably still use a local IndexedDB database, and WasmDatabase.open is explicitly a "we'll try the best we can do" approach that reports problems without throwing. That means that we can't scream at users when things like the worker are missing, but the docs already mention a possible check for the return value to possibly reject databases where persistence is not possible.