Repository navigation
fix: fail fast on invoke methods no handler claims - #59
Merged
AdamMusa merged 1 commit intoNov 2, 2026
Merged
Conversation
This was referenced Oct 28, 2026
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.
AdamMusa
force-pushed
the
fix/invoke-unhandled-methods-fail-fast
branch
from
October 28, 2026 23:39
3ed74b8 to
afc3e02
Compare
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.
Engine-only. This is the single generic fix for the "Ruby call waits for its whole timeout" symptom in wave-3 items 2–4. It fully covers item 4 (
fix/window-methods-unsupported-platforms), which therefore has no separate PR.Root cause
When a control has no invoke listener,
Control.invokeMethodwaits for one to be added, up to the Ruby timeout. That wait is deliberate: Ruby can send a patch that adds a control and an invoke in the same breath, and the invoke must not lose the race with the control's first build. But the same wait also hung every call that a mounted renderer simply does not handle:WindowService.init()returns before registering a listener when!isDesktopPlatform(), so every Window method waited out its timeout.openon iOS/macOS: the Cupertino renderer registers no listener.The Cupertino SearchBar
open_view/close_viewwas not a timeout. That renderer registers a listener whosedefault:throwsUnknown SearchBar method, so Ruby got an immediate error. Its native implementation is a separate PR.Fix
Track whether a control is actually rendered, and fail fast only then:
isAttached/attach()/detach(). Attachment is counted, so a control rendered twice stays attached until both renderings are gone.StatelessElementattaches the control inmount. Inupdateit moves the attachment when the same element is rebuilt with a different control, and it detaches inunmount. Renderers register listeners ininitState, inside that same synchronous mount, and invokes are dispatched between frames. So by the time an invoke is handled, an attached control has registered every listener it ever will.service.init()and detaches on dispose.UnsupportedError("Window(30).center is not supported on android: no handler for "center" is registered for this control")Unattached controls (not built yet, or never) keep the old wait-for-listener behavior, so the patch-then-invoke race still works.
What Ruby sees:
on_resultgets the error right away instead of"Timeout waiting for invoke method listener ..."after 10 s or more.Desktop Window race (fixed after QA review of
3ed74b8)On desktop,
WindowService.init()registered its invoke listener only after an async platform round trip that reads the window state, butServiceBindingmarks the control attached right afterinit(). Apage.window.*call in that gap (for examplewait_until_ready_to_showright after startup) would have been rejected as "not supported on macOS"; on the base it reached the platform.Fix in
services/window.dart(5 added lines):init()._invokeMethodfirst awaits the existing_initWindowStateCompleter, so early calls wait for the window state and then act.dispose()removes the listener unconditionally.Audit of every other registration site: Page, Video, the QR scanner and all core and extension services and controls register their listener synchronously in
init()/initState(), the QR scanner also indidUpdateWidget. Window was the only asynchronous one.Tests
test/widgets/invoke_fail_fast_test.dart(8 tests):Text(no handlers) settles within one frame, with anUnsupportedErrornaming the control, the method and the platform. The Ruby timeout is 30 s and fake time is not advanced.ContextMenu.openinvoke settles within one frame with anUnsupportedError.center,closeandstart_resizingsettle within one frame with anUnsupportedError. AfterServiceBinding.dispose()the control is detached.TextFieldfocusinvoked before the field mounts stays pending, then completes and focuses the field once the widget mounts.qa_e59_race_test.dartprobe, kept as a regression test. With macOS and awindow_managerchannel that answers after 2 ms,wait_until_ready_to_showinvoked right after the binding is still pending while the state is read, not rejected. It then completes with no error, andwaitUntilReadyToShowreaches the platform aftergetBounds. Without thewindow.dartchange, this test fails because the call settles immediately as "not supported".TimeoutException.Without this fix, the Window invoke on mobile hangs the test for its whole timeout; I hit exactly that while writing #52.
verify_pr.sh(Flutter 3.41.2) at the final headafc3e02, rebased onto the current basef137eec:git merge-treeshows this merges cleanly with every open engine branch, including #52, which edits the lines just above ininvokeMethod.Follow-ups (separate PRs)
fix/cupertino-search-bar-open-close: native iOSopen_view/close_view.fix/cupertino-context-menu-open:CupertinoContextMenuhas no programmatic open API, so iOSopenreplies with an error that explains why. The generic message here is correct but says less.