Repository navigation
fix(flutter_bloc): extend InheritedProvider to enable _collapseProviders - #4922
Open
GhagSagar23 wants to merge 1 commit into
Open
GhagSagar23 wants to merge 1 commit into
GhagSagar23 wants to merge 1 commit into
Conversation
BlocProvider previously extended SingleChildStatelessWidget and created InheritedProvider internally in buildWithChild. This meant MultiProvider._collapseProviders skipped BlocProviders entirely (the `is InheritedProvider` check failed), causing each provider to add ~5-8 JS frames to the call stack during rebuild. With 119+ BlocProviders in a MultiBlocProvider, this exhausts Chrome's call stack in DDC debug mode (stack overflow on web). By extending InheritedProvider directly, BlocProvider now participates in _collapseProviders, matching RepositoryProvider's behavior and dramatically reducing widget tree depth. Closes felangel#4893 Relates to felangel#4781
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
BlocProviderpreviously extendedSingleChildStatelessWidgetand createdInheritedProviderinternally inbuildWithChild. This meantMultiProvider._collapseProviders— which merges adjacentInheritedProvidersubclasses into a singleSingleChildBuilder— skippedBlocProviders entirely (theprovider is InheritedProvidercheck failed at the firstBlocProvider, breaking the loop).Each uncollapsed provider adds ~5-8 JS stack frames during Flutter's recursive
Element.rebuildchain in DDC debug mode. With 119+BlocProviders in aMultiBlocProvider, this exhausts Chrome's call stack on web debug (stack overflow).By extending
InheritedProvider<T>directly — the same approachRepositoryProvideruses viaProvider<T>—BlocProvidernow participates in_collapseProviders, matchingMultiRepositoryProvider's behavior and dramatically reducing widget tree depth.Repro results (Chrome DDC debug, same machine)
MultiBlocProvider(before)MultiRepositoryProvider(collapsed)Breaking changes
BlocProviderconstructors are no longerconst(InheritedProvider's constructors aren't const). In practice this rarely affects real code since thecreateparameter is almost always a closure.childis not specified now comes fromInheritedProvider("used outside of MultiProvider" vs "used outside of MultiBlocProvider"). Tests updated to usecontainsmatcher.Test plan
flutter_bloctests passbloc_provider_test.dartassertion tests updated for new message sourceMultiBlocProviderwith 135BlocProviders no longer crashes on Chrome DDC debugCloses #4893
Relates to #4781