fix(festival-selector): avoid GoRouterState.of() inside gesture callback - #241
Merged
Conversation
Calling GoRouterState.of(context) from an onTap handler causes a complete app freeze when a notifyListeners() continuation is pending on the Dart microtask queue at tap time — reproduces reliably when switching festivals immediately after data finishes loading. Fix: capture the current path in showFestivalBrowser() before the modal opens, where it is safe to call InheritedWidget lookups, and pass it as a constructor parameter to FestivalSelectorSheet. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
LCOV of commit
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses an app freeze triggered by calling GoRouterState.of(context) inside the festival selection tap handler by capturing the current route before opening the festival selector modal and passing it into the sheet.
Changes:
- Capture the current route path in
showFestivalBrowser()and pass it intoFestivalSelectorSheetto avoidGoRouterState.of()during the festival cardonTap. - Update festival selection routing logic to preserve the user’s current tab (favorites vs home) based on the captured path.
- Minor comment-only cleanup in
BeerApiServiceandBeerProvider.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| lib/widgets/festival_menu_sheets.dart | Captures current route before modal opens and uses it to decide whether to navigate to /favorites on festival switch, avoiding GoRouterState.of() during tap. |
| lib/services/beer_api_service.dart | Comment-only cleanup in error tracking logic. |
| lib/providers/beer_provider.dart | Comment-only cleanup in setFestival. |
Comment on lines
+11
to
+16
| // Capture current route before opening modal — GoRouterState must not be | ||
| // accessed inside an onTap handler (gesture callbacks are not build phase). | ||
| String? currentPath; | ||
| try { | ||
| currentPath = GoRouterState.of(context).uri.path; | ||
| } catch (_) { |
Comment on lines
+204
to
211
| // Preserve user's tab: if on favorites, stay on favorites. | ||
| // currentPath was captured before the modal opened to avoid | ||
| // calling GoRouterState.of() inside a gesture callback, | ||
| // which can cause a freeze during active widget rebuilds. | ||
| String targetPath = buildFestivalHome(festival.id); | ||
| try { | ||
| final currentPath = GoRouterState.of(context).uri.path; | ||
| // Preserve user's tab: if on favorites, stay on favorites | ||
| if (currentPath.endsWith('/favorites')) { | ||
| targetPath = buildFavoritesPath(festival.id); | ||
| } | ||
| } catch (e) { | ||
| // GoRouterState unavailable (e.g., in tests), keep default path | ||
| debugPrint('Festival selector: Unable to get current route, using default: $e'); | ||
| if (currentPath?.endsWith('/favorites') == true) { | ||
| targetPath = buildFavoritesPath(festival.id); | ||
| } |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
🚀 Cloudflare Pages PreviewYour preview deployment is ready! Preview URL: https://fix-festival-switch-freeze.staging-cambeerfestival.pages.dev This preview will be automatically updated when you push new commits to this PR. |
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.
Calling GoRouterState.of(context) from an onTap handler causes a complete app freeze when a notifyListeners() continuation is pending on the Dart microtask queue at tap time — reproduces reliably when switching festivals immediately after data finishes loading.
Fix: capture the current path in showFestivalBrowser() before the modal opens, where it is safe to call InheritedWidget lookups, and pass it as a constructor parameter to FestivalSelectorSheet.