-
-
Notifications
You must be signed in to change notification settings - Fork 942
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
Nested ProviderScope fix breaks family providers(?) #2480
Comments
I managed to create a small sample reproducing this. Run this app, click on the buttons to switch page. The first switch to a new page works fine, but once you go back to a previous page things quickly break and stop updating.
Doing the same with Riverpod 2.3.3 works fine. EDIT: Note the provider override! Without that, thing seem to work. |
I think it's regression. The following test would suffice. test(
'when cancel autoDispose family override it should be disposed immediately',
() async {
final provider = Provider.autoDispose.family<int, int>((ref, _) => -1);
var constructionCount = 0;
final override = Provider.autoDispose.family<int, int>((ref, _) {
return ++constructionCount;
});
final root = createContainer();
final container = createContainer(
parent: root,
overrides: [provider.overrideWithProvider(override)],
);
var count = container.read(provider(0));
expect(count, 1);
await container.pump();
count = container.read(provider(0));
expect(count, 2);
}); |
Can you test if the above PR resolves the issue? |
I've now done some testing of the PR and from what I can tell, it fixes the problem! |
Oh, I didn't realize that fea8a96 changed the if condition. I was confused why the proposed PR was related to the problem, but it seems to simply revert the involuntary condition change. So LGTM. |
Describe the bug
Commit fea8a96 seems to have broken a lot of providers in our app.
For now I can say that it looks like rebuilds aren't being triggered for ConsumerState instances that are using ref.watch() in their build methods even though the watched provider is changed.
In this instance, the underlying provider is a StateNotifierProvider with
autoDispose
andfamily
, where we are switching thefamily
parameter as we switch pages in the app. The StateNotifier holds aList<DataItem>?
that is initiallynull
, but later updated with a value. Only the Widget on the initial "page" shows list items. Once we switch to a new page (using a new family argument) the new Widget only shows the provided value as beingnull
, even though it does get updated once data is fetched (which should trigger a rebuild).Sorry for the vagueness of this report, I'm still investigating and will provide more details if I figure anything out.
To Reproduce
<Please add a small sample to that can be executed to reproduce the problem. As a general rule, 100 lines is the maximum>
Expected behavior
ConsumerState should rebuild when watched provider changes.
The text was updated successfully, but these errors were encountered: