-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
fix: HydratedBloc storage doesn't change without closing previous storage #3887
Comments
I guess, it safe to throw error if we try to build storage when already a storage lives (i.e not closed) ?. @felangel |
That seems reasonable. The more user-friendly option in my opinion would be to automatically close the previous storage and register the new storage since that's likely what users would want in this case. Wdyt? |
Well thats what shld be done, am wondering does the user are aware that if they build new storage and existing one would deleted without doing "clear". Since as of now, user may know the only way to delete the storage instance is by doing "clear". Well i agree to clear automatically, but wondering that doesnt bother existing users who are using already. Does this be considered be breaking change. |
Technically it would be but this seems more like a bug since I can't imagine many people would expect/rely on the current behavior. I would personally treat this as a bug fix since the current behavior is incorrect. |
Well agreed to clear the existing one, will write a PR asap and will let u know. Thanks for ur time felix |
Thanks for your time and help as always! 🙏 |
Its been a while we talked about this, the fix am trying to land But as of our current impl, if user already building the multiple storage at same path its not breaking due to the fact we are just handing the same storage instance even if they try to create multiple times. So after this fix, if one might using in this way, the app could break. But this is totally wrong behavior and the right thing is to throw if they using same storages at same path at a same time. What do u think @felangel :/ . Btw, its been so long we talked about this 😂 |
Hi! 👋 Thanks for pointing this out. I see how changing the HydratedBloc.storage variable without closing the previous storage can lead to unexpected behavior, as the state doesn’t reset when switching to a new HydratedStorage. Suggested Workaround As you mentioned, closing the previous storage before creating a new one resolves this issue. You could add an explicit call to close the current storage before assigning a new one:
Proposed Enhancement It would be useful if HydratedBloc.storage either: Implementing one of these approaches would help prevent silent issues and make debugging easier by enforcing best practices around storage management. |
Description
When I try to change the HydratedBloc.storage variable, It won't change, unless I close the previous storage.
Steps To Reproduce
Simple code to reproduce it:
We have to close the previous storage, however If we don't, I think the method should do it automatically or throw an exception.
When nothing changes and no exceptions are thrown, debugging can be difficult.
The text was updated successfully, but these errors were encountered: