Repository navigation
fix: track visual modality so dialogs are refreshed on hotswap - #25417
Conversation
Dialogs are visually modal by default since 25.0, and ModalityMode.VISUAL was mapped to setChildModeless, so a component with visual modality was not tracked on the server side at all. Both the code paths that deal with overlays attached to the UI instead of the route are guarded by UI.hasModalComponent(), so with an open dialog they became no-ops: AbstractNavigationStateRenderer no longer detached the dialog on a route refresh, leaving it visible with outdated contents, and Hotswapper no longer requested a refresh of the whole route chain. Components set to ModalityMode.VISUAL are now tracked in UIInternals without making the UI inert, keeping the meaning of hasModalComponent() and the inert semantics unchanged, and both call sites take the new information into account. Fixes #25415
Tracking strict and visual modality in two separate stacks made getModalityComponents() report the components in the wrong order and, when a component switched between the two modes, report it twice. Components with modality are now kept in one stack, in the order they were set, while the existing modal component stack keeps taking care of the inert state only. Registration of the detach listener that stops tracking a component is idempotent, so repeatedly applying the same modality to a component does not pile up listeners on its element.
|
platosha
left a comment
There was a problem hiding this comment.
All @since 25.3 tags are outdated, they should mention 25.4 now.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ith-visual-modality
Memory footprintCompared with the base commit 3f5b0b9.
UI with 200 form rows added in the latest round trip: Heap retained per UI by class
Scenarios
Measured by |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Fixed the three reported issues: |
|
Could we implement this using a single modality related stack instead of two? Compare with the current approach. |
Keep one recency ordered stack of components with their modality mode and detach listener registration instead of a separate stack for strict modal components, another for all components with modality and a map of detach registrations. The active modal component is the most recent strict entry, and the inert state is updated by comparing it before and after each modality change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@platosha Yes, done. Comparison:
Two small behaviour differences:
The public API is unchanged, and the existing modality, routing and hotswap tests pass. |
|
/code-review |
vaadin-review-bot
left a comment
There was a problem hiding this comment.
Reviewed the changes — left 2 comments.
| Finding | |
|---|---|
| 📝 | Public refreshCurrentRoute now detaches open dialogs, but its Javadoc says nothing about it |
| 🧪 | The inert assertion added to modalVisualComponent_addedAndRemoved_hasModalReturnsCorrectValue cannot fail |
There was a problem hiding this comment.
Around line 1610 — could not attach to the exact diff line.
📝 Public refreshCurrentRoute now detaches open dialogs, but its Javadoc says nothing about it
cleanModalComponents now removes every component with modality on REFRESH_ROUTE, which includes VISUAL ones — i.e. dialogs in their default mode. refreshCurrentRoute(boolean) is public API usable in production, and its Javadoc only talks about re-instantiating the route target and chain.
The internal UIInternals.refreshCurrentRoute doc and the cleanModalComponents comment were both updated; the user-facing method that callers actually read was not.
UI.java:1610 · documentation
There was a problem hiding this comment.
Updated the UI.refreshCurrentRoute(boolean) Javadoc: it now says that components with modality (open dialogs in either STRICT or VISUAL mode) are removed from the UI during the refresh, and that their presence makes the whole route chain refresh regardless of refreshRouteChain.
Replace the new setChildVisuallyModal method with an overload setChildModal(Component, ModalityMode), so UI delegates in one call, and drop the @SInCE tags from the new Javadoc. On route refresh, skip components with modality that are nested inside another one: they go away together with it and must not be taken out of their parent. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
@platosha I ran the review. I fixed three findings in fa4f8aa and left the others as they are, for the reasons below. Fixed
Left as is
|
Also collect UI changes before asserting inert state in the STRICT-to-VISUAL downgrade test so the assertion can actually fail. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
vaadin-review-bot
left a comment
There was a problem hiding this comment.
Reviewed the changes — left 1 comment.
| Finding | |
|---|---|
Dialog's own applyModality() undoes the new VISUAL tracking, so the fix misses several common paths |
|
|
|
|
Documentation Bot: No documentation needed for this change. This is a bug fix: dialogs using the default visual modality ( Nothing was opened in vaadin/docs. If you disagree, the change has to be documented by hand there.
|
… (CP: 25.2) (#26487) This PR cherry-picks changes from the original PR #25417 to branch 25.2. > [!WARNING] > The cherry-pick had merge conflicts that were resolved automatically by Claude Code. Please review the changes carefully. --- > Dialogs are visually modal by default since 25.0, but `ModalityMode.VISUAL` was mapped to `setChildModeless`, so a component with visual modality was not tracked on the server side at all. > > Both code paths that deal with overlays attached to the UI instead of the route were guarded by `UI.hasModalComponent()`, so with an open dialog they became no-ops: > > - `AbstractNavigationStateRenderer` no longer detached the dialog on a route refresh, leaving it visible with outdated contents. > - `Hotswapper` no longer requested a refresh of the whole route chain. > > ## What changed > > - Components set to `ModalityMode.VISUAL` are now tracked in `UIInternals` without making the UI inert. The meaning of `hasModalComponent()` and the inert semantics are unchanged; the new `hasModalityComponent()` / `getModalityComponents()` cover both strict and visual modality, and both call sites take the new information into account. > - All components with modality are kept in a **single recency-ordered stack** of (component, mode, detach registration) entries, replacing the previous strict-only modal component stack. The active modal component is the most recent `STRICT` entry, and the inert state of the UI and its children is updated in one place by comparing the active modal component before and after each modality change. A single stack keeps `getModalityComponents()` in the order the components were set and cannot report a component twice when it switches between modes. > - The detach listener that stops tracking a component is registered once per component and kept in its stack entry, so repeatedly changing the modality of a component does not pile up listeners on its element; it is removed when the component is set modeless. > - Calling `setChildModal` again on the already active modal component now moves it to the top of the stack (above any visually modal component set after it) instead of being a no-op. > - `UI.setChildComponentModal(Component, boolean)` still maps `false` to `MODELESS`, which now also clears visual modality; its Javadoc points visually modal components to the `ModalityMode` overload. `Dialog` needs to report its actual mode through that overload for the fix to cover all paths (re-attach, `setVisible`, `setModality` on an open dialog, add-then-open) — companion change: vaadin/flow-components#10440. > - `cleanModalComponents()` in `AbstractNavigationStateRenderer` now removes all components with modality on `REFRESH_ROUTE`, instead of draining only the strict-modal stack. Modeless components are left untouched. > > Fixes #25415 > > ## API Changes > > ### com.vaadin.flow.component.internal.UIInternals > > ```java > // Added > public boolean hasModalityComponent() // true if a child component with STRICT or VISUAL modality is set; unlike hasModalComponent() it also counts components that only show a modality curtain > public List<Component> getModalityComponents() // child components with STRICT or VISUAL modality, most recently set first, never null > public void setChildModal(Component child, ModalityMode mode) // overload of setChildModal(Component) that sets any modality mode; VISUAL tracks the child as having modality without making the UI and its other components inert > ``` > > > Co-authored-by: totally-not-ai[bot] <290682512+totally-not-ai[bot]@users.noreply.github.com>
… (CP: 25.3) (#10449) This PR cherry-picks changes from the original PR #10440 to branch 25.3. --- > **Review risk:** two-way door — Dialog only; no behavior change with the current Flow version > > ## Summary > `Dialog.applyModality()` reduced the dialog state to a boolean (`opened && visible && modality == STRICT`) and passed it to `UI.setChildComponentModal(Component, boolean)`, which maps `false` to `MODELESS`. An open, visible dialog in `ModalityMode.VISUAL` was therefore reported to the UI as modeless. This passes the dialog's actual `ModalityMode` instead (`MODELESS` when closed or hidden). > > Companion to vaadin/flow#25417, which makes the UI track `VISUAL` components (so that route refresh and hotswap rebuild the full route chain while a visually modal dialog is open). Without this change, `Dialog.applyModality()` drops a visual dialog from that tracking whenever it runs: `setModality(VISUAL)` or `setVisible(...)` on an open dialog, re-attaching a dialog, or `ui.add(dialog)` followed by `open()`. > > ## What changed > - `Dialog.applyModality()` calls `UI.setChildComponentModal(Component, ModalityMode)` with the dialog's modality while it is opened and visible, and `MODELESS` otherwise. > - No behavior change with current Flow: `UI` currently treats `VISUAL` like `MODELESS` on the server. `STRICT` handling is unchanged. > > ## Test summary > - Existing dialog modality and dialog unit tests pass. > - Verified locally against a Flow build that includes vaadin/flow#25417: setting `VISUAL` on an open dialog, toggling visibility, re-attaching an auto-added dialog, and add-then-open all keep the dialog tracked (all four failed before this change). Tests asserting that tracking can be added once the Flow API is released. > > 🤖 Generated with [Claude Code](https://claude.com/claude-code) > Co-authored-by: totally-not-ai[bot] <290682512+totally-not-ai[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
The cherry-pick of #25417 used `Component.findAncestor(SerializablePredicate)`, which was added to main by #26035 and is marked `@since 25.4`. The 25.3 branch only has the `findAncestor(Class)` overload, so `flow-server` failed to compile with "incompatible types: Class is not a functional interface". Walk the ancestors with a local helper instead, mirroring the existing `isComponentElementEqualsOrChild` idiom in the same class. Semantics are unchanged: the component itself is not tested, only its ancestors, so a component with modality nested inside another one is still left in its parent. No public API is added to the maintenance branch. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
… (CP: 25.3) (#26488) This PR cherry-picks changes from the original PR #25417 to branch 25.3. --- > Dialogs are visually modal by default since 25.0, but `ModalityMode.VISUAL` was mapped to `setChildModeless`, so a component with visual modality was not tracked on the server side at all. > > Both code paths that deal with overlays attached to the UI instead of the route were guarded by `UI.hasModalComponent()`, so with an open dialog they became no-ops: > > - `AbstractNavigationStateRenderer` no longer detached the dialog on a route refresh, leaving it visible with outdated contents. > - `Hotswapper` no longer requested a refresh of the whole route chain. > > ## What changed > > - Components set to `ModalityMode.VISUAL` are now tracked in `UIInternals` without making the UI inert. The meaning of `hasModalComponent()` and the inert semantics are unchanged; the new `hasModalityComponent()` / `getModalityComponents()` cover both strict and visual modality, and both call sites take the new information into account. > - All components with modality are kept in a **single recency-ordered stack** of (component, mode, detach registration) entries, replacing the previous strict-only modal component stack. The active modal component is the most recent `STRICT` entry, and the inert state of the UI and its children is updated in one place by comparing the active modal component before and after each modality change. A single stack keeps `getModalityComponents()` in the order the components were set and cannot report a component twice when it switches between modes. > - The detach listener that stops tracking a component is registered once per component and kept in its stack entry, so repeatedly changing the modality of a component does not pile up listeners on its element; it is removed when the component is set modeless. > - Calling `setChildModal` again on the already active modal component now moves it to the top of the stack (above any visually modal component set after it) instead of being a no-op. > - `UI.setChildComponentModal(Component, boolean)` still maps `false` to `MODELESS`, which now also clears visual modality; its Javadoc points visually modal components to the `ModalityMode` overload. `Dialog` needs to report its actual mode through that overload for the fix to cover all paths (re-attach, `setVisible`, `setModality` on an open dialog, add-then-open) — companion change: vaadin/flow-components#10440. > - `cleanModalComponents()` in `AbstractNavigationStateRenderer` now removes all components with modality on `REFRESH_ROUTE`, instead of draining only the strict-modal stack. Modeless components are left untouched. > > Fixes #25415 > > ## API Changes > > ### com.vaadin.flow.component.internal.UIInternals > > ```java > // Added > public boolean hasModalityComponent() // true if a child component with STRICT or VISUAL modality is set; unlike hasModalComponent() it also counts components that only show a modality curtain > public List<Component> getModalityComponents() // child components with STRICT or VISUAL modality, most recently set first, never null > public void setChildModal(Component child, ModalityMode mode) // overload of setChildModal(Component) that sets any modality mode; VISUAL tracks the child as having modality without making the UI and its other components inert > ``` > > > Co-authored-by: totally-not-ai[bot] <290682512+totally-not-ai[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Anton Platonov <anton@vaadin.com>
…2) (#26497) This PR cherry-picks changes from the original PR #26425 to branch 25.2. --- > **Review risk:** two-way door — changes where overlays such as notifications, context menus and nested dialogs are attached while a visually modal dialog is open; easy to revert. > > Fixes #25136 > Builds on #25417 (merged) > > **Behavior deviation** · flow-server · apps that open an overlay while a default (visually modal) `Dialog` is open > > ## Summary > > An overlay opened while a visually modal dialog is showing was attached to the UI, outside the dialog. The dialog's modality curtain blocks pointer events and traps focus outside of it, so the overlay could not be clicked or reached with the keyboard. Overlays are now nested inside the most recently opened strictly or visually modal component. > > **Risks:** > -⚠️ Behavior change: an overlay opened while a visually modal component is showing now becomes a child of that component, so it is removed together with it. This is the same as with strictly modal components. Before, it was attached to the UI, where the user could not reach it on the client. > -⚠️ Public API: one method added to the internal `UIInternals`. > - ✅ No security, memory, serialization, threading, performance or migration impact. > > ## What changed > > - Added `UIInternals.getActiveModalityComponent()`, which returns the most recently set component with `STRICT` or `VISUAL` modality, based on the modality stack from #25417. > - Made `UI.addToModalComponent()` add to that component instead of only to the active strictly modal one. > - Left `hasModalComponent()`, `getActiveModalComponent()` and all inert handling unchanged, so the UI is still only inert for `STRICT`, and shortcut routing through the inert-escaping component works as before. > > ## Test summary > > - An overlay opened while only a visually modal component is showing is nested into it (this flips the test from #25417 that pinned the old attach-to-UI behavior). > - An overlay is nested into a visually modal component opened on top of a strictly modal one. > - A strictly modal component opened on top of a visually modal one is nested in it, its overlays are nested in it and stay interactive, and nesting goes back to the visually modal component once it is removed. > - Existing UI, shortcut and route refresh unit tests pass. > > Co-authored-by: totally-not-ai[bot] <290682512+totally-not-ai[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…3) (#26498) This PR cherry-picks changes from the original PR #26425 to branch 25.3. --- > **Review risk:** two-way door — changes where overlays such as notifications, context menus and nested dialogs are attached while a visually modal dialog is open; easy to revert. > > Fixes #25136 > Builds on #25417 (merged) > > **Behavior deviation** · flow-server · apps that open an overlay while a default (visually modal) `Dialog` is open > > ## Summary > > An overlay opened while a visually modal dialog is showing was attached to the UI, outside the dialog. The dialog's modality curtain blocks pointer events and traps focus outside of it, so the overlay could not be clicked or reached with the keyboard. Overlays are now nested inside the most recently opened strictly or visually modal component. > > **Risks:** > -⚠️ Behavior change: an overlay opened while a visually modal component is showing now becomes a child of that component, so it is removed together with it. This is the same as with strictly modal components. Before, it was attached to the UI, where the user could not reach it on the client. > -⚠️ Public API: one method added to the internal `UIInternals`. > - ✅ No security, memory, serialization, threading, performance or migration impact. > > ## What changed > > - Added `UIInternals.getActiveModalityComponent()`, which returns the most recently set component with `STRICT` or `VISUAL` modality, based on the modality stack from #25417. > - Made `UI.addToModalComponent()` add to that component instead of only to the active strictly modal one. > - Left `hasModalComponent()`, `getActiveModalComponent()` and all inert handling unchanged, so the UI is still only inert for `STRICT`, and shortcut routing through the inert-escaping component works as before. > > ## Test summary > > - An overlay opened while only a visually modal component is showing is nested into it (this flips the test from #25417 that pinned the old attach-to-UI behavior). > - An overlay is nested into a visually modal component opened on top of a strictly modal one. > - A strictly modal component opened on top of a visually modal one is nested in it, its overlays are nested in it and stay interactive, and nesting goes back to the visually modal component once it is removed. > - Existing UI, shortcut and route refresh unit tests pass. > > Co-authored-by: totally-not-ai[bot] <290682512+totally-not-ai[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…5.3) (#10459) This PR cherry-picks changes from the original PR #10457 to branch 25.3. --- > ## Description > > Related to vaadin/flow#26425 > > Flow now adds auto-added overlays to the most recent component with `STRICT` or `VISUAL` modality, not only `STRICT`. This change came in vaadin/flow#26425, which builds on vaadin/flow#25417. `DialogModalityTest` still expected the old behavior and failed. > > - Renamed `visualModal_openSecondDialog_addedToUI` to `visualModal_openSecondDialog_addedToFirstDialog` and changed it to expect the first dialog as the parent of a second dialog opened over a visually modal dialog > > ## Type of change > > - Tests > Co-authored-by: Sascha Ißbrücker <sissbruecker@vaadin.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
**Review risk:** two-way door — changes where overlays such as notifications, context menus and nested dialogs are attached while a visually modal dialog is open; easy to revert. Fixes vaadin#25136 Builds on vaadin#25417 (merged) **Behavior deviation** · flow-server · apps that open an overlay while a default (visually modal) `Dialog` is open ## Summary An overlay opened while a visually modal dialog is showing was attached to the UI, outside the dialog. The dialog's modality curtain blocks pointer events and traps focus outside of it, so the overlay could not be clicked or reached with the keyboard. Overlays are now nested inside the most recently opened strictly or visually modal component. **Risks:** -⚠️ Behavior change: an overlay opened while a visually modal component is showing now becomes a child of that component, so it is removed together with it. This is the same as with strictly modal components. Before, it was attached to the UI, where the user could not reach it on the client. -⚠️ Public API: one method added to the internal `UIInternals`. - ✅ No security, memory, serialization, threading, performance or migration impact. ## What changed - Added `UIInternals.getActiveModalityComponent()`, which returns the most recently set component with `STRICT` or `VISUAL` modality, based on the modality stack from vaadin#25417. - Made `UI.addToModalComponent()` add to that component instead of only to the active strictly modal one. - Left `hasModalComponent()`, `getActiveModalComponent()` and all inert handling unchanged, so the UI is still only inert for `STRICT`, and shortcut routing through the inert-escaping component works as before. ## Test summary - An overlay opened while only a visually modal component is showing is nested into it (this flips the test from vaadin#25417 that pinned the old attach-to-UI behavior). - An overlay is nested into a visually modal component opened on top of a strictly modal one. - A strictly modal component opened on top of a visually modal one is nested in it, its overlays are nested in it and stay interactive, and nesting goes back to the visually modal component once it is removed. - Existing UI, shortcut and route refresh unit tests pass. --------- Co-authored-by: totally-not-ai[bot] <290682512+totally-not-ai[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
|
This ticket/PR has been released with Vaadin 25.4.0-alpha4. |



Dialogs are visually modal by default since 25.0, but
ModalityMode.VISUALwas mapped tosetChildModeless, so a component with visual modality was not tracked on the server side at all.Both code paths that deal with overlays attached to the UI instead of the route were guarded by
UI.hasModalComponent(), so with an open dialog they became no-ops:AbstractNavigationStateRendererno longer detached the dialog on a route refresh, leaving it visible with outdated contents.Hotswapperno longer requested a refresh of the whole route chain.What changed
ModalityMode.VISUALare now tracked inUIInternalswithout making the UI inert. The meaning ofhasModalComponent()and the inert semantics are unchanged; the newhasModalityComponent()/getModalityComponents()cover both strict and visual modality, and both call sites take the new information into account.STRICTentry, and the inert state of the UI and its children is updated in one place by comparing the active modal component before and after each modality change. A single stack keepsgetModalityComponents()in the order the components were set and cannot report a component twice when it switches between modes.setChildModalagain on the already active modal component now moves it to the top of the stack (above any visually modal component set after it) instead of being a no-op.UI.setChildComponentModal(Component, boolean)still mapsfalsetoMODELESS, which now also clears visual modality; its Javadoc points visually modal components to theModalityModeoverload.Dialogneeds to report its actual mode through that overload for the fix to cover all paths (re-attach,setVisible,setModalityon an open dialog, add-then-open) — companion change: fix: pass dialog modality mode to UI instead of a strict flag flow-components#10440.cleanModalComponents()inAbstractNavigationStateRenderernow removes all components with modality onREFRESH_ROUTE, instead of draining only the strict-modal stack. Modeless components are left untouched.Fixes #25415
API Changes
com.vaadin.flow.component.internal.UIInternals