From 746c40494038fd9536ab1bd03bab14ae345b7272 Mon Sep 17 00:00:00 2001 From: caalador Date: Thu, 21 Nov 2024 14:00:11 +0200 Subject: [PATCH] fix: vaadin/router added with react-router (#20522) Exclude vaadin/router when runing in react mode. Without exclusion vaadin/router gets added from the vaadin-core.json package in platform. Fixes #20496 --- .../frontend/VersionsJsonConverter.java | 5 +++ .../frontend/VersionsJsonConverterTest.java | 35 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/flow-server/src/main/java/com/vaadin/flow/server/frontend/VersionsJsonConverter.java b/flow-server/src/main/java/com/vaadin/flow/server/frontend/VersionsJsonConverter.java index bfeb9afacd0..9c5027c6b69 100644 --- a/flow-server/src/main/java/com/vaadin/flow/server/frontend/VersionsJsonConverter.java +++ b/flow-server/src/main/java/com/vaadin/flow/server/frontend/VersionsJsonConverter.java @@ -69,6 +69,7 @@ class VersionsJsonConverter { * Mode value for dependency for all modes. */ public static final String MODE_ALL = "all"; // same as empty string + private static final Object VAADIN_ROUTER = "@vaadin/router"; private final JsonObject convertedObject; @@ -151,6 +152,10 @@ private void addDependency(JsonObject obj) { if (Objects.equals(npmName, VAADIN_CORE_NPM_PACKAGE)) { return; } + if (reactEnabled && Objects.equals(npmName, VAADIN_ROUTER)) { + exclusions.add(npmName); + return; + } if (!isIncludedByMode(mode)) { return; } diff --git a/flow-server/src/test/java/com/vaadin/flow/server/frontend/VersionsJsonConverterTest.java b/flow-server/src/test/java/com/vaadin/flow/server/frontend/VersionsJsonConverterTest.java index 4a9a3aecfc6..059f75b5dab 100644 --- a/flow-server/src/test/java/com/vaadin/flow/server/frontend/VersionsJsonConverterTest.java +++ b/flow-server/src/test/java/com/vaadin/flow/server/frontend/VersionsJsonConverterTest.java @@ -228,6 +228,41 @@ public void reactRouterNotUsed_reactComponentsIgnored() { convertedJson.getString("@polymer/iron-list")); } + @Test + public void reactRouterUsed_noVaadinRouterAdded() { + String json = """ + { + "core": { + "flow": { + "javaVersion": "3.0.0.alpha17" + }, + }, + "vaadin-router": { + "npmName": "@vaadin/router", + "jsVersion": "2.0.0" + }, + "react": { + "react-components": { + "jsVersion": "24.4.0-alpha7", + "npmName": "@vaadin/react-components", + "mode": "react" + } + }, + "platform": "foo" + } + """.formatted(VAADIN_CORE_NPM_PACKAGE); + + VersionsJsonConverter convert = new VersionsJsonConverter( + Json.parse(json), true); + JsonObject convertedJson = convert.getConvertedJson(); + + Assert.assertFalse( + "Found @vaadin/router even though it should not be in use.", + convertedJson.hasKey("@vaadin/router")); + Assert.assertTrue("Missing react-components", + convertedJson.hasKey("@vaadin/react-components")); + } + @Test public void testModeProperty() { String json = """