fix: keep the deck out of focus traversal - #204
Merged
Conversation
spydon
force-pushed
the
fix/focus-after-first-frame
branch
from
September 5, 2026 11:57
d36260f to
f9ee5e2
Compare
On the web, starting a deck throws "RenderBox was not laid out" once at
startup:
EXCEPTION CAUGHT BY WIDGETS LIBRARY
The following assertion was thrown while dispatching notifications for
WidgetsBindingObserver.didChangeViewFocus:
RenderBox was not laid out: RenderSemanticsAnnotations#53775 NEEDS-LAYOUT
FlutterDeckControlsListener wraps the deck in Focus(autofocus: true). The
autofocus is applied from a microtask before the first layout, and on the
web that synchronously round trips through the engine:
FocusManager.applyFocusChangesIfNeeded
-> View._scopeFocusChangeListener
-> PlatformDispatcher.requestViewFocusChange
-> DomElement.focusWithoutScroll
-> WidgetsBinding.handleViewFocusChanged
-> View.didChangeViewFocus
-> FocusTraversalPolicy.findFirstFocus
-> _sortAllDescendants
Sorting reads FocusNode.rect, which reads RenderBox.size and asserts
hasSize. No layout has run at that point, so the assertion fires.
The node exists to receive key events, not to be a tab stop, so mark it
skipTraversal. It is then left out of the traversal sort and never has its
rect read, while it still holds focus and still receives shortcuts.
Verified against Flutter 3.47.0 stable: the exception is gone and keyboard
shortcuts still work.
spydon
force-pushed
the
fix/focus-after-first-frame
branch
from
September 5, 2026 12:10
f9ee5e2 to
04849c9
Compare
mkobuolys
approved these changes
Sep 5, 2026
Owner
|
@spydon ❤️ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On the web, starting any deck throws
RenderBox was not laid outonce at startup:FlutterDeckControlsListenerwraps the deck inFocus(autofocus: true). The autofocus is applied from a microtask before the first layout, and on the web that synchronously round trips through the engine:_sortAllDescendantsreadsFocusNode.rect, which readsRenderBox.sizeand assertshasSize. No layout has run at that point, so the assertion fires.Fix
The node exists so the deck receives key events, not so it can be a tab stop, so it is marked
skipTraversal. It is then left out of the traversal sort and never has itsrectread, while it still holds focus and still receives shortcuts.Testing
should focus the deck without joining focus traversal, which fails without the fix and passes with it.flutter_decksuite passes (209 tests). Removing the focus entirely breaks 3 of the existing keyboard tests, so the deck genuinely still receives keyboard input.flutter run -d chrome: 1 exception at startup before the change, 0 after.ElevatedButton) on the first slide, to check the fix does not depend on the deck node being the only focus node: 1 exception before the change, 0 after.