Skip to content
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

IndexedDB instance on Web is not persisted #73

Open
felangel opened this issue Jan 24, 2025 · 4 comments
Open

IndexedDB instance on Web is not persisted #73

felangel opened this issue Jan 24, 2025 · 4 comments

Comments

@felangel
Copy link

Steps to Reproduce
See felangel/bloc#4335 for detailed reproduction steps.

I believe this is because the underlying IndexedDB instance is not configure to be persistent.

You can see a sample at https://flutter-firebase-auth-2b1c3.web.app.

Image

Version

  • Platform: Web
  • Flutter version: 3.27.3
  • Hive version: 2.9.0
@felangel felangel changed the title IndexedDB instance on Web does is not persisted. IndexedDB instance on Web is not persisted Jan 24, 2025
@Rexios80
Copy link
Member

The counter persists for me on that sample in both Safari and Chrome. Am I supposed to be seeing something different?

@felangel
Copy link
Author

felangel commented Jan 24, 2025

The counter persists for me on that sample in both Safari and Chrome. Am I supposed to be seeing something different?

It's an issue when adding packages and re-deploying (then the cached state is lost) but I think it has something to do with the default Flutter service worker. I added more context in the linked bloc issue. When I disabled the service worker (flutter build web --pwa-strategy=none) I was no longer able to reproduce the issue so I think we can close this 🤷

In general though it might be nice to document how hive_ce will handle persistence on web (what the durability is and whether the database will be guaranteed to be persisted or not). It seems like the database is not guaranteed to be persisted and as a result it's probably not suitable for cases when the application relies on stored data being there in subsequent loads.

@Rexios80
Copy link
Member

I think that "Is persistent" field is related to this: https://developer.mozilla.org/en-US/docs/Web/API/StorageManager/persist

Maybe I could try enabling it in hive?

Web data in general is not guaranteed to persist

@Rexios80
Copy link
Member

Try this code and see if anything changes: #74

I can't get persistence to enable on localhost, but maybe it works on a deployed site

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants