From cf784245e8b6cbeb5e227215ee5608ac6fce836a Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Sat, 24 Oct 2026 14:17:57 +0100 Subject: [PATCH] fix(chat): remove remaining router Back interception --- app/lib/application/app_router.dart | 13 +++++------- app/notes/chat-scroll-roundtrip-stock-back.md | 14 +++++++++++++ app/test/application/app_router_test.dart | 21 ++++++++++++------- .../application/chat_scroll_back_test.dart | 10 ++++++++- 4 files changed, 42 insertions(+), 16 deletions(-) diff --git a/app/lib/application/app_router.dart b/app/lib/application/app_router.dart index 00420511..1b4ced2f 100644 --- a/app/lib/application/app_router.dart +++ b/app/lib/application/app_router.dart @@ -78,7 +78,8 @@ class AppRouterDelegate extends RouterDelegate with ChangeNotifier { /// Called when a system Back belongs to the Runs detail, not the app stack. final VoidCallback onPopToRuns; - /// Called when a system Back belongs to one chat session. + /// Legacy callback retained for callers; chat Back is owned by its Navigator + /// route and never invokes this override. final VoidCallback onPopToChat; final bool cupertino; @@ -262,6 +263,7 @@ class AppRouterDelegate extends RouterDelegate with ChangeNotifier { bool get _isExitRoot => _rootExit.enabled && + _route.chatSessionId == null && !_canStepUp && switch (_route.kind) { AppRouteKind.pipelines || @@ -272,11 +274,10 @@ class AppRouterDelegate extends RouterDelegate with ChangeNotifier { _ => false, }; - /// Whether the open route has a level above it in its own tab (a stage, - /// a run, a pipeline, a chat). + /// Whether an inline run/pipeline detail needs the shell to step up. Chats + /// always own a pushed route and use normal Navigator Back instead. bool get _canStepUp => _route.runId != null || - _route.chatSessionId != null || (_route.kind == AppRouteKind.pipelines && _route.pipelineId != null); /// Goes up one level: a stage to its run or pipeline, an item to its list. @@ -299,10 +300,6 @@ class AppRouterDelegate extends RouterDelegate with ChangeNotifier { ); return true; } - if (_route.chatSessionId != null) { - onPopToChat(); - return true; - } return false; } diff --git a/app/notes/chat-scroll-roundtrip-stock-back.md b/app/notes/chat-scroll-roundtrip-stock-back.md index acae6108..070366de 100644 --- a/app/notes/chat-scroll-roundtrip-stock-back.md +++ b/app/notes/chat-scroll-roundtrip-stock-back.md @@ -45,3 +45,17 @@ sequence and did not establish the device-specific cause. `build/candidates/stock-chat-back-29880696/`. Combined release **29880730**, also including the requested rotating Stop icon, is now published/download-verified; see `slow-stop-rotation.md`. Web is published too. Device timing still unverified. + +## Follow-up: remove remaining router interception + +- User reports the device problem persists and requests only removal of the Back + override. The router still treated a chat selection as an inline detail and + could dispatch `onPopToChat` from its root PopScope/fallback. +- Removed chat from that inline step-up path and disabled root double-back while + a chat session is selected. The pushed chat route retains stock Navigator Back; + no timing, scrolling, or animation workaround was added. +- Regression tests reject a blocking PopScope while chat is open, fail if the + legacy callback runs, and cover the exact scroll roundtrip at both widths. +- Checks: all 108 application tests pass; full gate clean analysis and 1,860 tests + pass. No physical-device testing; this does not prove the reported delay fixed. +- Updated APK build/publication is in progress at the user's request. diff --git a/app/test/application/app_router_test.dart b/app/test/application/app_router_test.dart index e817682d..4d2207dc 100644 --- a/app/test/application/app_router_test.dart +++ b/app/test/application/app_router_test.dart @@ -15,14 +15,21 @@ AppRouterDelegate delegate(AppRoute initial, {void Function()? onChat}) => void main() { TestWidgetsFlutterBinding.ensureInitialized(); - test('system Back leaves one chat session for the chat list', () async { - var left = 0; - final router = delegate(AppRoute.chatSession('s1'), onChat: () => left++); - addTearDown(router.dispose); + test( + 'router does not intercept chat Back or invoke the legacy override', + () async { + var left = 0; + final router = delegate(AppRoute.chatSession('s1'), onChat: () => left++); + addTearDown(router.dispose); - expect(await router.popRoute(), isTrue); - expect(left, 1); - }); + // With no Navigator mounted there is nothing to pop. The router must not + // substitute a chat-specific callback or arm main-screen double-back. + expect(await router.popRoute(), isFalse); + expect(await router.popRoute(), isFalse); + expect(left, 0); + expect(router.route, AppRoute.chatSession('s1')); + }, + ); test('system Back steps up one level at a time', () async { var runs = 0; diff --git a/app/test/application/chat_scroll_back_test.dart b/app/test/application/chat_scroll_back_test.dart index 4a5a1da8..09e3aba8 100644 --- a/app/test/application/chat_scroll_back_test.dart +++ b/app/test/application/chat_scroll_back_test.dart @@ -71,7 +71,7 @@ void main() { router = AppRouterDelegate( initial: AppRoute.chat, cupertino: false, - onPopToChat: () => router.goTo(AppRoute.chat), + onPopToChat: () => fail('Chat Back must not use the router override'), onPopToRuns: () {}, builder: (_, route) => AdaptiveShell( destination: AppDestination.chat, @@ -115,6 +115,14 @@ void main() { isTrue, reason: 'Chat must be pushed, not swapped into the main page', ); + expect( + find.byWidgetPredicate( + (widget) => widget is PopScope && !widget.canPop, + ), + findsNothing, + reason: + 'The main-screen Back interceptor must not block an open chat', + ); expect( tester.widget(findNativeBack()).onPressed, isNull,