Skip to content

docs: document watching requests via client.events - #6566

Merged
peholmst merged 3 commits into
mainfrom
doc-bot/vaadin-flow/26064-40d33f7ca2134761
Dec 2, 2026
Merged

peholmst merged 3 commits into
mainfrom
doc-bot/vaadin-flow/26064-40d33f7ca2134761

Conversation

@vaadin-bot

Copy link
Copy Markdown
Contributor

Documentation for vaadin/flow#26064 by @totally-not-ai[bot].

Note

The source pull request is merged, so this documentation describes the final
shape of the change. Please review it and mark it ready for review.

Change categories: NEW_FEATURE

File Change
articles/flow/advanced/server-client-communication.adoc Added a "Watching Requests from Page Scripts" section documenting window.Vaadin.Flow.clients[appId].events, the vaadin-request event, and the sent/error/response/end lifecycle of the request object it carries, including the attempt, failure, and outcome properties and the ability to dispatch synthetic events for testing.

Auto-generated by the Documentation Bot — review before merging.

Generated by Documentation Bot for #26064 · agent · 206.8 AIC · ⊞ 11.7K · ◷

  • expires on Dec 4, 2026, 12:55 PM UTC

Add a section to Server to Client Communication describing
window.Vaadin.Flow.clients[appId].events and the vaadin-request event,
through which page scripts can observe each request's delivery
(sent/error/response/end) and dispatch synthetic events for testing.

Documents vaadin/flow#26064 (`3962e2c011fed2b23ed3f3547341980495f0a9ef`).
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Preview Deployment

This PR has been deployed for preview.

URL: https://docs-preview-pr-6566.fly.dev

Changed pages

Added content is highlighted in green; removed content is marked in red on each page.

Built from bedbbfe

@peholmst
peholmst marked this pull request as ready for review December 2, 2026 07:45

@vaadin-review-bot vaadin-review-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the changes — left 5 comments.

Finding
⚠️ failure is an object with reason and status, not the reason string the page describes
⚠️ "every request the client sends" is wrong: heartbeats are not announced
💬 The example uses a client variable that the page never defines
💬 The page omits that listeners run synchronously inside the client's work
📐 The new section has no since badge

A `vaadin-request` event is dispatched when the first invocation for a request is queued, or right before the first send for a request that has no invocations, such as a resynchronization. Its `detail` is the request, which then dispatches events of its own as its delivery proceeds:

`sent`:: An attempt to deliver the request goes out. The request's `attempt` property counts attempts, starting at `0` while it's still queued.
`error`:: The attempt failed. The request's `failure` property gives the reason: `network`, `timeout`, `http` with the response's `status`, or `invalid-response` for a reply that couldn't be parsed.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ failure is an object with reason and status, not the reason string the page describes

The request's failure property gives the reason: network, timeout, http with the response's status, or invalid-response

In flow-client/src/main/frontend/internal/client/communication/VaadinRequest.ts:21-34, failure is a VaadinRequestFailure object: { reason: 'network' | 'timeout' | 'http' | 'invalid-response', status?: number }. The page never names reason or status, so a reader writes request.failure === 'timeout' and the check never matches.

Suggested rewrite:

The attempt failed. The request's failure property gives an object with a reason of network, timeout, http or invalid-response, plus a status with the HTTP status when the reason is http.

server-client-communication.adoc:86 · accuracy

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. failure is now described as an object whose reason is network, timeout, http or invalid-response, with status holding the HTTP status for http.


== Watching Requests from Page Scripts

`window.Vaadin.Flow.clients[appId].events` is an `EventTarget` that announces every request the client sends to the server, so a page script can follow one, for example to measure it. The client only dispatches on it and never listens to it, so nothing a page script dispatches on it changes what the client does.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ "every request the client sends" is wrong: heartbeats are not announced

window.Vaadin.Flow.clients[appId].events is an EventTarget that announces every request the client sends to the server

Both ClientEvents.ts and VaadinRequest.ts:97 state "Heartbeats are not covered", and Heartbeat.ts sends its own XHR without creating a VaadinRequest. The unload beacon (MessageSender.sendUnloadBeacon()) also bypasses it. A reader who builds a connection monitor on this will wait for events that never arrive.

Suggest "announces the UIDL requests the client sends to the server; heartbeats are not covered".

server-client-communication.adoc:81 · accuracy

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. The section now says that the client announces the requests it sends, and that heartbeats aren't announced.


[source,javascript]
----
client.events.addEventListener('vaadin-request', ({ detail: request }) => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 The example uses a client variable that the page never defines

The prose names window.Vaadin.Flow.clients[appId].events, then the example starts from a bare client. The page never says what appId is or how a page script obtains it, and appId appears nowhere else in the documentation. A reader cannot run the example as written.

Adding one line fixes it, for example:

const client = window.Vaadin.Flow.clients[appId];

along with a sentence on where appId comes from.

server-client-communication.adoc:94 · clarity

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example now starts with const client = Object.values(window.Vaadin.Flow.clients).find((c) => c.events);. The prose says that clients holds one client per application, keyed by its application ID. It also says that the script has to run after the application has started, for example through Page.executeJs().

`response`:: A reply to the attempt arrived and was identified.
`end`:: The delivery has settled. The request's `outcome` property says how: `acknowledged` for a reply from the server, `rejected` if the server couldn't process the request or the session has expired, or `discarded` if the client gave up without a confirming reply. `end` is dispatched exactly once, as the last event.

The request is the same object across every attempt to deliver it. A resend after a lost connection, a resend from the resend timer, or a resend over a reconnected push channel all fire `sent` again on the same object, with `attempt` incremented.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💬 The page omits that listeners run synchronously inside the client's work

VaadinRequest.ts:93-95 and ClientEvents.ts:67-69 both warn: "Listeners run synchronously inside the client's own work, including while it queues invocations: keep them cheap and do not call back into the client from them." The section invites readers to add listeners for measurement but carries none of this, so an expensive listener or a reentrant call into the client looks supported.

server-client-communication.adoc:90 · clarity

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added: listeners run synchronously inside the client's own work, including while it queues invocations. Keep them cheap, and don't call back into the client from them.

This process ensures UI consistency, even in the presence of errors or unexpected behavior. The application remains robust against transient network problems or client-side interruptions. Additionally, the user experience is preserved without requiring a full page reload, as Vaadin rebuilds the UI without reloading the entire bundle from the server.


== Watching Requests from Page Scripts

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 The new section has no since badge

CONVENTIONS.md: "Mark new features with a since badge instead: the [role="since:com.vaadin:vaadin@V25.2"] attribute above a section heading". The PR is categorized NEW_FEATURE, and the sibling section below carries such a badge. Add the badge for the current development version (25.4 per articles/_vaadin-version.adoc):

[role="since:com.vaadin:vaadin@V25.4"]
== Watching Requests from Page Scripts

server-client-communication.adoc:79 · conventions

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added [role="since:com.vaadin:vaadin@V25.4"] above the heading. The feature shipped in 25.4.0-alpha5.

failure is an object with reason and status, and heartbeats aren't
announced. Show how a page script gets the client, say that listeners
run synchronously, and add the 25.4 since badge.
@peholmst
peholmst merged commit 9bddf85 into main Dec 2, 2026
10 of 11 checks passed
@peholmst
peholmst deleted the doc-bot/vaadin-flow/26064-40d33f7ca2134761 branch December 2, 2026 08:50
peholmst pushed a commit that referenced this pull request Dec 2, 2026
…6820)

## Summary

Documents the two other events that
`window.Vaadin.Flow.clients[appId].events` dispatches, next to
`vaadin-request`: `vaadin-server-message` (vaadin/flow#26305) and
`vaadin-ui-terminated` (vaadin/flow#27058). Both are in 25.4.

Extends the section added in #6566 (merged).

## What changed

- The section is renamed to "Watching Requests and Messages from Page
Scripts", and its intro lists all three events.
- The intro now says that a synthetic `vaadin-ui-terminated` makes the
Flow router stop waiting for a pending navigation. Synthetic
`vaadin-request` and `vaadin-server-message` events still change nothing
in the client.
- `vaadin-server-message`: when it fires, the `parsed`/`start`/`end`
events of the message, its `request` and `outcome` properties, the cases
where events are skipped, and an example that measures handling time.
- `vaadin-ui-terminated`: when the UI stops, that an embedded web
component can start a new UI after "Session expired", and
`isTerminated()`.
- The paragraph on dispatching synthetic events now covers messages too.

## Test summary

- Checked every statement against the Flow client sources
(`ClientEvents`, `VaadinServerMessage`, `UILifecycle`, `MessageHandler`,
and the XHR and push connections) on `main` and `25.4`.

Working on behalf of Petter

---------

Co-authored-by: Vaadin Bot <vaadin-bot@users.noreply.github.com>
Co-authored-by: totally-not-ai[bot] <290682512+totally-not-ai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants