UIDetachedException was thrown when session was active

The app and browser are running normally. As a matter of fact, I was able to refresh the page with new content by manually refreshing the browser. So why would a UIDetachedException get thrown if the session is still active?

public class WodView extends VerticalLayout implements AfterNavigationObserver {
    private UI ui;
	
 @Override
    protected void onAttach(AttachEvent attachEvent) {
        ui = attachEvent.getUI();
    }
	
 public void refresh(ZonedDateTime zonedDateTime) {
        try {
            ui.access(() -> {
                ui.getSession().lock();
                init(zonedDateTime);
                ui.getSession().unlock();
                ui.push();
            });
        } catch (UIDetachedException e) {
            System.out.println("UI is detached");
        }
    }

Hi Brian,

Without seeing how refresh is getting called its a little hard to tell what is happening. In any case, you need to make sure that you clear ui and stop refreshing in the onDetach method.

Maybe the UI was created a second time and the first one was detached?

That happens eg. when browser refresh was done by the user.