bloc icon indicating copy to clipboard operation
bloc copied to clipboard

fix: hydrated bloc stopped persisting state after update (^9.1.3)

Open devopsean opened this issue 1 year ago • 10 comments

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

  1. Test state persistence using hydrated_bloc: ^9.1.0
  2. 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

devopsean avatar Jan 08 '24 19:01 devopsean

+1, My app seems to persist with 9.1.2 but not with 9.1.3

JoseGeorges8 avatar Jan 16 '24 14:01 JoseGeorges8

Sorry for the delay! I'll investigate and try to get a fix in by the end of the week, thanks!

felangel avatar Jan 18 '24 06:01 felangel

@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 avatar Jan 19 '24 06:01 felangel

@felangel Steps to reproduce the error:-

  1. Use hydrated_bloc: 9.1.2
  2. Hold isLoggedIn flag in a bloc which uses HydratedMixin to store the data.
  3. 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.
  4. 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

Akshaymain avatar Jan 22 '24 05:01 Akshaymain

@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

devopsean avatar Jan 22 '24 05:01 devopsean

Thanks, I'll try to reproduce with the Flutter/Dart versions you both provided and get back to you.

felangel avatar Feb 01 '24 03:02 felangel

@felangel Any update on this?

Akshay-Niveus avatar May 02 '24 10:05 Akshay-Niveus

@Akshay-Niveus i'd really appreciate any reproduction steps as so far I've been unable to reproduce the issue, thanks!

felangel avatar May 03 '24 15:05 felangel

@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 calls fromJson 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 calling hydrate(), but it is now required"

vincent-hoodoo avatar May 31 '24 04:05 vincent-hoodoo