Repository navigation
Description
Flutter Web Debug Stack Overflow with Large MultiBlocProvider Configuration
Summary
We are experiencing a stack overflow / call-stack exhaustion issue in Flutter Web debug mode when running our application with a large number of globally registered BlocProvider / Cubit instances through MultiBlocProvider.
The application works as expected on mobile platforms, but Flutter Web debug mode can fail during application startup/navigation with a stack overflow in the browser renderer.
We would like to understand whether this behavior is related to the interaction between the BLoC package's MultiBlocProvider implementation and the Flutter Web debug runtime.
Environment
Flutter
Flutter 3.47.2 • channel stable
Framework • revision d3b14c8769 (2026-08-26)
Engine • revision a804b26164
Dart 3.13.2
DevTools 2.60.0
Application
Platform: Flutter Web
Build mode: Debug
Browser: Google Chrome
State management: flutter_bloc
Application State Manager Audit
- 107 BLoCs
- 12 Cubits
- 119 total state managers
Problem Description
The application contains a large root-level MultiBlocProvider configuration.
Conceptually, the application has a structure similar to:
MultiBlocProvider(
providers: [
BlocProvider<BlocA>(...),
BlocProvider<BlocB>(...),
BlocProvider<BlocC>(...),
// ...
// 119 globally registered providers
],
child: MyApp(),
)When running the application in Flutter Web debug mode, we observe a stack overflow/call-stack exhaustion failure.
The failure is particularly noticeable when entering certain screens, including the Login flow.
The affected screens themselves do not appear to contain an unusually recursive widget implementation. The issue appears to be related to the depth of the provider/widget hierarchy created by the large global MultiBlocProvider configuration.
Observed Behavior
Flutter Web Debug
Application starts
↓
Large MultiBlocProvider hierarchy
↓
Navigate/open affected screen
↓
Deep call stack
↓
Stack overflow / renderer failure
Mobile
The same application architecture does not reproduce the issue in the same way on Android/iOS.
Web Release
The issue also appears to be specific to the Web debug/runtime environment rather than being a general BLoC functionality failure.
Investigation Performed
We investigated the application architecture and performed a BLoC/Cubit usage audit.
We also temporarily reduced the number of globally registered providers and removed several unused/dead BLoCs.
After reducing the global provider count, the Web debug application became stable.
This indicates that the depth/size of the provider hierarchy is likely a significant contributing factor.
However, we do not consider the reduced provider count to be a definitive threshold or permanent solution.
Related Issue
We found a closely related BLoC issue:
The issue reports a similar Flutter Web stack overflow scenario with a large number of globally initialized BlocProviders. The reported application had 250+ providers, and reducing the provider count resolved the problem.
Our application currently has 119 providers registered through MultiBlocProvider, so the behavior appears potentially related to the same class of provider-tree/call-stack issue.
We understand that this does not establish a fixed provider-count limit, and we are not assuming that the two issues have exactly the same root cause.
Expected Behavior
A large MultiBlocProvider configuration should ideally not result in an unrecoverable stack overflow in Flutter Web debug mode.
If there is a practical limitation related to provider-tree depth, we would appreciate clarification on:
- Whether there is a known limitation with deeply nested
MultiBlocProviderconfigurations on Flutter Web. - Whether
MultiBlocProviderintroduces additional widget/element nesting for every registered provider. - Whether there is a recommended architectural approach for applications with a large number of BLoCs/Cubits.
- Whether the current behavior is expected to be handled by
flutter_bloc, Flutter Web, or another underlying dependency. - Whether there are any recommended optimizations to avoid excessive call-stack depth.
- Whether this behavior is known to be affected by Flutter Web debug compilation/runtime behavior.
Requested Investigation
Could the maintainers please investigate whether a large number of providers in MultiBlocProvider can cause excessive call-stack depth in Flutter Web debug mode?
If possible, we would also appreciate guidance on whether this should be addressed within flutter_bloc or whether the limitation originates from the Flutter Web/Dart debug runtime.
Potential Workaround
Our current workaround is to avoid registering all feature-specific BLoCs globally.
We are considering moving feature-specific BLoCs/Cubits to route/page-level scopes, for example:
MyApp
└── Global MultiBlocProvider
├── AuthenticationBloc
├── AppConfigurationBloc
└── Other application-wide state
Routes
├── Dashboard
│ └── DashboardBloc
│
├── Device
│ ├── DeviceBloc
│ └── DeviceSettingsBloc
│
└── Reports
├── ReportsBloc
└── ReportFilterCubit
This reduces the number of globally nested providers while keeping feature-specific state scoped to the feature that actually requires it.
References
- BLoC GitHub Issue MultiBlocProvider causes stack overflow issue on web #4781:
MultiBlocProvider causes stack overflow issue on web #4781 - BLoC Flutter Concepts:
https://bloclibrary.dev/flutter-bloc-concepts/ - Flutter Web documentation:
https://docs.flutter.dev/platform-integration/web - Dart Dev Compiler:
https://dart.dev/tools/dart-dev-compiler
Activity
[-]# Flutter Web Debug Stack Overflow with Large MultiBlocProvider Configuration[/-][+]Issue: Flutter Web Debug Stack Overflow with Large MultiBlocProvider Configuration[/+]GhagSagar23 commentedon Nov 19, 2026
Root Cause Analysis
I investigated this and the root cause is in how
BlocProviderinteracts withMultiProvider._collapseProviders.The collapse gap:
MultiProvider(from theproviderpackage) has an optimization called_collapseProvidersthat merges adjacentInheritedProvidersubclasses into a singleSingleChildBuilder, dramatically reducing widget tree depth. However,BlocProviderextendsSingleChildStatelessWidget, notInheritedProvider— so this check fails immediately:Compare:
RepositoryProviderextendsProvider<T>→InheritedProvider<T>, soMultiRepositoryProviderbenefits from the collapse.BlocProviderdoesn't because it wrapsInheritedProviderinternally viabuildWithChildrather than extending it.Why web-debug only:
DDC (Dart Dev Compiler) compiles each Dart method to a separate JS function with full debug info, assertions, and no inlining. Each widget layer in the
Nestedtree triggers Flutter's recursiveElement.rebuild()→performRebuild()→build()→inflateWidget()→mount()chain: ~5-8 JS frames per layer. With 119+ uncollapsedBlocProviders, that's ~600-950 extra stack frames before the app's own widget tree starts — enough to exhaust Chrome's ~984 KB call stack. Release builds (dart2js) survive because aggressive inlining collapses many frames into one.Minimal repro:
I reproduced this locally with a minimal project — two entry points, same provider count:
MultiBlocProviderMultiRepositoryProviderFix:
Opened #4922 — makes
BlocProviderextendInheritedProvider<T>directly (likeRepositoryProviderextendsProvider<T>), so_collapseProviderscan merge them. All 94 existing tests pass.This also relates to #4781 (same class of issue, higher provider count).