Restore dynamic component decorators#4528
Restore dynamic component decorators#4528alexandrevryghem wants to merge 9 commits intoDSpace:mainfrom
Conversation
…orator maps Co-authored-by: Nona Luypaert <nona.luypaert@atmire.com> Co-authored-by: Alexandre Vryghem <alexandre@atmire.com>
Co-authored-by: Alexandre Vryghem <alexandre@atmire.com>
5c64f85 to
7952510
Compare
…hods, remove duplicate logic
There was a problem hiding this comment.
Hello @alexandrevryghem , @artlowel ,
Many thanks for these changes. I’ve taken an initial look at the PR and performed some testing, and I wanted to share some feedback with you.
Overall, I believe this PR is an improvement over the previous static map approach, both in terms of bundle size and maintainability. It also brings back the decorator functionality, which is definitely a nice feature to have.
During my testing, however, I noticed that the script is triggered multiple times during the build process. This could be related to how files are currently being watched by the Webpack plugin, as the script appears to fire on any type of file change. This behavior could lead to unnecessary resource usage and longer build times, especially in development mode.
Additionally, the way the decorators are currently generated raises some concerns regarding the upcoming migration to Nx. As it stands, this kind of independent build process would be difficult to align with Nx’s principles—particularly the project isolation model—and might even break it.
I think it would be best to tailor this solution within the context of an Nx workspace, rethinking how decorators are built. For example, we could isolate each decorator in its own library and ensure the script rebuilds only the files within those libraries when changes occur.
In any case, I believe it would be valuable to discuss this in one of the upcoming community calls, so we can gather feedback from other developers as well.
|
Hi @alexandrevryghem, |
|
@FrancescoMolinaro Thnx for the review & sorry for the delayed response. I tested the new NX PR, alongside this script and verified that both PRs are compatible. The only thing we would need to change is that the current implementation only searches for decorators in the Regarding the isolation of the decorators in the modules, I would not recommend doing that. This would mean that if we wanted to create a new plugin for dspace that adds a To prevent services from disabled modules to be available at runtime, we could update the script in the future though to only scan for decorators inside enabled modules. Regarding performance, the script takes less than half a second to generate all the registries so I don't think this is a problem. If people would however want to disable this auto rebuild it would be easy though, you would only have to remove the plugin from webpack and run |
|
@alexandrevryghem : When you have a chance, I'd appreciate it if you can rebase this on latest I realize there was some discussion above around overlap with Nx (with @FrancescoMolinaro above). But, since the Nx work isn't likely to occur for 10.x, I'd like us all to consider whether this PR is still a useful step in the right direction for 10.0. |
5aa0d62 to
8de9848
Compare
8de9848 to
0f4fce3
Compare
|
Hi @alexandrevryghem, |
|
Hi @alexandrevryghem , sorry for the delay on this and thanks for your works, I tried this again today and the functionality seems working as expected, the only thing is that gitHub is now signaling 260 files changed and seems that includes a lot of files/changes already on main. |
|
@FrancescoMolinaro thnx for the review! I took a quick look at the current diff on GitHub and all the changes that I can see on my end do look like intentional modifications that are not present on NOTE: we started the development of this right after dspace 9.0 got released so you can look at the original branch this PR started from here, and it has 255 file changes. So having 260 files changes after the merge with |
|
Hi @alexandrevryghem , sorry I think it was an issue only on my side, I was seeing code changes to the yml files for docker and the pipelines, cleaning the browser cache did solve the issue and now I can see the correct files, I thought the number of files changed was high because of that but looking at the correct code changes it is a reasonable number as this PR thouches all the components that previously had a decorator. I am going to do a code review asap, thanks and sorry again for the false alarm. |
FrancescoMolinaro
left a comment
There was a problem hiding this comment.
Hi @alexandrevryghem , thanks again for your work on this, I did check again the code and generally it looks ok, I have found just a couple of things that I would like to address, you can find an inline comment for each of those.
Otherwise is looking good for me, thanks again for the effort.
| import { MenuItemType } from '../menu-item-type.model'; | ||
| import { MenuSection } from '../menu-section.model'; | ||
|
|
||
| export interface MenuSectionDTO { |
There was a problem hiding this comment.
Hi @alexandrevryghem , this interface seems to be defined and exported with the same name but different structure in menu.component.ts, if both are needed could we change the name of one of the two so that the difference is clear?
| */ | ||
| ngOnInit(): void { | ||
| this.instantiateComponent(); | ||
| void this.instantiateComponent(); |
There was a problem hiding this comment.
@alexandrevryghem I have seen that this method is now not a void method anymore, could we remove the void operator and add a catch for any possible error from the returned promise? I think otherwise errors in the component instantiation could be swallowed by the void operator resulting just in an empty component.
| @@ -0,0 +1,413 @@ | |||
| import { | |||
There was a problem hiding this comment.
@alexandrevryghem since this file is the core logic of the decorator plugin and it's logic is quite complex, would be possible to add some unit tests so that it would be easier to find issues on future code changes? I think some tests to enforce the functions logic should be enough.
References
main.jsbundle caused by standalone component migration #2899Description
When DSpace was migrated to standalone components the decorators on all the dynamic components were removed. The way dynamic components used to work was by mapping the different types of supported components with their component declaration. These mappings were automatically populated by the decorators themselves once the class was loaded, so that's why we always loaded those components eagerly. During the switch to standalone components the logic to populate the maps automatically was replaced with hardcoded maps. This PR now generates these hardcoded decorator maps automatically during every rebuild using the new
npm run generate:decorator:registriesscript, and we also lazy loaded all the component imports to reduce the main bundle size.Instructions for Reviewers
List of changes in this PR:
scripts/generate-decorator-registries.tshas been created that goes over the whole code and finds all the decorators defined inside theDECORATORSarray. These decorators are then all bundled together in a registry file that will be used to retrieve the matching component.npm run generate:decorator:registrieson every rebuildlistable-object.decorator.ts#getMatchnot always being able to fall back to a default componentlistable-object.decorator.ts#getMatchlogic in all the decorators to find the best matchGuidance for how to test this PR:
generate-decorator-registries.ts#DECORATORSand verify that they are still all rendering correctly in prod & dev modeChecklist
mainbranch of code (unless it is a backport or is fixing an issue specific to an older branch).npm run lintnpm run check-circ-deps)package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.