-
-
Notifications
You must be signed in to change notification settings - Fork 908
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
Cannot use ref functions after the dependency of a provider changed but before the provider rebuilt
occurs under certain conditions
#815
Comments
Hello! Without a way to reproduce this, I have no means to K ow if that error is expected or not |
I'm sorry, but I'd like to add a note when I can make a reproducible code 🙏 |
Faced the same issue. Last working version for me is 1.0.0-dev.7 |
This error was added on purpose recently. Please add a way to reproduce the issue, otherwise chances are this is expected. |
For information: This happens typically happens if you're using It could be that you're using a final provider = FutureProvider((ref) {
ref.watch(foo);
await something();
ref.watch(bar);
}) But during the |
I had the same problem. I've implemented a minimum of reproducible code, can you check it please? hooks_riverpod: 1.0.0-dev.11 ❯ flutter --version
Flutter 2.5.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 18116933e7 (11 days ago) • 2021-10-15 10:46:35 -0700
Engine • revision d3ea636dc5
Tools • Dart 2.14.4 ControlRoom-2021-10-26-19-45-53.mp4 |
Thanks for the reproducible code Interestingly:
|
Thanks for checking. |
My app uses the latest version of riverpod on master branch, but it sometimes throws this error :( |
@tomoyuki28jp could you share a way to reproduce the problem in your case? I don't have the issue on master. |
Facing the same issue randomly on 1.0.0-dev.11. But seems to be fixed on master branch edit: Just happened again on master branch :/ was working fine on dev 7. No await in the provider code |
With #815 (comment) code and this, the error occurs on 1.0.0 stable release. void main() {
runApp(
const ProviderScope(
child: MaterialApp(
home: FirstScreen(),
),
),
);
}
The error message is |
my issue #831 no longer exists. maybe your issue and mine are not the same |
I see same exception. For my use case, the exception happens only once while redirecting to a path with go_router while app alive. Here is to reproduce the exception below. chunghha/fl_pages@7c08ec5 I may be probably missing to check something so keep digging in but also I'd like to share for a help. Performing hot restart...
Restarted application in 571ms.
flutter: GoRouter: known full paths for routes:
flutter: GoRouter: => /
flutter: GoRouter: => /polygon
flutter: GoRouter: => /login
flutter: GoRouter: setting initial location /
flutter: |.. _routeToPath: /
flutter: \.... _authStatus: AuthStatus.unauthenticated
flutter: GoRouter: redirecting to /login
flutter: |.. _routeToPath: /login
flutter: \.... _authStatus: AuthStatus.unauthenticated
flutter: |.. _routeToPath: /login
flutter: \.... _authStatus: AuthStatus.unauthenticated
flutter: token 0002BIhGyCWXtb0YpIeRvED8TZ6R
flutter: \^[[38;5;12m┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────<…>
flutter: \^[[38;5;12m│ #0 printAppVersion (package:fl_pages/util/app_version.dart:12:13)<…>
flutter: \^[[38;5;12m│ #1 <asynchronous suspension><…>
flutter: \^[[38;5;12m├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄<…>
flutter: \^[[38;5;12m│ 💡 App Version: 1.1.0+1.1.0<…>
flutter: \^[[38;5;12m└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────<…>
flutter: GoRouter: going to /
flutter: ══╡ EXCEPTION CAUGHT BY FLUTTER FRAMEWORK ╞═════════════════════════════════════════════════════════
flutter: The following _Exception was thrown Exception during GoRouter navigation:
flutter: Exception: 'package:riverpod/src/framework/provider_base.dart': Failed assertion: line 645 pos 7:
flutter: '_debugDidChangeDependency == false': Cannot use ref functions after the dependency of a provider
flutter: changed but before the provider rebuilt
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #2 ProviderElementBase._assertNotOutdated (package:riverpod/src/framework/provider_base.dart:645:7)
flutter: #3 ProviderElementBase.watch (package:riverpod/src/framework/provider_base.dart:691:5)
flutter: #4 appRouter.<anonymous closure>.<anonymous closure> (package:fl_pages/app.router.dart:49:15)
flutter: #5 GoRouterDelegate._getLocRouteMatchesWithRedirects (package:go_router/src/go_router_delegate.dart:323:22)
flutter: #6 GoRouterDelegate._go (package:go_router/src/go_router_delegate.dart:249:21)
flutter: #7 GoRouterDelegate.go (package:go_router/src/go_router_delegate.dart:149:5)
flutter: #8 GoRouter.go (package:go_router/src/go_router.dart:78:22)
flutter: #9 GoRouterHelper.go (package:go_router/go_router.dart:32:25)
flutter: #10 goToPage (package:fl_pages/app.router.dart:87:11)
flutter: #11 LoginButton.build.<anonymous closure> (package:fl_pages/widgets/login_button.widget.dart:39:11)
flutter: <asynchronous suspension>
flutter: (elided 2 frames from class _AssertionError)
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
flutter: GoRouter: known full paths for routes:
flutter: GoRouter: => /
flutter: GoRouter: => /polygon
flutter: GoRouter: => /login
flutter: GoRouter: setting initial location /
flutter: |.. _routeToPath: /
flutter: \.... _authStatus: AuthStatus.authenticated
flutter: GoRouter: refreshing /
flutter: |.. _routeToPath: /
flutter: \.... _authStatus: AuthStatus.authenticated
flutter: |.. _index onTap: 1
flutter: GoRouter: going to /polygon
flutter: |.. _routeToPath: /polygon
flutter: \.... _authStatus: AuthStatus.authenticated
flutter: |.. _index onTap: 0
flutter: GoRouter: going to /
flutter: |.. _routeToPath: /
flutter: \.... _authStatus: AuthStatus.authenticated
Application finished. |
I have my fix |
For reference, this should be fixed in the 2.0.0 dev release. |
Do you know where I can find the notes for 'package:riverpod/src/framework/provider_base.dart':
Failed assertion: line 657 pos 7: '_debugDidChangeDependency == false':
Cannot use ref functions after the dependency of a provider changed but before the provider rebuilt |
@pcelis19 Please provide a way to reproduce your issue. As mentioned before it could very well be that it's your code the problem |
This worked for me thank you |
For me, I noticed that i was using
Was to be used instead of
|
What should i do in this case? |
Describe the bug
After 293cc06 was released,
Cannot use ref functions after the dependency of a provider changed but before the provider rebuilt
occurs under certain conditionsTo Reproduce
It reproduced on our internal project, and I haven't been able to create a simple reproducible sample code yet 🙏
I observed this:
ref.watch(fooProvider);
is called_dependents
hasthis
: https://github.com/rrousselGit/river_pod/blob/3a4637025ca9e7f30ee1c61fc9e7976e04415644/packages/riverpod/lib/src/framework/base_provider.dart#L935element.getExposedValue()
inwatch
called: https://github.com/rrousselGit/river_pod/blob/f410a75dc1ae8c665c9db9a4b2bdd63d4b49faa5/packages/riverpod/lib/src/framework/base_provider.dart#L940-L940_dependents[i]
hasthis
and_didChangeDependency()
called: https://github.com/rrousselGit/river_pod/blob/f410a75dc1ae8c665c9db9a4b2bdd63d4b49faa5/packages/riverpod/lib/src/framework/base_provider.dart#L795-L795_debugDidChangeDependency
was set totrue
ref.watch(fooProvider);
endedref.watch(barProvider);
called_debugDidChangeDependency
was set to true: https://github.com/rrousselGit/river_pod/blob/f410a75dc1ae8c665c9db9a4b2bdd63d4b49faa5/packages/riverpod/lib/src/framework/base_provider.dart#L860-L860Expected behavior
Works fine without any errors.
The text was updated successfully, but these errors were encountered: