[web] warm-up frame does not block schedule frame (#162779)

Fix the issue with the first frame not rendering, introduced in
https://github.com/flutter/flutter/pull/162554.

Nobody filed an issue yet. I found it while testing something else.
This commit is contained in:
Yegor 2025-02-05 21:01:10 -08:00 committed by GitHub
parent 1f5cb0d665
commit d4772e591c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 6 deletions

View File

@ -120,8 +120,6 @@ class FrameService {
required ui.VoidCallback beginFrame,
required ui.VoidCallback drawFrame,
}) {
_isFrameScheduled = true;
// A note from dkwingsmt:
//
// We use timers here to ensure that microtasks flush in between.
@ -133,7 +131,6 @@ class FrameService {
// https://github.com/flutter/engine/pull/50570#discussion_r1496671676
Timer.run(() {
_isFrameScheduled = false;
_isRenderingFrame = true;
_debugFrameNumber += 1;
// TODO(yjbanov): it's funky that if beginFrame crashes, the drawFrame
@ -142,10 +139,15 @@ class FrameService {
// "we did this before so let's continue doing it" excuse
// only works so far (referring to the discussion linked
// above).
beginFrame();
try {
beginFrame();
} finally {
_isRenderingFrame = false;
}
});
Timer.run(() {
_isRenderingFrame = true;
try {
drawFrame();
} finally {

View File

@ -136,8 +136,13 @@ void testMain() {
},
);
// IMPORTANT: scheduled, but not yet rendering
expect(instance.isFrameScheduled, isTrue);
// Even though the warm-up frame is scheduled the value of
// isFrameScheduled remains false. This is because, for reasons to be yet
// addressed, the warm-up frame can be (and indeed is) interleaved with
// a normal scheduleFrame request. See the TODOs inside the
// scheduleWarmUpFrame code, and this discussion in particular:
// https://github.com/flutter/engine/pull/50570#discussion_r1496671676
expect(instance.isFrameScheduled, isFalse);
expect(instance.isRenderingFrame, isFalse);
await frameCompleter.future;
expect(instance.isFrameScheduled, isFalse);