bloc
bloc copied to clipboard
fix: hydrated bloc stopped persisting state after update (^9.1.3)
Description Hydrated bloc stopped persisting and restoring states after I updated beyond v9.1.0. When I lock in v9.1.0 in my pubspec.yaml, it works fine but when I let it run to the max possible version using "^", it does not work.
Steps To Reproduce
- Test state persistence using hydrated_bloc: ^9.1.0
- Compare with state persistence using hydrated_bloc: 9.1.0
Expected Behavior State should correctly persist.
Additional Context I get null data from persistence using hydrated_bloc: ^9.1.0
+1, My app seems to persist with 9.1.2 but not with 9.1.3
Sorry for the delay! I'll investigate and try to get a fix in by the end of the week, thanks!
@JoseGeorges8 @devopsean I tried to reproduce and was unable. Are either of you able to provide a link to a minimal reproduction sample with detailed steps to reproduce the error (e.g. what platform you're running on what host machine you're using, what version of flutter/dart etc)? Thanks!
@felangel Steps to reproduce the error:-
- Use hydrated_bloc: 9.1.2
- Hold isLoggedIn flag in a bloc which uses HydratedMixin to store the data.
- Refer isLoggedIn flag whenever user access the application and route him to home-screen if it is true or login-screen if it is false.
- Now update hydrated_bloc version to 9.1.3 and then check. In 9.1.2 it works as expected but in 9.1.3 it routes user to login-screen all the time.
Platform: Web, Android and iOS.
Mac OS: 14.2.1 (23C71)
VS code: 1.85.2 (Universal)
Flutter and Dart version: Flutter 3.10.5 • channel stable Dart 3.0.5 • DevTools 2.23.1
@JoseGeorges8 @devopsean I tried to reproduce and was unable. Are either of you able to provide a link to a minimal reproduction sample with detailed steps to reproduce the error (e.g. what platform you're running on what host machine you're using, what version of flutter/dart etc)? Thanks!
Flutter 3.16.0 • channel stable • https://github.com/flutter/flutter.git Framework • revision db7ef5bf9f (10 weeks ago) • 2023-11-15 11:25:44 -0800 Engine • revision 74d16627b9 Tools • Dart 3.2.0 • DevTools 2.28.2
Mac OS: 13.5.1 (22G90)
Android Studio Giraffe | 2022.3.1 Patch 2
Thanks, I'll try to reproduce with the Flutter/Dart versions you both provided and get back to you.
@felangel Any update on this?
@Akshay-Niveus i'd really appreciate any reproduction steps as so far I've been unable to reproduce the issue, thanks!
@felangel I was able to reproduce it. It affects HydratedMixin
.
It's not exactly a "bug", but rather a breaking change introduced with https://github.com/felangel/bloc/commit/e2407caf46dd217535816889ea0e6791fdc4ab3c .
Before this commit landed, even though the documentation said to call
hydrate();
in the constructor, the desired behavior would work without calling it (fromJson
was called anyway from the state
getter);
After the commit landed, fromJson
is not called anymore if the user doesn't explicitly call it.
Not sure if a fix is required here? But since it is a breaking change, maybe it would be worth:
- landing a
9.1.6
version that callsfromJson
if the state is null? - marking it as a breaking change for
9.2.0
by saying something along the lines of "previously, HydratedMixin would work without callinghydrate()
, but it is now required"