-
-
Notifications
You must be signed in to change notification settings - Fork 961
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
Invalid argument: Maximum call stack size exceeded (bug in dart compiler) #1713
Comments
I have been able to pinpoint where the error is occurring. It appears that if I am watching a provider in more than one place within the same widget, and the provider is using .autoDispose, then it will result in the error. Removing .autoDispose fixes the issue. As I said, this is only happening on Flutter web. After "fixing" that, I noticed the same issue was occurring when I called .listen on a provider, regardless if it had .autoDispose added to it. Calls This
Gets This
|
It appears that if I am watching any provider with an .autoDispose that it is giving me this error. Flutter Web |
I'm facing the same issue |
I am having the same issue. I have a sample app here with it failing. https://github.com/JulianSwales/test_web |
|
I confirm the same. Facing the issue on web with versions |
From git-bisect the breaking commit was this one: Note that this could be an issue with dart's web compiler and not a problem with riverpod. We'll have to try to figure out a smaller example (ideally without the flutter dependency, and likely without all of the riverpod machinery) if we want the dart team to quickly resolve the issue if it is a problem with the dart compiler. A minimal reproduction flutter riverpod sample, taken from the flutter riverpod example (just changing the provider to autoDispose). import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
// A Counter example implemented with riverpod
void main() {
runApp(
// Adding ProviderScope enables Riverpod for the entire project
const ProviderScope(child: MyApp()),
);
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(home: Home());
}
}
/// Providers are declared globally and specify how to create a state
final counterProvider = StateProvider.autoDispose((ref) => 0);
class Home extends ConsumerWidget {
const Home({super.key});
@override
Widget build(BuildContext context, WidgetRef ref) {
return Scaffold(
appBar: AppBar(title: const Text('Counter example')),
body: Center(
// Consumer is a widget that allows you reading providers.
child: Consumer(
builder: (context, ref, _) {
final count = ref.watch(counterProvider.state).state;
return Text('$count');
},
),
),
floatingActionButton: FloatingActionButton(
// The read method is a utility to read a provider without listening to it
onPressed: () => ref.read(counterProvider.state).state++,
child: const Icon(Icons.add),
),
);
}
} |
The dart web-simple template with the following reproduces the error. import 'dart:html';
import 'package:riverpod/riverpod.dart';
void main() {
final container = ProviderContainer();
final value = container.read(stringValue.state);
querySelector('#output')?.text = 'Your ${value.state} app is running.';
final _ = container.listen(stringValue.state, (_, value) {
querySelector('#output')?.text = 'Your ${value.state} app is running.';
}, fireImmediately: true);
}
final stringValue = StateProvider.autoDispose((ref) => 'Hello world');
|
It is reproducible without flutter using the dart web-simple template and the following snippet: import 'dart:html';
import 'package:riverpod/riverpod.dart';
void main() {
final container = ProviderContainer();
final value = container.read(stringValue.state);
querySelector('#output')?.text = 'Your ${value.state} app is running.';
final sub = container.listen(stringValue.state, (_, value) {
querySelector('#output')?.text = 'Your ${value.state} app is running.';
}, fireImmediately: true);
container.read(stringValue.notifier).state = 'Hello changed';
sub.close();
}
final stringValue = StateProvider.autoDispose((ref) => 'Hello world'); My guess is that without actually disposing the provider, the dart compiler optimizes out all of the related code from riverpod, thats why @TimWhiting s snippet worked. The error / stack trace is:
So it seems like the js |
Thanks for that @schultek, I actually just realized that I was on the commit prior to the breaking commit when testing the webdev snippet. Was able to reproduce, with just the read on the container. Filed dart-lang/sdk#50119, since I believe it is a web compiler issue. |
While creating the dart issue, I found that I don't get this error for an AOT web build. |
I found a non-riverpod snippet that reproduces the issue, which I added to the ticket. So this can possibly be closed. |
Thank you all for your investigation. That pure Dart example posted in the related issue is quite a funky one. |
Flutter Web: |
I can confirm what everyone else is saying. Using I understand that this is a Dart SDK issue. Though presumably the next Dart stable release could be months away and as it stands all apps using What is the recommended "patch" for now? Revert to Riverpod 2.0.0-dev.9 or wait for a new minor release with a workaround? |
Well first it'd be nice to have a reply from the Dart team. It's a bug. So it doesn't have to take months to be released. It could be cherry-picked. |
In the meantime, everyone please add a thumbs up to the linked dart issue, to help them prioritize this for a fix and cherry pick. @schultek Even though this is a dart issue I think we should leave this issue open to make it easier for Riverpod users to find so we don't get duplicate issues opening. |
Here's the minimal code (if anyone was looking for) I get the error when I use void main() => runApp(ProviderScope(child: MaterialApp(home: FooPage())));
class FooPage extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
ref.watch(fooProvider);
return Container();
}
}
final fooProvider = FutureProvider.autoDispose<int>((ref) => Future.value(0)); |
For what it is worth, I only had this bug when in debug on web. Release mode seemed to be not affected. |
same here ;) |
Can confirm that this is only an issue when running the app in DEBUG mode. When I run it in RELEASE mode, I do not get the error. |
Here's the minimal code (if anyone was looking for) I get the error when I use autoDispose on either the FutureProvider or StreamProvider
|
UPDATE: FAIL I have a same issue.
To:
|
That doesnt fix it, at least not on my machine. We run 2.17 for a long time and that issue is there since last upgrade |
I added a PR for a fix. I think the fix can be used until the dart team officially fix the issue. |
Edit: This is a dart web compiler bug, only for the debug web compiler, you can get around it by developing on desktop and testing / deploying a release build on web.
Upvote this issue: dart-lang/sdk#50119
Describe the bug
Getting this error for Flutter web with Riverpod version 2.0:
Version 1.0.3 worked fine on web, but using version 2.0 seems to be giving me this error.
No issues found on Android/iOS. Just web so far.
To Reproduce
I am not really sure how to reproduce this for the provider file is quite lengthy. I am actively looking for the source but thought I should post this for the time being.
The text was updated successfully, but these errors were encountered: