Repository navigation
docs: broaden Element bindProperty revert behavior - #6753
Conversation
Preview DeploymentThis PR has been deployed for preview. URL: https://docs-preview-pr-6753.fly.dev Changed pagesAdded content is highlighted in green; removed content is marked in red on each page.
Built from 87524ec |
vaadin-review-bot
left a comment
There was a problem hiding this comment.
Reviewed the changes — left 2 comments.
| Finding | |
|---|---|
| The claim about an asynchronous write callback is inverted: the client value is reverted, not kept | |
| "no property change event firing for the revert" is true only when the callback leaves the signal unchanged |
| [since:com.vaadin:vaadin@V25.3]#A value that arrives from the client isn't guaranteed to have the type of the bound signal -- the client is free to set a property to anything. A value the signal can't hold is rejected: a warning is logged, and the property is reverted on the client to the value the signal holds. The write callback isn't expected to handle this itself, so a binding needs no defensive code for it.# | ||
| [since:com.vaadin:vaadin@V25.3]#A value that arrives from the client isn't guaranteed to have the type of the bound signal -- the client is free to set a property to anything. A value the signal can't hold is rejected: a warning is logged. The write callback isn't expected to handle this itself, so a binding needs no defensive code for it.# | ||
|
|
||
| The write callback must update the signal synchronously. After the callback returns, the signal's value is compared to the value the client sent. If they differ -- whether because the value didn't match the signal's type, because a validating callback left the signal unchanged, or for any other reason -- the property is reverted on the client to the value the signal holds, with no property change event firing for the revert. A callback that updates the signal asynchronously leaves the client showing its own value until the signal changes. |
There was a problem hiding this comment.
"A callback that updates the signal asynchronously leaves the client showing its own value until the signal changes."
The opposite happens, and the preceding sentence in the same paragraph already says so. When the callback returns without having changed the signal, the signal value differs from the client value, so Flow queues the signal value for the client (ElementPropertyMap.doDeferredUpdateFromClient, lines 694-701, and the test bindProperty_noOpCallback_noEventAndSignalValueSentToClient: "The client shows "bar", so it has to be told to go back to "foo""). The Element#bindProperty javadoc states it too: "a client-side value is reverted to the current signal value until the signal changes" (Element.java:1035-1037).
Suggested rewrite: "A callback that updates the signal asynchronously makes the client revert to the signal's current value, and the asynchronous update reaches the client only once it changes the signal."
element-bindings.adoc:113 · accuracy
There was a problem hiding this comment.
Fixed. The page now says that a callback that updates the signal asynchronously makes the client revert to the signal's current value, and that the client receives the new value once the asynchronous update changes the signal.
| [since:com.vaadin:vaadin@V25.3]#A value that arrives from the client isn't guaranteed to have the type of the bound signal -- the client is free to set a property to anything. A value the signal can't hold is rejected: a warning is logged, and the property is reverted on the client to the value the signal holds. The write callback isn't expected to handle this itself, so a binding needs no defensive code for it.# | ||
| [since:com.vaadin:vaadin@V25.3]#A value that arrives from the client isn't guaranteed to have the type of the bound signal -- the client is free to set a property to anything. A value the signal can't hold is rejected: a warning is logged. The write callback isn't expected to handle this itself, so a binding needs no defensive code for it.# | ||
|
|
||
| The write callback must update the signal synchronously. After the callback returns, the signal's value is compared to the value the client sent. If they differ -- whether because the value didn't match the signal's type, because a validating callback left the signal unchanged, or for any other reason -- the property is reverted on the client to the value the signal holds, with no property change event firing for the revert. A callback that updates the signal asynchronously leaves the client showing its own value until the signal changes. |
There was a problem hiding this comment.
When the callback writes a different value to the signal, the property is reverted to that value and a property change event fires with it. See ElementBindPropertyTest.bindProperty_transformingCallback_valueChangeEventTriggered (line 989): a client update of "bar" with a callback that upper-cases gives eventValue == "BAR" and counter == 1. No event fires only when the signal is left unchanged, including the type-mismatch case (bindProperty_noOpCallback_noEventAndSignalValueSentToClient, line 1014).
The sibling page already draws this distinction for field bindings, in articles/flow/ui-state/building-ui.adoc:240 and :254.
Suggested rewrite: "…the property is reverted on the client to the value the signal holds. A callback that leaves the signal unchanged fires no property change event. A callback that writes a different value fires one for the value that the signal holds."
element-bindings.adoc:113 · accuracy
There was a problem hiding this comment.
Fixed. The paragraph now separates the two cases. A callback that leaves the signal unchanged fires no property change event. A callback that writes a different value fires one with the value that the signal holds. I also split the long sentence and listed that third revert case.
A callback that updates the signal asynchronously makes the client revert to the signal value, it doesn't keep the client value. A callback that writes a different value fires a property change event with it; only a callback that leaves the signal unchanged fires none.
Documentation for vaadin/flow#26966 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: BEHAVIOR_CHANGE
articles/flow/ui-state/element-bindings.adocElement#bindProperty()revert description: the client-side property reverts whenever the signal's value differs from the value the client sent after the write callback runs (type mismatch, a validating callback that leaves the signal unchanged, or a callback that writes a different value). A property change event fires only when the callback wrote a different value. The callback must update the signal synchronously; with an asynchronous update the client first reverts, then receives the new value.Auto-generated by the Documentation Bot — review before merging.