Skip to content

Commit 6ffcc45

Browse files
gnpricechrisbobbe
authored andcommitted
msglist: Fix excess fetching on scrolling past code blocks
Fixes: #507
1 parent 41dff48 commit 6ffcc45

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

lib/widgets/message_list.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@ class _MessageListState extends State<MessageList> with PerAccountStoreAwareStat
236236
}
237237

238238
bool _handleScrollMetricsNotification(ScrollMetricsNotification notification) {
239+
if (notification.depth > 0) {
240+
// This notification came from some Viewport nested more deeply than the
241+
// one for the message list itself (e.g., from a CodeBlock). Ignore it.
242+
return true;
243+
}
244+
239245
_handleScrollMetrics(notification.metrics);
240246
return true;
241247
}

test/widgets/message_list_test.dart

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,37 @@ void main() {
131131
check(itemCount(tester)).equals(301);
132132
}, skip: true); // TODO this still reproduces manually, still needs debugging,
133133
// but has become harder to reproduce in a test.
134+
135+
testWidgets("avoid getting distracted by nested viewports' metrics", (tester) async {
136+
// Regression test for: https://github.com/zulip/zulip-flutter/issues/507
137+
await setupMessageListPage(tester, foundOldest: false, messages: [
138+
...List.generate(300, (i) => eg.streamMessage(id: 1000 + i)),
139+
eg.streamMessage(id: 1301, content: '<div class="codehilite"><pre><span></span><code>verb\natim\n</code></pre></div>'),
140+
...List.generate(100, (i) => eg.streamMessage(id: 1302 + i)),
141+
]);
142+
final lastRequest = connection.lastRequest;
143+
check(itemCount(tester)).equals(404);
144+
145+
// Fling-scroll upward...
146+
await tester.fling(find.byType(MessageListPage), const Offset(0, 300), 8000);
147+
await tester.pump();
148+
149+
// ... in particular past the message with a [CodeBlockNode]...
150+
bool sawCodeBlock = false;
151+
for (int i = 0; i < 30; i++) {
152+
await tester.pump(const Duration(milliseconds: 100));
153+
if (tester.widgetList(find.byType(CodeBlock)).isNotEmpty) {
154+
sawCodeBlock = true;
155+
break;
156+
}
157+
}
158+
check(sawCodeBlock).isTrue();
159+
160+
// ... and we should attempt no fetches. (This check isn't strictly
161+
// necessary; a request would have thrown, as we prepared no response.)
162+
await tester.pump();
163+
check(connection.lastRequest).identicalTo(lastRequest);
164+
});
134165
});
135166

136167
group('ScrollToBottomButton interactions', () {

0 commit comments

Comments
 (0)