Repository navigation
fix: include only react-components in package.json - #18707
Conversation
| for (String key : platformPinnedDependencies.keys()) { | ||
| if (options.isReactEnabled() && isReactModuleAvailable() | ||
| && !FrontendUtils.isPackageKeyReactComponents(key) | ||
| && pinnedPlatformDependencies.contains(key)) { |
There was a problem hiding this comment.
the contains(key) is always true here as we are iterating the same set of keys as added to the pinnedPlatformDependencies
| if (options.isReactEnabled() && isReactModuleAvailable() | ||
| && !FrontendUtils.isPackageKeyReactComponents(dep.getKey()) | ||
| && pinnedPlatformDependencies.contains(dep.getKey())) { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
Trusting the platformPinnedDependencies content as boolean reactComponents = pinnedPlatformDependencies.contains("@vaadin/react-components"); would make this:
| if (options.isReactEnabled() && isReactModuleAvailable() | |
| && !FrontendUtils.isPackageKeyReactComponents(dep.getKey()) | |
| && pinnedPlatformDependencies.contains(dep.getKey())) { | |
| continue; | |
| } | |
| if (reactComponents | |
| && pinnedPlatformDependencies.contains(dep.getKey())) { | |
| continue; | |
| } |
Also is this no here just to not add the @NpmPackage annotations from server Component definitions?
There was a problem hiding this comment.
Yes, basically so. Without this just having vaadin-core dependency would end up adding all web-components. Or having any dependency with @NpmPackage with core components.
| * components, {@code false} otherwise | ||
| */ | ||
| static boolean isPackageKeyReactComponents(String key) { | ||
| return key.equals("@vaadin/react-components"); |
There was a problem hiding this comment.
As a string check this sounds a bit easy to fail.
A better way would be to collect all the possibilities in the versions.json found under the react (perhaps in the future react-pro) object which is formatted as:
"react": {
"react-components": {
"jsVersion": "24.4.0-alpha13",
"npmName": "@vaadin/react-components"
}
},
There was a problem hiding this comment.
Yep, I agree that making it future proof by reading from the json object would be better. It's just that we only have that @vaadin/react-components in react now so kept it simple as possible for this reason only.
caalador
left a comment
There was a problem hiding this comment.
After removing the unused method it looks fine.
| || !oldHash.equals(newHash); | ||
| } | ||
|
|
||
| private boolean isReactModuleAvailable() { |
There was a problem hiding this comment.
This is now not needed as it's not used anywhere in the class
mshabarov
left a comment
There was a problem hiding this comment.
The case where package.json isn't exist looks working well, but if package.json exists before starting the app and it has WCs, then they aren't removed.
| if (reactComponents | ||
| && !FrontendUtils.isPackageKeyReactComponents(key)) { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
This looks dangerous and probably not correct, as it skips adding everything from platform's versions json that isn't @vaadin/react-components. Besides web-component, versions json has lumo, polymer, bundles, statistics and potentially other "non-component" dependencies that are skipped with this codes.
Also, if I run this patch with the existing package.json containing the web-components, this patch doesn't remove them from, probably because the logic below in this method isn't running, which is incorrect.
But from the other side, how Flow can only extract semantically web-components entries...Should we change the structure of versions.json in the platform, so it would store web-components in a separated sub-list?
There was a problem hiding this comment.
We need a sub-list. Either in versions.json or Flow can populate it. Basically it should be a list of all @vaadin/* dependencies in react-component's package.json. We could even start with reading this list from file in flow.
There was a problem hiding this comment.
It's not removing existing dependency as that's how the package.json update works in general. but if you think, it's safe to remove existing, it could be done too. Just not adding it is probably safer.
There was a problem hiding this comment.
Well, retaining them would require package.json removal during migration to effectively trigger this feature, but this is probably fine. Maybe it's indeed safer to only not adding them.
Having a sub-list is discussible, see the corresponding discussion in Slack.
There was a problem hiding this comment.
My main concern vs merging this change is these messages in the logs:
2024-02-19T13:28:30.526+02:00 INFO 10210 --- [onPool-worker-1] c.v.f.server.frontend.TaskUpdateImports :
Failed to find the following imports in the `node_modules` tree:
- @vaadin/polymer-legacy-adapter/style-modules.js
If the build fails, check that npm packages are installed.
To fix the build remove `package-lock.json` and `node_modules` directory to reset modules.
In addition you may run `npm install` to fix `node_modules` tree structure.
@vaadin/bundles npm package is not found, Vaadin component dependency bundles are disabled.
Error: The following dependencies are imported but could not be resolved:
2024-02-19T13:28:36.541+02:00 INFO 10210 --- [v-server-output] c.v.b.devserver.DevServerOutputTracker :
2024-02-19T13:28:36.541+02:00 INFO 10210 --- [v-server-output] c.v.b.devserver.DevServerOutputTracker : @vaadin/polymer-legacy-adapter/style-modules.js
These shouldn't be logged at least if we think that there is no impact on applications.
There was a problem hiding this comment.
Let's put on hold this PR until we decide about a solution to add/remove only components.
|
We have to implement the following feature for components packages dynamic management:
|
| continue; | ||
| } | ||
| JsonObject json = (JsonObject) value; | ||
| if (!isIncludedByMode(json)) { |
There was a problem hiding this comment.
Now with this new method the old approach above (!reactEnabled && isReactObject(key)) isn't needed anymore.
Flow should add or not to add the npm dependency based on this new mode value.
There was a problem hiding this comment.
Also IMO it would be better to structure it as:
if (isIncludedByMode(json)) {
if (json.hasKey(NPM_NAME)) {
addDependency(json);
} else {
collectDependencies(json);
}
}There was a problem hiding this comment.
Current code does not require "mode: react" for react dependencies. If we change this so that "mode: react" is needed in version.json, then we need to add it in platform versions.json and wait for next snapshot before we merge this PR (this takes more time naturally).
If we keep it as it is, we can merge this/platform independently. Which path should we take?
There was a problem hiding this comment.
Discussed and decided to add react mode in platform and this means that platform PR needs to be merged first before this PR can be merged (after related changes). In other words, we will not depend on "react" and "react-pro" keys anymore. We use "mode: react" feature instead.
| private static final String JS_VERSION = "jsVersion"; | ||
| private static final String NPM_NAME = "npmName"; | ||
| private static final String NPM_VERSION = "npmVersion"; | ||
| private static final String MODE = "mode"; |
There was a problem hiding this comment.
Better to make it private so platform's codes can reuse it if necessary.
There was a problem hiding this comment.
I assume you mean public.
| * @return {@code true} if the key is a package key for a Vaadin react | ||
| * components, {@code false} otherwise | ||
| */ | ||
| static boolean isPackageKeyReactComponents(String key) { |
There was a problem hiding this comment.
Looks like this isn't needed anymore.
| } else if (reactEnabled) { | ||
| return MODE_REACT.equalsIgnoreCase(mode); | ||
| } else { | ||
| return MODE_LIT.equalsIgnoreCase(mode); |
There was a problem hiding this comment.
I propose to add a debug logging to each case, showing the package name and it's version.
| + "\"react\": {\n" + | ||
| " \"react-components\": {\n" + | ||
| " \"jsVersion\": \"24.4.0-alpha13\",\n" + | ||
| " \"npmName\": \"@vaadin/react-components\"\n" + |
There was a problem hiding this comment.
this needs a react mode ?
b26c843 to
daf0561
Compare
mshabarov
left a comment
There was a problem hiding this comment.
LGTM, except that for some reason this PR gets not-related changes from other commits.
Needs a clean-up and rebase.
It's just how github shows commits after rebasing. So it's already rebased. |
|
I see some other commits in your branch. I propose to revert them and squash all the commits. Then merge latest main. |
When React is enabled, package.json update includes only @vaadin/react-components and excludes all other @vaadin/* web-components pinned by platform versions (core and pro). React components are wrappers for web-components. When React is disabled, only web-components are updated in the package.json. Fixes: #18684
Reverted part of the package.json updating back to previous and implemented support for `mode` in versions.json. Value can be `lit`, `react`, `all` or empty (or non-existing). Dependencies are filtered based on the `mode` property and active React mode.
daf0561 to
bd95de0
Compare
|



When React is enabled, package.json update includes only @vaadin/react-components and excludes all other @vaadin/* web-components pinned by platform versions (core and pro). React components are wrappers for web-components. When React is disabled, only web-components are updated in the package.json.
Fixes: #18684
Note! This PR in platform must be merged before this PR.