Repository navigation
docs: document vaadin-server-message and vaadin-ui-terminated events - #6820
Conversation
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`).
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.
client.events also announces each message from the server, with its own parsed, start and end events, and the UI stopping.
…rver-message # Conflicts: # articles/flow/advanced/server-client-communication.adoc
vaadin-review-bot
left a comment
There was a problem hiding this comment.
Reviewed the changes — left 1 comment.
| Finding | |
|---|---|
"nothing a page script dispatches on it changes what the client does" is no longer true now that vaadin-ui-terminated is documented |
| == Watching Requests and Messages from Page Scripts | ||
|
|
||
| `window.Vaadin.Flow.clients[appId].events` is an `EventTarget` that announces the requests the client sends to the server, so a page script can follow one, for example to measure it. Heartbeats aren't announced. The client only dispatches on it and never listens to it, so nothing a page script dispatches on it changes what the client does. | ||
| `window.Vaadin.Flow.clients[appId].events` is an `EventTarget` that announces the requests the client sends to the server, the messages it receives from the server, and the UI stopping. A page script can follow a request or a message, for example to measure it. Heartbeats aren't announced. The client only dispatches on it and never listens to it, so nothing a page script dispatches on it changes what the client does. |
There was a problem hiding this comment.
vaadin-ui-terminated is documented
The intro keeps the blanket claim:
The client only dispatches on it and never listens to it, so nothing a page script dispatches on it changes what the client does.
Flow's own client code does listen on this very EventTarget: flow-client/src/main/frontend/Flow.ts:789 registers events.addEventListener('vaadin-ui-terminated', () => this.settleRoundTrip?.()). A synthetic vaadin-ui-terminated dispatched from a page script therefore settles a pending Flow navigation round trip (Flow.ts:468 and Flow.ts:538).
The claim was harmless while only vaadin-request was documented. Now that the section documents the one event Flow listens to, it should be narrowed, for example: "The client engine only dispatches on it and never listens to it, so a synthetic vaadin-request or vaadin-server-message changes nothing about what it does."
server-client-communication.adoc:82 · accuracy
There was a problem hiding this comment.
Narrowed the sentence: synthetic vaadin-request and vaadin-server-message events still change nothing in the client, but a synthetic vaadin-ui-terminated does, because the Flow router listens to it to stop waiting for a pending navigation.
Preview DeploymentThis PR has been deployed for preview. URL: https://docs-preview-pr-6820.fly.dev Changed pagesAdded content is highlighted in green; removed content is marked in red on each page.
Built from 66738e4 |
Summary
Documents the two other events that
window.Vaadin.Flow.clients[appId].eventsdispatches, next tovaadin-request:vaadin-server-message(vaadin/flow#26305) andvaadin-ui-terminated(vaadin/flow#27058). Both are in 25.4.Extends the section added in #6566 (merged).
What changed
vaadin-ui-terminatedmakes the Flow router stop waiting for a pending navigation. Syntheticvaadin-requestandvaadin-server-messageevents still change nothing in the client.vaadin-server-message: when it fires, theparsed/start/endevents of the message, itsrequestandoutcomeproperties, 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", andisTerminated().Test summary
ClientEvents,VaadinServerMessage,UILifecycle,MessageHandler, and the XHR and push connections) onmainand25.4.Working on behalf of Petter