From 9a46a6b2b90648c29d961efd45726cfdde0f91d9 Mon Sep 17 00:00:00 2001 From: Alan Silva Date: Thu, 22 Oct 2026 23:42:31 +0100 Subject: [PATCH] fix(app): guard foreground refresh during interaction --- app/lib/application/app_router.dart | 3 + app/lib/application/pipelines_app.dart | 6 ++ .../app_lifecycle_reconnect_test.dart | 70 ++++++++++++++++++- 3 files changed, 78 insertions(+), 1 deletion(-) diff --git a/app/lib/application/app_router.dart b/app/lib/application/app_router.dart index 18899cc1..46af0ab0 100644 --- a/app/lib/application/app_router.dart +++ b/app/lib/application/app_router.dart @@ -90,6 +90,9 @@ class AppRouterDelegate extends RouterDelegate with ChangeNotifier { AppRoute get route => _route; + /// Whether a dialog, popup, or other route is covering the shell page. + bool get hasTransientRoute => _navigatorKey.currentState?.canPop() ?? false; + bool get searchOpen => _route.kind == AppRouteKind.search; bool get templatesOpen => _route.kind == AppRouteKind.templates; diff --git a/app/lib/application/pipelines_app.dart b/app/lib/application/pipelines_app.dart index b7ad172c..081e207e 100644 --- a/app/lib/application/pipelines_app.dart +++ b/app/lib/application/pipelines_app.dart @@ -217,6 +217,7 @@ class _PipelinesAppState extends State // A return to the foreground refreshes only the visible list. Detail routes // (including pipeline definitions and run visits) keep their current data. + if (_delegate.hasTransientRoute || _isEditingText) return; final route = _delegate.route; if (route.kind == AppRouteKind.pipelines && route.pipelineId == null && @@ -227,6 +228,11 @@ class _PipelinesAppState extends State } } + bool get _isEditingText { + final focusContext = FocusManager.instance.primaryFocus?.context; + return focusContext?.findAncestorWidgetOfExactType() != null; + } + /// A replaced socket drops the attention status baseline so the gap cannot /// replay a transition; the Runs list's next read reseeds the rows. void _attentionSessionChanged() { diff --git a/app/test/application/app_lifecycle_reconnect_test.dart b/app/test/application/app_lifecycle_reconnect_test.dart index cdff20b4..44d76547 100644 --- a/app/test/application/app_lifecycle_reconnect_test.dart +++ b/app/test/application/app_lifecycle_reconnect_test.dart @@ -1,6 +1,6 @@ import 'dart:convert'; -import 'package:flutter/widgets.dart'; +import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pipelines_app/application/pipelines_app.dart'; import 'package:pipelines_app/core/transport/pipelines_client.dart'; @@ -153,6 +153,74 @@ void main() { await tester.pump(); }); + testWidgets('foreground resume preserves an open dialog and skips refresh', ( + tester, + ) async { + final channel = FakeChannel()..readyCompleter.complete(); + final provider = PlatformRouteInformationProvider( + initialRouteInformation: RouteInformation(uri: Uri.parse('/runs')), + ); + addTearDown(provider.dispose); + final client = PipelinesClient(channelFactory: (_) => channel); + await pumpApp(tester, provider: provider, client: client); + await waitForRequest(tester, channel, 'list_runs'); + final initialRuns = pipelineRequest(channel, 'list_runs')!; + channel.incoming.add(jsonEncode({ + 'id': initialRuns['id'], + 'type': 'runs', + 'runs': PipelineFixture().runs, + })); + await tester.pump(); + final before = countType(channel, 'list_runs'); + showDialog( + context: tester.element(find.byType(Scaffold).first), + builder: (_) => const AlertDialog(content: Text('Still open')), + ); + await tester.pump(); + + await resume(tester); + + expect(countType(channel, 'list_runs'), before); + expect(find.text('Still open'), findsOneWidget); + await tester.pumpWidget(const SizedBox.shrink()); + await tester.pump(); + }); + + testWidgets('foreground resume skips refresh while a text field has focus', ( + tester, + ) async { + final channel = FakeChannel()..readyCompleter.complete(); + final provider = PlatformRouteInformationProvider( + initialRouteInformation: RouteInformation(uri: Uri.parse('/runs')), + ); + addTearDown(provider.dispose); + final client = PipelinesClient(channelFactory: (_) => channel); + await pumpApp(tester, provider: provider, client: client); + await waitForRequest(tester, channel, 'list_runs'); + final initialRuns = pipelineRequest(channel, 'list_runs')!; + channel.incoming.add(jsonEncode({ + 'id': initialRuns['id'], + 'type': 'runs', + 'runs': PipelineFixture().runs, + })); + await tester.pump(); + final before = countType(channel, 'list_runs'); + showDialog( + context: tester.element(find.byType(Scaffold).first), + builder: (_) => const AlertDialog(content: TextField()), + ); + await tester.pump(); + await tester.tap(find.byType(TextField).last); + await tester.pump(); + + await resume(tester); + + expect(countType(channel, 'list_runs'), before); + expect(FocusManager.instance.primaryFocus?.hasFocus, isTrue); + await tester.pumpWidget(const SizedBox.shrink()); + await tester.pump(); + }); + testWidgets('foreground resume does not refresh an open run detail', ( tester, ) async {