Skip to content

Commit 66a4888

Browse files
authored
fix: Prefix web component client app with wc- (#15315)
Avoids conflicts with the application
1 parent f9611c6 commit 66a4888

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

flow-server/src/main/java/com/vaadin/flow/component/UI.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,29 @@ public int getUIId() {
206206
* the id of the new ui
207207
*
208208
* @see #getUIId()
209+
* @deprecated Use {@link #doInit(VaadinRequest, int, String)} instead
209210
*/
211+
@Deprecated
210212
public void doInit(VaadinRequest request, int uiId) {
213+
doInit(request, uiId,
214+
getSession().getService().getMainDivId(getSession(), request));
215+
}
216+
217+
/**
218+
* Internal initialization method, should not be overridden. This method is
219+
* not declared as final because that would break compatibility with e.g.
220+
* CDI.
221+
*
222+
* @param request
223+
* the initialization request
224+
* @param uiId
225+
* the id of the new ui
226+
* @param appId
227+
* the application id
228+
*
229+
* @see #getUIId()
230+
*/
231+
public void doInit(VaadinRequest request, int uiId, String appId) {
211232
if (this.uiId != -1) {
212233
String message = "This UI instance is already initialized (as UI id "
213234
+ this.uiId
@@ -224,8 +245,6 @@ public void doInit(VaadinRequest request, int uiId) {
224245
}
225246
this.uiId = uiId;
226247

227-
String appId = getSession().getService().getMainDivId(getSession(),
228-
request);
229248
appId = APP_ID_REPLACE_PATTERN.matcher(appId).replaceAll("");
230249
getInternals().setAppId(appId);
231250

flow-server/src/main/java/com/vaadin/flow/component/webcomponent/WebComponentUI.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public class WebComponentUI extends UI {
5959
public static final String NO_NAVIGATION = "Navigation is not available for WebComponents";
6060

6161
@Override
62-
public void doInit(VaadinRequest request, int uiId) {
63-
super.doInit(request, uiId);
62+
public void doInit(VaadinRequest request, int uiId, String appId) {
63+
super.doInit(request, uiId, appId);
6464

6565
assignThemeVariant();
6666
getEventBus().addListener(WebComponentConnectEvent.class,

flow-server/src/main/java/com/vaadin/flow/server/BootstrapHandler.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -362,9 +362,6 @@ public PushMode getPushMode() {
362362
/**
363363
* Gets the application id.
364364
*
365-
* The application id is defined by
366-
* {@link VaadinService#getMainDivId(VaadinSession, VaadinRequest)}
367-
*
368365
* @return the application id
369366
*/
370367
public String getAppId() {
@@ -1529,7 +1526,7 @@ protected BootstrapContext createAndInitUI(Class<? extends UI> uiClass,
15291526

15301527
// Set thread local here so it is available in init
15311528
UI.setCurrent(ui);
1532-
ui.doInit(request, session.getNextUIid());
1529+
ui.doInit(request, session.getNextUIid(), context.getAppId());
15331530
session.addUI(ui);
15341531

15351532
// After init and adding UI to session fire init listeners.

flow-server/src/main/java/com/vaadin/flow/server/communication/WebComponentBootstrapHandler.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ public <T extends Annotation> Optional<T> getPageConfigurationAnnotation(
9595
protected Optional<PwaRegistry> getPwaRegistry() {
9696
return Optional.empty();
9797
}
98+
99+
@Override
100+
public String getAppId() {
101+
return "wc-" + super.getAppId();
102+
}
98103
}
99104

100105
private static class WebComponentBootstrapPageBuilder

flow-server/src/test/java/com/vaadin/flow/component/UITest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ private static UI createTestUI() {
189189
MockLogger mockLogger = new MockLogger();
190190
UI ui = new UI() {
191191
@Override
192-
public void doInit(VaadinRequest request, int uiId) {
192+
public void doInit(VaadinRequest request, int uiId, String appId) {
193193

194194
}
195195

0 commit comments

Comments
 (0)