You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
UI locking: add UI lock API that delegates to the session lock #27580
First step towards per-UI locking: introduce the UI lock API without changing behaviour, so it becomes explicit which framework code protects UI state and which protects session state.
Scope
Add UI.getLockInstance(), lock(), unlock(), hasLock(), checkHasLock() and getPendingAccessQueue(). For now they delegate to the session lock and throw UIDetachedException when the UI is detached.
Change framework code that protects UI state from session.checkHasLock() to ui.checkHasLock(): UIInternals, StateTree, Router, BeforeLeaveEvent, ValueSignal, …
Acceptance criteria
No behaviour change: all existing tests pass unchanged.
Unit tests for the new UI methods, including the detached-UI case.
Add-ons can start migrating from session to UI lock checks.
Triage: valid enhancement. Not on the default branch yet; it adds public API to UI, so a maintainer should confirm a few points first.
Where it fits: the new UI methods mirror the existing VaadinSession lock methods and, for now, just delegate to the session lock. Framework checks that guard UI state then call the UI instead of the session.
Caveat: "throw when detached" cannot apply to every method. Today the UI state tree and ValueSignal quietly skip the lock check when the UI has no session. Components of a detached or never-attached UI are routinely changed, for example in unit tests. If checkHasLock() threw there, it would break the "no behaviour change" goal.
Next step: add the delegating API and move the UI-state checks over, keeping today's detached-UI tolerance. 1. OK to add this public UI API now, before step 0 is settled? (recommended: yes — it only delegates and copies the VaadinSession names) 2. On a detached UI: lock(), unlock() and getLockInstance() throw UIDetachedException, hasLock() returns false, and checkHasLock() does nothing? (recommended: yes) 3. Also add getLastLocked() / getLastUnlocked(), as listed in Locking issue when using Multiple Tabs in a near Real-Time-Application #24187? (recommended: no, add them with the per-UI lock). One reply from a maintainer mentioning @totally-not-ai (e.g. @totally-not-ai do it, or @totally-not-ai 1: yes, 2: yes, 3: no) is enough for me to open a PR; others are welcome to weigh in.
Call sites that check the lock for UI state today
UIInternals: eight session.checkHasLock() calls, plus a session != null && session.hasLock() check.
StateTree.checkHasLock(): skips the check when the session is null.
Router (ui.getSessionOrThrow().checkHasLock()), BeforeLeaveEvent (getSessionOrThrow().hasLock(), in setReferences and proceed).
UI.push() throws UIDetachedException and then calls session.checkHasLock(). That's the existing precedent for the throwing methods.
Session-scoped checks (StreamResourceRegistry, VaadinService, VaadinSession itself) should stay on the session lock.
Notes for the implementation
Each new method should keep the exact exception type and message that its call site produces today. getSessionOrThrow() call sites already throw on a detached UI. StateTree and ValueSignal treat it as "no check" or "not locked".
getPendingAccessQueue() returns the session queue for now. UI.access() keeps using the session queue until step 3.
Tests: the new methods with an attached UI, a detached UI and a never-attached UI; the existing suites should pass unchanged.
Activity
totally-not-ai commentedon Dec 1, 2026
Triage: valid enhancement. Not on the default branch yet; it adds public API to
UI, so a maintainer should confirm a few points first.UImethods mirror the existingVaadinSessionlock methods and, for now, just delegate to the session lock. Framework checks that guard UI state then call the UI instead of the session.ValueSignalquietly skip the lock check when the UI has no session. Components of a detached or never-attached UI are routinely changed, for example in unit tests. IfcheckHasLock()threw there, it would break the "no behaviour change" goal.UIAPI now, before step 0 is settled? (recommended: yes — it only delegates and copies theVaadinSessionnames) 2. On a detached UI:lock(),unlock()andgetLockInstance()throwUIDetachedException,hasLock()returnsfalse, andcheckHasLock()does nothing? (recommended: yes) 3. Also addgetLastLocked()/getLastUnlocked(), as listed in Locking issue when using Multiple Tabs in a near Real-Time-Application #24187? (recommended: no, add them with the per-UI lock). One reply from a maintainer mentioning @totally-not-ai (e.g.@totally-not-ai do it, or@totally-not-ai 1: yes, 2: yes, 3: no) is enough for me to open a PR; others are welcome to weigh in.Call sites that check the lock for UI state today
UIInternals: eightsession.checkHasLock()calls, plus asession != null && session.hasLock()check.StateTree.checkHasLock(): skips the check when the session isnull.Router(ui.getSessionOrThrow().checkHasLock()),BeforeLeaveEvent(getSessionOrThrow().hasLock(), insetReferencesandproceed).ValueSignal:session == null || !session.hasLock().UI.push()throwsUIDetachedExceptionand then callssession.checkHasLock(). That's the existing precedent for the throwing methods.StreamResourceRegistry,VaadinService,VaadinSessionitself) should stay on the session lock.Notes for the implementation
getSessionOrThrow()call sites already throw on a detached UI.StateTreeandValueSignaltreat it as "no check" or "not locked".getPendingAccessQueue()returns the session queue for now.UI.access()keeps using the session queue until step 3.