Replies: 2 comments
-
There are a few dangers with having it Say you keep the user ID in a provider, and you have a FutureProvider watching that userIdProivder to do some network requests. Such that when the user ID changes, the FutureProvider automatically updates through ref.watch. In that scenario, having the reload flag to true by default could cause possible security concerns. To avoid possible problems like this, the flag is opt-in on purpose.
That's expected. In the latter case, a dependency of the provider changed. As such, it's a reload, not a refresh. That's the whole point of the different between "reload" vs "refresh"
That isn't the case. Both would emit Your sample isn't showcasing a dependency change. Your StreamProvider didn't rebuild. In the end, if you want to have the flag on by default, you're free to make an extension on extension<T> on AsyncValue<T> {
R myWhen<R>({
required R Function(T data) data,
required R Function(Object error, StackTrace stacktrace) error,
required R Function() loading,
}) {
return when(skipLoadingOnReload: true, data: data, error: error, loading: loading);
}
} |
Beta Was this translation helpful? Give feedback.
-
Thanks for your response. I now better understand why the flag is set to false by default 🧑🎓 |
Beta Was this translation helpful? Give feedback.
-
skipLoadingOnReload should be set to TRUE by default
It's not really a bug, but rather a design improvement.
In the preview version
2.0.0-dev.0
you introduced the propertyisRefreshing
toAsyncData
. Witch is freaking awesome 🎉 !This version was in active development, and you changed the internal behaviour. Now
AsyncLoading
can hold data.If user define a unique
FutureProvider
, this was not a problem. When theFutureProvider
is refreshed or invalidated, it will emit anAsyncData
and the propertyisRefreshing
will betrue
.But, if the
FutureProvider
depends on an otherProvider
and this one is refreshed, then theFutureProvider
will first emit aAsyncLoading
and then anAsyncData
.To let users know when the data is reloading you added the argument
skipLoadingOnReload
to thewhen
method ofAsyncValue
.I think that this design has a few caveats:
.when
has more functionalities that.map
.AsyncValue
getters relie on.map
and not.when
.skipLoadingOnReload
should be set tofalse
. So I have to setskipLoadingOnReload = true
every time I use anAsyncValue
.I have also found two inconsistencies caused by this design.
Refreshing and Reloading do not share the same behaviour
Refreshing a Future provider doesn't not emit a new
AsyncLoading
. But refreshing a provider on which the future provider depends emits a newAsyncLoading
.Stream and Future providers do not share the same behaviour
AsyncData
.AsyncLoading
.This can lead to tricky bugs when refactoring code, following the depreciation of the
.stream
property.Exemples:
In this repo, there are exemples of those two problems.
Both problems are illustrated using Riverpod version 2.0.0-dev.0 and 2.3.4.
Expected behaviour
Riverpod rocks 🤘
Thanks for all the work you put in this project.
Beta Was this translation helpful? Give feedback.
All reactions