Skip to content

Commit 23b2967

Browse files
authored
fix: use direct VAADIN path for push script URL (#22827) (CP: 24.9) (#22854)
The correct approach is to use the direct VAADIN/... path without any navigation prefix. This works because the <base href> already points to the servlet root, so relative URLs resolve correctly to {context-path}/{servlet-path}/VAADIN/... Fixes #22826
1 parent 6458831 commit 23b2967

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1507,18 +1507,18 @@ protected static String getPushScript(BootstrapContext context) {
15071507
VaadinRequest request = context.getRequest();
15081508
// Parameter appended to JS to bypass caches after version upgrade.
15091509
String versionQueryParam = "?v=" + Version.getBuildHash();
1510-
// Load client-side dependencies for push support
1511-
String pushJSPath = BootstrapHandlerHelper.getServiceUrl(request) + "/";
15121510

1511+
String pushJs;
15131512
if (request.getService().getDeploymentConfiguration()
15141513
.isProductionMode()) {
1515-
pushJSPath += ApplicationConstants.VAADIN_PUSH_JS;
1514+
pushJs = ApplicationConstants.VAADIN_PUSH_JS;
15161515
} else {
1517-
pushJSPath += ApplicationConstants.VAADIN_PUSH_DEBUG_JS;
1516+
pushJs = ApplicationConstants.VAADIN_PUSH_DEBUG_JS;
15181517
}
15191518

1520-
pushJSPath += versionQueryParam;
1521-
return pushJSPath;
1519+
// Use direct path - the <base href> already points to the servlet root,
1520+
// so VAADIN/... resolves correctly to {context}/{servlet}/VAADIN/...
1521+
return pushJs + versionQueryParam;
15221522
}
15231523

15241524
protected static void setupErrorDialogs(Element style) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,9 @@ private void addDevTools(Document indexDocument,
422422

423423
indexDocument.body().appendChild(new Element("vaadin-dev-tools"));
424424

425-
String pushUrl = BootstrapHandlerHelper.getServiceUrl(request) + "/"
426-
+ ApplicationConstants.VAADIN_PUSH_DEBUG_JS;
427-
addScriptSrc(indexDocument, pushUrl);
425+
// Use direct path - the <base href> already points to the servlet root,
426+
// so VAADIN/... resolves correctly to {context}/{servlet}/VAADIN/...
427+
addScriptSrc(indexDocument, ApplicationConstants.VAADIN_PUSH_DEBUG_JS);
428428
}
429429

430430
static boolean isAllowedDevToolsHost(AbstractConfiguration configuration,

flow-server/src/test/java/com/vaadin/flow/server/communication/JavaScriptBootstrapHandlerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public void should_respondPushScript_when_enabledInDeploymentConfiguration()
173173

174174
// Using regex, because version depends on the build
175175
Assert.assertTrue(json.getString("pushScript").matches(
176-
"^\\./VAADIN/static/push/vaadinPush\\.js\\?v=[\\w\\.\\-]+$"));
176+
"^VAADIN/static/push/vaadinPush\\.js\\?v=[\\w\\.\\-]+$"));
177177
}
178178

179179
@Test
@@ -191,7 +191,7 @@ public void should_respondPushScript_when_nonRootServletPath()
191191

192192
// Using regex, because version depends on the build
193193
Assert.assertTrue(json.getString("pushScript").matches(
194-
"^\\./VAADIN/static/push/vaadinPush\\.js\\?v=[\\w\\.\\-]+$"));
194+
"^VAADIN/static/push/vaadinPush\\.js\\?v=[\\w\\.\\-]+$"));
195195
}
196196

197197
@Test
@@ -226,7 +226,7 @@ public void should_respondPushScript_when_annotatedInAppShell()
226226

227227
// Using regex, because version depends on the build
228228
Assert.assertTrue(json.getString("pushScript").matches(
229-
"^\\./VAADIN/static/push/vaadinPush\\.js\\?v=[\\w\\.\\-]+$"));
229+
"^VAADIN/static/push/vaadinPush\\.js\\?v=[\\w\\.\\-]+$"));
230230
}
231231

232232
@Test

0 commit comments

Comments
 (0)