Skip to content

Commit 5f1cd67

Browse files
browsquare-tombstudiostudio
authored
perf(mobile): stop rebuilding Home's channel list when a route covers it (#9459)
Opening any route or sheet above Home (search, a message's action menu, a profile sheet, Activity, Settings) rebuilt Home's whole channel list twice: once when the route started covering Home and once when it finished. On a phone the open channel sits inside Home's conversation pane, so a sheet over a channel (long-press menu, profile) did the same. `HomePage` and `ChannelsPage` read `ModalRoute.of(context)` in their own builds, which depends on every part of the route's state (whether it's current, whether it's offstage, and so on). `ChannelsPage` also depended on the whole `DuoToolbarScope`, whose `active` flag flips whenever a route covers the pane, through `frostedAppBarHeight`. Every channel row and the Solo section depended on `ConversationPaneScope` for the selected channel, and that scope notified all of them when its route-dependent `active` flag flipped. Each of those rebuilt a fresh channel inventory, including Solo rows that had scrolled away, which resubscribed their typing feeds for 30 seconds. Now: - Home's native controls (Activity bell, tab bar, Duo rail) read the route in a small `_NativeControlsGate` leaf, so only they rebuild when Home is covered. - `ChannelsPage` mirrors route currency into its header suppression notifier from a `_RouteCurrencySync` leaf above the header, so the header still switches in the same frame. The two "wait until this route is current again" loops read the same notifier. - `DuoToolbarScope` is an `InheritedModel` with a strip-only lookup, `maybeStripOf`. The frosted header's height and `ChannelsPage` use it, so `active` changes no longer reach them. Every other reader keeps `maybeOf` and its current behavior. - `ConversationPaneScope`'s `active` flag lives in its own private inherited widget, read only by `isActiveOf`. Rows that only need the controller no longer rebuild when it flips. - Opening a channel looks up the conversation pane instead of depending on it. ### Validation New test: opening and closing a sheet above Home rebuilds neither `HomePage`, `ChannelsPage` nor any channel row. It fails without this change. Full mobile test suite, `flutter analyze` and the file-size check pass. On the iPhone 12 mini (profile build, Builderlab): Same scripted run on `main` and on this branch (search opened and closed 3 times, then a message's long-press menu and a profile sheet over an open channel): | | main | this branch | | --- | --- | --- | | Widget builds per search open | 126 to 350 | 56 to 60 | | Build time per search open | 79 to 90 ms | 29 to 41 ms | | Build time, long-press menu open | 64 ms | 17 ms | | Typing subscriptions reopened by the sheets | 9 (about 80 KB of messages downloaded) | 0 | The menu, profile sheet, channel header and Home's tab bar and Activity button behaved the same in both runs. ### Regressions None expected. The native controls and header switch from the same route state as before, in the same frame. A `DuoToolbarScope` strip change still reaches the header and the channel list. --------- Signed-off-by: Tom Brow <[email protected]> Co-authored-by: Tom Brow <[email protected]> Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@buzz.block.builderlab.xyz> Co-authored-by: studio <dc2fc481343672df31a689840c09299972e704dac592e0da6f18486646a7ee3e@localhost>
1 parent 3764a2e commit 5f1cd67

7 files changed

Lines changed: 283 additions & 147 deletions

File tree

‎mobile/lib/features/channels/channels_page.dart‎

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class ChannelsPage extends HookConsumerWidget {
188188
final nativeDuoTitle =
189189
messagesFilters != null &&
190190
defaultTargetPlatform == TargetPlatform.iOS &&
191-
(DuoToolbarScope.maybeOf(context)?.strip ??
191+
(DuoToolbarScope.maybeStripOf(context) ??
192192
FoldGeometry.of(context).strip) !=
193193
null;
194194
final filterContentHeight = messagesFilters == null
@@ -206,10 +206,8 @@ class ChannelsPage extends HookConsumerWidget {
206206
);
207207
// A sheet's dim barrier can't composite over Home's native soft edge, so
208208
// use the Flutter backdrop while another route covers this page.
209-
final route = ModalRoute.of(context);
210209
final headerNativeSuppressed = useValueNotifier(false);
211-
headerNativeSuppressed.value =
212-
messagesFilters != null && !(route?.isCurrent ?? true);
210+
final routeCurrent = useValueNotifier(true);
213211
final communityAvatarKey = useMemoized(GlobalKey.new);
214212
final nativeCommunityAvatarBounds = useRef<Rect?>(null);
215213
final headerKey = useMemoized(GlobalKey.new);
@@ -310,7 +308,10 @@ class ChannelsPage extends HookConsumerWidget {
310308
.toList();
311309
Future<void> openChannel(Channel channel) async {
312310
if (!context.mounted) return;
313-
final pane = ConversationPaneScope.maybeOf(context);
311+
// A lookup, not a dependency: the page doesn't rebuild with the pane.
312+
final pane = context
313+
.getInheritedWidgetOfExactType<ConversationPaneScope>()
314+
?.notifier;
314315
if (pane != null) {
315316
pane.open(
316317
channel.id,
@@ -431,7 +432,7 @@ class ChannelsPage extends HookConsumerWidget {
431432
do {
432433
await WidgetsBinding.instance.endOfFrame;
433434
if (cancelled || !context.mounted) return;
434-
} while (ModalRoute.of(context)?.isCurrent == false);
435+
} while (!routeCurrent.value);
435436
if (ref.read(pairedCommunityLandingProvider)?.id !=
436437
arrivingCommunity.id) {
437438
return;
@@ -500,7 +501,7 @@ class ChannelsPage extends HookConsumerWidget {
500501
do {
501502
await WidgetsBinding.instance.endOfFrame;
502503
if (cancelled || !context.mounted) return;
503-
} while (ModalRoute.of(context)?.isCurrent == false);
504+
} while (!routeCurrent.value);
504505
if (!ref.read(communityGridLandingProvider)) return;
505506
ref.read(communityGridLandingProvider.notifier).clear();
506507
openCommunityGrid();
@@ -648,7 +649,7 @@ class ChannelsPage extends HookConsumerWidget {
648649
return () => active = false;
649650
}, [newChannelAction, newDmAction, currentPubkey]);
650651

651-
return ValueListenableBuilder(
652+
final page = ValueListenableBuilder(
652653
valueListenable: headerTreatment,
653654
// Retain the inventory during header animation. Provider and parent
654655
// updates still construct a fresh body with current channel data.
@@ -840,6 +841,40 @@ class ChannelsPage extends HookConsumerWidget {
840841
body: child!,
841842
),
842843
);
844+
return _RouteCurrencySync(
845+
current: routeCurrent,
846+
nativeSuppressed: headerNativeSuppressed,
847+
suppressesNative: messagesFilters != null,
848+
child: page,
849+
);
850+
}
851+
}
852+
853+
/// Mirrors whether this page's route is current into [current], and into
854+
/// [nativeSuppressed] when [suppressesNative] is set.
855+
///
856+
/// Only this leaf depends on the route, so a route or sheet opening above Home
857+
/// rebuilds it and the header listening to [nativeSuppressed], not the channel
858+
/// inventory. The header is a descendant, so it updates in the same frame.
859+
class _RouteCurrencySync extends StatelessWidget {
860+
const _RouteCurrencySync({
861+
required this.current,
862+
required this.nativeSuppressed,
863+
required this.suppressesNative,
864+
required this.child,
865+
});
866+
867+
final ValueNotifier<bool> current;
868+
final ValueNotifier<bool> nativeSuppressed;
869+
final bool suppressesNative;
870+
final Widget child;
871+
872+
@override
873+
Widget build(BuildContext context) {
874+
final isCurrent = ModalRoute.isCurrentOf(context) ?? true;
875+
current.value = isCurrent;
876+
nativeSuppressed.value = suppressesNative && !isCurrent;
877+
return child;
843878
}
844879
}
845880

‎mobile/lib/features/channels/channels_page/sections.dart‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,7 @@ class _SectionChevron extends StatelessWidget {
640640

641641
bool _usesNativeSectionMenu(BuildContext context) =>
642642
defaultTargetPlatform == TargetPlatform.iOS &&
643-
(DuoToolbarScope.maybeOf(context)?.strip ??
644-
FoldGeometry.of(context).strip) !=
643+
(DuoToolbarScope.maybeStripOf(context) ?? FoldGeometry.of(context).strip) !=
645644
null;
646645

647646
class _SectionOptionsButton extends StatelessWidget {

0 commit comments

Comments
 (0)