Repository navigation
Allow applying server-driven client updates within a browser view transition - #24816
totally-not-ai[bot] wants to merge 18 commits into
Conversation
Adds UI#enableViewTransition() so that the DOM changes produced by the current server response are applied inside a document.startViewTransition() call on the client, enabling the resulting updates to be animated. The request is stored per-response in UIInternals, written into the response metadata by UidlWriter, and reset after the response is built so it only affects a single round trip. This lets an add-on or specific application logic opt in to view transitions for individual updates without a global configuration flag. The client applies the changes within a view transition only when the browser supports the API, falling back to applying them directly otherwise.
| private static native void startViewTransition(Command command) | ||
| /*-{ | ||
| $doc.startViewTransition(function() { | ||
| command.@com.vaadin.client.Command::execute()(); |
There was a problem hiding this comment.
Good catch — wrapped the startViewTransition callback in $entry(...). Since the browser invokes it asynchronously (outside the GWT call stack), $entry is needed so GWT's exception handling and the deferred command scheduler run correctly for code executed within the transition.
The callback passed to document.startViewTransition() is invoked asynchronously by the browser, outside the GWT call stack. Wrapping it in $entry ensures GWT exception handling and the deferred command scheduler run correctly for code executed within the transition.
Reverts unrelated package-lock.json churn introduced by the build step.
The it-tests (11) job failed in the "Set up Maven" step with HTTP 403 while downloading the Maven distribution from Maven Central, before any project code was compiled or tested. This empty commit re-triggers CI to get past the transient infrastructure failure.
Move the view-transition decision into a single JSNI helper (flushChanges) so that the only added executable Java line in MessageHandler is the call itself; the previous approach turned existing, JVM-untestable client lines into new uncovered lines and dragged down new-code coverage. Also add GWT tests verifying that server-requested changes are applied inside a view transition when the browser supports the API, and applied directly otherwise.
|
|
Did you ever get to try this one out @jouni and did it help? If you describe the use cases for transitions here, then somebody else could also have a look |
|
The motivating case is animating an arbitrary, server-driven UI change that would otherwise apply instantly. For example, a feature that fills in a form on the server can call The browser snapshots the affected elements before and after the update and animates between the two states, so no per-component animation code is needed. Because it is opt-in per response, an add-on or a specific piece of logic can animate a single round trip without any global configuration. Leaving the question of real-world results to |
Yeah, I did a quick test locally back in June. I remember it working as expected. The use case was about our AI form filler, that we might’ve wanted to use view transitions for the "AI has modified this field value" marker animations, which would’ve allowed us to capture the screenshot of the state of the fields before the AI changed their values, and include the changing of the value in the transitions as well. But we decided to go with the simpler CSS animation approach, and just delay setting the new value to halfway of the animation, so to the user it seems the value changes with the animation, not before it. |
|
|
|
This is still a nice-to-have feature, I would say. Probably non needed or used very often. We could build on it, though, making it easier to create more complex view transitions, instead of just the default crossfade. |
|
|
|
Yes, complex transitions are possible after this change. Just saying that creating those are outside the comfort zone of our target audience, if they can only use CSS for it. |
|
|
|
…tes-in-view-transition The GWT client engine was removed on main in favour of the TypeScript client, so the view transition handling is ported from the deleted MessageHandler.java to MessageHandler.ts, with its GWT tests replaced by web-test-runner tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Memory footprintCompared with the base commit 3a9144f.
Scenarios
Measured by |
document.startViewTransition() runs its update callback asynchronously. Flushing inside it while ending the request and releasing the response lock synchronously let the client report itself idle with the old DOM still on screen, and let a pending message flush the changes outside the transition. Applying the changes and finishing the message processing now both happen inside the update callback. Also name the supported browsers that lack the View Transitions API in the enableViewTransition() Javadoc. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…tes-in-view-transition # Conflicts: # flow-client/src/main/frontend/internal/client/communication/MessageHandler.ts
Applying changes could finish processing twice when it threw, ending an unrelated in-flight request. The promises of a skipped view transition were also left unhandled, reporting an AbortError.
…tes-in-view-transition # Conflicts: # flow-client/src/main/frontend/internal/client/communication/MessageHandler.ts # flow-client/src/test/frontend/internal/client/communication/MessageHandlerTests.ts
The browser swallows what the update callback throws and rejects the transition's finished promise instead. Logging it with Console.error hid the failure in production mode, unlike the same failure without a transition. Report it through Console.reportStacktrace instead.
|
The reported field ( |
|
@totally-not-ai I want to release this feature behind a feature flag. |
UI.enableViewTransition() now throws DisabledFeatureException unless the com.vaadin.experimental.viewTransitions feature flag is enabled, so the API can ship as experimental. The UidlWriter test now sets the internal flag directly since it tests response writing, not the flag check.
|
@jouni Done: the feature is now behind the experimental |
Bundle sizeCompared with the base commit 3a9144f.
Size by module, before minification
The production bundle of |
@totally-not-ai, yes, let's create a tracking issue for feedback. |
|



What changed
Adds
UI#enableViewTransition(), which requests that the DOM changes produced by the current server response are applied inside adocument.startViewTransition()call on the client, so the resulting updates can be animated.com.vaadin.experimental.viewTransitions=trueis set (for example insrc/main/resources/vaadin-featureflags.properties, or from the experimental features tab in Copilot). With the flag off,UI#enableViewTransition()throws aDisabledFeatureExceptionthat explains how to enable it. The flag is checked on every call, so no server restart is needed.UI#enableViewTransition()— public opt-in API for the current request.CoreFeatureFlagProvider.VIEW_TRANSITIONS— the newviewTransitionsfeature flag. Its "more info" link points to the feedback issue Feedback: experimental view transitions for server updates #27688.UIInternals— stores the request per response (isViewTransitionRequested()/setViewTransitionRequested(boolean)).UidlWriter— writes the flag into the response metadata asJsonConstants.META_VIEW_TRANSITIONand resets it afterwards, so it only affects a single round trip.MessageHandler.ts— when the server asked for a transition and the browser supports the API, the reactive flush runs inside thedocument.startViewTransition()update callback; otherwise the changes are applied directly. A skipped transition (e.g. in a hidden tab) is not reported as an error; a failure while applying the changes is reported like one without a transition, also in production mode. Because the browser invokes that callback asynchronously, ending the request, stopping the loading indicator and releasing the response lock also happen inside it, so the client keeps reporting itself as active (e.g. for TestBench'swaitForVaadin) and no queued message can flush the changes outside the transition.Why
There is currently no way to have an arbitrary, server-driven UI change animate — changes are always applied instantly. Making this a per-response opt-in (rather than a global configuration flag) lets an add-on or a specific piece of application logic animate individual updates without affecting the rest of the application. By default the browser applies a simple cross-fade; richer transitions can be defined purely with CSS via
view-transition-nameand the::view-transition-*pseudo-elements. Behaviour degrades gracefully: browsers without the View Transitions API (e.g. Safari 17 and Firefox before 144, including the current ESR) just apply the changes as before.Testing
UItests verify thatenableViewTransition()throws aDisabledFeatureExceptionnaming the flag when it is off or no service is available, and that it requests a transition when the flag is on, also for a UI without a session.UidlWriterTestverifies the metadata flag is written when requested and that it is reset so it does not leak into the next response.startViewTransitionstub to verify that the changes are applied, the request ended and the next queued message handled only once the transition runs its update, and that changes are applied directly when no transition is requested or the API is unavailable.Use case
A developer has a table of tasks with a "Sort by priority" button. Today, clicking it makes the rows jump to their new positions instantly, which makes it hard to follow where a given row went. They want the reordering to animate, but they do not want to animate every update in the application, and they do not want to reimplement sorting in client-side JavaScript just to get a transition.
They enable the experimental flag in
src/main/resources/vaadin-featureflags.properties:com.vaadin.experimental.viewTransitions=trueThen they opt in for that one round trip and let CSS do the rest:
The browser snapshots the rows before and after the update and animates them into their new positions; no per-component animation code is needed, and browsers without the View Transitions API simply render the reordered list directly.
API Changes
com.vaadin.flow.component.UI
com.vaadin.experimental.CoreFeatureFlagProvider
com.vaadin.flow.component.internal.UIInternals
com.vaadin.flow.shared.JsonConstants
🤖 Generated with Claude Code