Skip to content

feat: implement window.Vaadin.Flow.whenReady(callback) for TestBench async waiting#23739

Closed
Artur- wants to merge 1 commit intomainfrom
wait-for-vaadin-in-flow
Closed

feat: implement window.Vaadin.Flow.whenReady(callback) for TestBench async waiting#23739
Artur- wants to merge 1 commit intomainfrom
wait-for-vaadin-in-flow

Conversation

@Artur-
Copy link
Copy Markdown
Member

@Artur- Artur- commented Mar 3, 2026

TestBench needs a way to know when a Flow application is fully
initialized and idle before interacting with it. Previously there was
no standard async mechanism — TestBench had to poll internal state
directly, which required repeated round-trips between the test and
the browser.

Add a whenReady function that polls until the document is fully loaded
and all Flow clients are idle, then invokes the callback. This gives
TestBench a reliable async signal for waitForVaadin, avoiding the
polling overhead.

The function is defined in a single resource file (whenReady.js) and
injected into both bootstrap paths via placeholder replacement. Module
files (Flow.ts, FlowBootstrap.js) do not include it since they load
after the inline scripts.

The dev-mode-not-ready page sets whenReady to false so TestBench can
distinguish "not ready yet" from "not supported" and poll until the
real page loads.

@github-actions github-actions Bot added the +0.0.1 label Mar 3, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 3, 2026

Test Results

 1 391 files  ±0   1 391 suites  ±0   1h 14m 51s ⏱️ -6s
 9 997 tests ±0   9 926 ✅ ±0  71 💤 ±0  0 ❌ ±0 
10 472 runs  ±0  10 392 ✅ ±0  80 💤 ±0  0 ❌ ±0 

Results for commit a538e5b. ± Comparison against base commit 0a924d4.

♻️ This comment has been updated with latest results.

@mcollovati mcollovati force-pushed the wait-for-vaadin-in-flow branch from 597eb10 to 7b7980b Compare March 30, 2026 14:22
@mcollovati
Copy link
Copy Markdown
Collaborator

Is this PR still valid and should be reviewed and tested?

@sonarqubecloud
Copy link
Copy Markdown

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.
@Artur- Artur- force-pushed the wait-for-vaadin-in-flow branch from a538e5b to a5a1cae Compare May 1, 2026 15:15
@Artur-
Copy link
Copy Markdown
Member Author

Artur- commented May 1, 2026

Replaced by #24240

@Artur- Artur- closed this May 1, 2026
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 1, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants