I found out an interesting issue with the way vaadin determines if finds a UI. This behavior is dependent on the assumption that window.name in the DOM is not already set to non-empty string. If the window.name is already preset before vaadin is loaded, this pre-cludes correct UI loading especially in multiple tabs. Here is the test scenario
- Open a window with a vaadin app, whose window.name (in browser DOM) is preset to “abc”
- interact with the vaadin UI in window 1
- Open another window with the same vaadin app whose window name is also preset to “abc”
- Interact with vaadin UI in window 2
- Now switch tabs and interact with vaadin UI in window 1
- Vaadin will now throw the communication error alert in window 1
After substantial debugging the following is the root cause
Vaadin computes the embedId from the window name and app name. If window name is an empty string then vaadin generated a new DOM window name, otherwise it uses the preset window name.
- Open a window with a vaadin app, whose window name (in browser DOM) is preset to “abc”
[list=1]
- In com.vaadin.server.VaadinSession.addUI(UI) new UI is added with an embedId of abc.-number
- No previous UI exists with the same embed id at this point
[/list] - interact with the vaadin UI in window 1 – events are processed as usual
- Open another window with the same vaadin app whose window name is also preset to “abc”
[list=1]
- In com.vaadin.server.VaadinSession.addUI(UI) new UI is added with an embedId of abc.-number (same embed ID as step1.1)
- Previous UI (window 1) is found in the embedIdMap
- Call close on previousUI (window 1)
- This sets closing=true when finally com.vaadin.ui.UI.close() is called
[/list] - Interact with vaadin UI in window 2 – events are processed as usual since this UI is in good state
- Now switch tabs and interact with vaadin UI in window 1
[list=1]
- At some point during request processing com.vaadin.server.VaadinService.cleanupSession(VaadinSession) is called which in turn calls com.vaadin.server.VaadinService.removeClosedUIs(VaadinSession)
- Since the window 1 UI closing flag is set to true, this is removed from the session
- In com.vaadin.server.communication.UidlRequestHandler.synchronizedHandleRequest(VaadinSession, VaadinRequest, VaadinResponse) UI is not found in session and UI Not found error is written response.getWriter().write(getUINotFoundErrorJSON(session.getService(), request));
[/list] - Vaadin will now throw the communication error alert in window
Currently using vaadin version 7.3.6
IMO the solution should be that vaadin not use standard DOM properties and rather create vaadin specific properties which has fewer chances of corruption.