Skip to content

Commit

Permalink
fix: Fixed an assert error if a family depends on itself while spec…
Browse files Browse the repository at this point in the history
…ifying `dependencies`. (#1721)
  • Loading branch information
rrousselGit committed Oct 3, 2022
1 parent bdbde9c commit 8c9b02e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/flutter_riverpod/CHANGELOG.md
@@ -1,3 +1,7 @@
# 2.0.2

Fixed an assert error if a `family` depends on itself while specifying `dependencies`.

# 2.0.1

Updated changelog (see 2.0.0)
Expand Down
4 changes: 4 additions & 0 deletions packages/hooks_riverpod/CHANGELOG.md
@@ -1,3 +1,7 @@
# 2.0.2

Fixed an assert error if a `family` depends on itself while specifying `dependencies`.

# 2.0.1

Updated changelog (see 2.0.0)
Expand Down
4 changes: 4 additions & 0 deletions packages/riverpod/CHANGELOG.md
@@ -1,3 +1,7 @@
# 2.0.2

Fixed an assert error if a `family` depends on itself while specifying `dependencies`.

# 2.0.1

Updated changelog (see 2.0.0)
Expand Down
2 changes: 2 additions & 0 deletions packages/riverpod/lib/src/framework/element.dart
Expand Up @@ -600,6 +600,8 @@ The provider ${_debugCurrentlyBuildingElement!.origin} modified $origin while bu

assert(
provider != origin ||
// Families are allowed to depend on themselves with different parameters.
(origin.from != null && listenable.from == origin.from) ||
origin.dependencies == null ||
origin.dependencies!.contains(listenable.from) ||
origin.dependencies!.contains(listenable),
Expand Down
17 changes: 17 additions & 0 deletions packages/riverpod/test/framework/scope_test.dart
Expand Up @@ -300,6 +300,23 @@ Future<void> main() async {
});

group('When specifying "dependencies"', () {
test(
'a family can read itelf, even if not present in the dependencies list',
() {
final dep = Provider((ref) => 'foo');
late final ProviderFamily<String, int> provider;
provider = Provider.family<String, int>(
(ref, id) {
if (id == 0) return ref.watch(dep);
return ref.watch(provider(0));
},
dependencies: [dep],
);
final container = createContainer();

expect(container.read(provider(42)), 'foo');
});

test('auto scope direct provider dependencies', () {
final dep = Provider((ref) => 0, name: 'dep');
var buildCount = 0;
Expand Down

0 comments on commit 8c9b02e

Please sign in to comment.