Repository navigation
fix: fail Window calls when the window state cannot be read - #79
Merged
AdamMusa merged 2 commits intoNov 2, 2026
Merged
Conversation
Control.invokeMethod waited up to the Ruby timeout whenever a control had no invoke listener. That wait exists for invokes that race ahead of a control's first build, but it also hung every call a mounted renderer simply does not handle: ContextMenu.open on iOS, and every Window method on mobile and web, where WindowService registers no listener. Track whether a control is rendered: ControlWidget's element attaches the control while mounted (moving the attachment when the widget is rebuilt with another control), and ServiceBinding attaches services after init(). An attached control without listeners now replies at once with an UnsupportedError naming the control, method and platform. Unmounted controls keep the old wait-for-listener behavior. On desktop, WindowService used to register its listener only after an async read of the window state, so an early page.window call would now be rejected. It registers synchronously in init() and each method waits for the window state before acting. Every other service and control already registers its listener synchronously.
If WindowService's initial window-state read failed, the readiness completer never completed, so every Window invoke waited forever and Ruby only saw its own timeout. Complete the completer with a StateError in the catch so pending and later calls get an immediate error reply, mark its future as handled so an unobserved failure is not reported as uncaught, and stop scheduling window updates that have no state to diff against.
This was referenced Oct 29, 2026
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.
Depends on #59 (
fix/invoke-unhandled-methods-fail-fast, approved atafc3e02). This branch is #59's commit plus one commit (b8893b4). Please review only the last commit; once #59 merges, the diff shrinks to it. #59 itself is not amended.Problem
On desktop,
WindowServicereads the window state once (getWindowState()), and with #59 every Window invoke awaits_initWindowStateCompleterbefore acting. If that read failed (aPlatformExceptionfromwindow_manager, for example), thecatchonly logged it. The completer never completed, so every pending and later Window call hung on the Dart side with no reply, and Ruby only saw its own timeout.Fix (
services/window.dart)catch, complete the completer with aStateError("Window state could not be read: <error>"). Pending calls fail immediately, and later calls fail on their next await, which the backend returns to Ruby as the invoke error.ignore()on the completer's future first, so a failure with no call waiting is not reported as an uncaught async error. Calls that do await it still receive the error._scheduleWindowUpdateskips once the read has failed. There is no window state to diff against. This keeps the base behavior, where updates were never applied after a failed read, and the queuedthengets anonErrorso it cannot surface an unhandled error.A successful read behaves exactly as in #59.
Tests
test/widgets/invoke_fail_fast_test.dart, new test (9 in the file). It runs on macOS with awindow_managerchannel whosegetBoundsthrows after 2 ms:centerinvoked during the read is pending, then fails as soon as the read fails, with aStateErrornaming "Window state could not be read" and the platform message.closesettles within one frame with aStateError.setBounds, andcenter/closenever reach the platform. No uncaught async errors occur.Before the fix the pending call never settled (the test failed on
settled == false). The earlier race test (a successful read) still passes.verify_pr.sh(Flutter 3.41.2) at the final headb8893b4: