Repository navigation
Conversation
Define ready() as the canonical Promise-based "wait until Flow is
idle" API and whenReady(callback) as a thin callback adapter for
TestBench-style usage. Both are inlined into the bootstrap HTML so
they are available on every Flow page in dev and production mode.
ready() resolves once document.readyState is complete,
window.Vaadin.Flow.devServerIsNotLoaded is falsy, at least one client
with isActive() has been registered, and all such clients report
inactive. The "at least one client" requirement avoids a false
positive before Flow has bootstrapped. ready() takes an optional
{ timeout } (default 30s) and rejects on timeout instead of polling
forever. whenReady(callback) invokes the callback either when ready()
resolves or after logging the rejection on timeout, so the callback
contract holds either way.
The dev-mode-not-ready page sets ready and whenReady to false as
not-ready sentinels for TestBench.
The leading guard comment in whenReady.js was breaking the startsWith assertion. Move the warning about disallowed // comments onto the WHEN_READY_JS field's javadoc, where future maintainers of the inlining are more likely to see it, and relax the test to use contains so unrelated changes to whenReady.js do not break it.
|
The client now dispatches a vaadin-flow-activity-changed window event whenever the result of isActive() may have changed: when a request ends, when the deferred command queue drains, when a client is published and when a Flow.ts navigation finishes. ready() listens for it (and for readystatechange) instead of polling every 50ms, with a slow interval kept only as a safety net. ready() now also treats a page without any Flow client as idle, matching what TestBench has always done, so it does not hang until the timeout on pages that never start a Flow client. The whenReady(callback) adapter is removed; ready() returns a Promise, which is enough for any caller. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Dispatching in a microtask let ready() observe a momentary idle state in the middle of a promise chain, e.g. between Flow finishing its initialization and navigating to the first route, and resolve before the view was rendered. Dispatching in a separate task means listeners only see the state between tasks, which is also what a polling caller such as TestBench has always observed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
# Conflicts: # flow-server/src/main/java/com/vaadin/flow/server/communication/IndexHtmlRequestHandler.java
Evaluate ready.js in ReadyTests the way the server inlines it, joined
to one line, so a // comment breaks the tests. Add tests for waiting on
document.readyState, for loadingFinished() and publishClient()
notifying activity changes, and for the {{READY}} substitution in the
web component bootstrap. Pin the deferred command count condition in
TrackingSchedulerTests and the script order in IndexHtmlRequestHandler
tests.
Document the ready() contract in ready.js, keeping the comment free of
< since the script is inlined into a script element.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Fixed: removed the unthrown |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Fixed: added a reason to the |
|
# Conflicts: # flow-server/src/test/java/com/vaadin/flow/server/communication/IndexHtmlRequestHandlerTest.java
# Conflicts: # flow-client/src/test/frontend/FlowTests.ts
When a postponed back/forward navigation proceeds, Flow waits for the browser to move to the target entry before it shows the view. serverPaused had already reported Flow idle, so Vaadin.Flow.ready() could resolve during that move, before the view was shown. Mark Flow active again until completeNavigation runs.



Review risk: two-way door — adds a new client-side JS API (
window.Vaadin.Flow.ready()) and a window event; existing behavior of Flow pages is unchanged and nothing depends on the API until a testing tool opts in.Summary
Adds
window.Vaadin.Flow.ready({ timeout }), a Promise-based "wait until Flow is idle" API that testing tools (TestBench, Playwright, …) can use instead of pollingwindow.Vaadin.Flow.clients[*].isActive()from outside the browser. The readiness rules live in Flow, so every tool gets the same definition of "idle".What changed
ready()is documented inready.jsand inlined into the bootstrap script of both bootstrap paths (IndexHtmlRequestHandlerandBootstrapHandler), so it exists before any client module has loaded. It resolves oncedocument.readyStateiscomplete, the dev server is loaded and every registered client reportsisActive() === false. A page with no Flow clients counts as idle, matching what TestBench has always done. It rejects after the timeout (default 30s).ready()is event-driven: the client dispatches avaadin-flow-activity-changedwindow event wheneverisActive()may have changed (request ended, deferred command queue drained, client published,Flow.tsnavigation finished).ready()re-checks on that event and onreadystatechange; a 500ms interval is kept only as a safety net.ready()does not resolve before that view is shown.ready: false, so callers fall back to their own handling while the dev server starts.whenReady(callback)adapter: the Promise API is enough for callers.Test summary
ready()itself, evaluated joined to one line as the server inlines it (so a//comment fails them): resolves immediately when idle or when there are no clients, waits for the document to finish loading, resolves on the activity event without waiting for the safety-net interval, keeps waiting while the dev server is not loaded, rejects on timeout.publishClientandFlow.loadingFinished()notify, that notifications are coalesced, and that a momentary idle state inside a promise chain is not reported (fails with microtask dispatch). Flow stays active until a postponed back/forward navigation that proceeds has shown its view.ready()afterwindow.Vaadin.Flowis initialised, and that the{{READY}}placeholder is substituted in the web component bootstrap.ready()resolved before the first view was rendered in 36 of 60 page loads; with it, 0 of 60, the same as the existing polling.API Changes
com.vaadin.flow.server.BootstrapHandler.READY_JS(the inlined script, shared by both bootstrap paths).window.Vaadin.Flow.ready(options?: { timeout?: number }): Promise<void>and window eventvaadin-flow-activity-changed.🤖 Generated with Claude Code