Skip to content

Commit ff318c9

Browse files
authored
fix: use direct VAADIN path for push script URL (#22827)
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 a18581f commit ff318c9

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
@@ -1509,18 +1509,18 @@ protected static String getPushScript(BootstrapContext context) {
15091509
VaadinRequest request = context.getRequest();
15101510
// Parameter appended to JS to bypass caches after version upgrade.
15111511
String versionQueryParam = "?v=" + Version.getBuildHash();
1512-
// Load client-side dependencies for push support
1513-
String pushJSPath = BootstrapHandlerHelper.getServiceUrl(request) + "/";
15141512

1513+
String pushJs;
15151514
if (request.getService().getDeploymentConfiguration()
15161515
.isProductionMode()) {
1517-
pushJSPath += ApplicationConstants.VAADIN_PUSH_JS;
1516+
pushJs = ApplicationConstants.VAADIN_PUSH_JS;
15181517
} else {
1519-
pushJSPath += ApplicationConstants.VAADIN_PUSH_DEBUG_JS;
1518+
pushJs = ApplicationConstants.VAADIN_PUSH_DEBUG_JS;
15201519
}
15211520

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

15261526
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
@@ -445,9 +445,9 @@ private void addDevTools(Document indexDocument,
445445

446446
indexDocument.body().appendChild(new Element("vaadin-dev-tools"));
447447

448-
String pushUrl = BootstrapHandlerHelper.getServiceUrl(request) + "/"
449-
+ ApplicationConstants.VAADIN_PUSH_DEBUG_JS;
450-
addScriptSrc(indexDocument, pushUrl);
448+
// Use direct path - the <base href> already points to the servlet root,
449+
// so VAADIN/... resolves correctly to {context}/{servlet}/VAADIN/...
450+
addScriptSrc(indexDocument, ApplicationConstants.VAADIN_PUSH_DEBUG_JS);
451451
}
452452

453453
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
@@ -170,7 +170,7 @@ public void should_respondPushScript_when_enabledInDeploymentConfiguration()
170170

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

176176
@Test
@@ -188,7 +188,7 @@ public void should_respondPushScript_when_nonRootServletPath()
188188

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

194194
@Test
@@ -223,7 +223,7 @@ public void should_respondPushScript_when_annotatedInAppShell()
223223

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

229229
@Test

0 commit comments

Comments
 (0)