Skip to content

Restore dynamic component decorators#4528

Open
alexandrevryghem wants to merge 9 commits intoDSpace:mainfrom
atmire:restore-decorator-support_contribute-main
Open

Restore dynamic component decorators#4528
alexandrevryghem wants to merge 9 commits intoDSpace:mainfrom
atmire:restore-decorator-support_contribute-main

Conversation

@alexandrevryghem
Copy link
Copy Markdown
Member

@alexandrevryghem alexandrevryghem commented Jul 3, 2025

References

Description

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:registries script, and we also lazy loaded all the component imports to reduce the main bundle size.

Instructions for Reviewers

List of changes in this PR:

  • A new script scripts/generate-decorator-registries.ts has been created that goes over the whole code and finds all the decorators defined inside the DECORATORS array. These decorators are then all bundled together in a registry file that will be used to retrieve the matching component.
  • A new custom webpack plugin has been created to run npm run generate:decorator:registries on every rebuild
  • All the existing decorators that were not themable yet, have been made themable
  • Update the listable-object.decorator.ts#getMatch not always being able to fall back to a default component
  • Used the listable-object.decorator.ts#getMatch logic in all the decorators to find the best match

Guidance for how to test this PR:

  • Go over all the decorators listed in generate-decorator-registries.ts#DECORATORS and verify that they are still all rendering correctly in prod & dev mode
  • Verify the bundle size is now smaller (757.6KB → 631.27KB)

Checklist

  • My PR is created against the main branch of code (unless it is a backport or is fixing an issue specific to an older branch).
  • My PR is small in size (e.g. less than 1,000 lines of code, not including comments & specs/tests), or I have provided reasons as to why that's not possible.
  • My PR passes ESLint validation using npm run lint
  • My PR doesn't introduce circular dependencies (verified via npm run check-circ-deps)
  • My PR includes TypeDoc comments for all new (or modified) public methods and classes. It also includes TypeDoc for large or complex private methods.
  • My PR passes all specs/tests and includes new/updated specs or tests based on the Code Testing Guide.
  • My PR aligns with Accessibility guidelines if it makes changes to the user interface.
  • My PR uses i18n (internationalization) keys instead of hardcoded English text, to allow for translations.
  • My PR includes details on how to test it. I've provided clear instructions to reviewers on how to successfully test this fix or feature.
  • If my PR includes new libraries/dependencies (in package.json), I've made sure their licenses align with the DSpace BSD License based on the Licensing of Contributions documentation.
  • If my PR includes new features or configurations, I've provided basic technical documentation in the PR itself.
  • If my PR fixes an issue ticket, I've linked them together.

@alexandrevryghem alexandrevryghem self-assigned this Jul 3, 2025
@alexandrevryghem alexandrevryghem added bug performance / caching Related to performance, caching or embedded objects labels Jul 3, 2025
Comment thread scripts/generate-decorator-registries.ts Fixed
Comment thread scripts/generate-decorator-registries.ts Fixed
artlowel and others added 2 commits July 3, 2025 16:14
…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>
@alexandrevryghem alexandrevryghem force-pushed the restore-decorator-support_contribute-main branch from 5c64f85 to 7952510 Compare July 3, 2025 14:17
@tdonohue tdonohue requested a review from atarix83 July 3, 2025 14:22
@tdonohue tdonohue moved this to 🙋 Needs Reviewers Assigned in DSpace 10.0 Release Jul 3, 2025
@tdonohue tdonohue moved this from 🙋 Needs Reviewers Assigned to 👀 Under Review in DSpace 10.0 Release Jul 3, 2025
@tdonohue tdonohue added this to the 10.0 milestone Jul 3, 2025
@tdonohue tdonohue self-requested a review July 3, 2025 14:22
Copy link
Copy Markdown
Contributor

@FrancescoMolinaro FrancescoMolinaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions
Copy link
Copy Markdown

Hi @alexandrevryghem,
Conflicts have been detected against the base branch.
Please resolve these conflicts as soon as you can. Thanks!

@alexandrevryghem
Copy link
Copy Markdown
Member Author

alexandrevryghem commented Sep 5, 2025

@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 src folder, but now we would need to include the modules folder as well.

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 @dataservice for example, that we would always have to create the service in the core module. Whereas the idea is that such a plugin should have its own core module that depends the dspace core module.

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 npm run generate:decorator:registries manually. But running the script manually takes more time and would complicate the build process for developers so I would leave it enabled by default.

@alexandrevryghem alexandrevryghem mentioned this pull request Feb 4, 2026
12 tasks
@tdonohue
Copy link
Copy Markdown
Member

tdonohue commented Feb 5, 2026

@alexandrevryghem : When you have a chance, I'd appreciate it if you can rebase this on latest main. Now that #4446 is merged, it seems like this can provide more improvements to themes in 10.x.

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.

@alexandrevryghem alexandrevryghem force-pushed the restore-decorator-support_contribute-main branch from 5aa0d62 to 8de9848 Compare February 28, 2026 17:35
@alexandrevryghem alexandrevryghem force-pushed the restore-decorator-support_contribute-main branch from 8de9848 to 0f4fce3 Compare March 1, 2026 12:14
@github-actions
Copy link
Copy Markdown

Hi @alexandrevryghem,
Conflicts have been detected against the base branch.
Please resolve these conflicts as soon as you can. Thanks!

@FrancescoMolinaro
Copy link
Copy Markdown
Contributor

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.
I am not sure if there was an issue in merging the main branch or is just gitHub being "stuck", as the files I have checked look identical.
Could you please have a look so that is clear which files changed in this PR? Maybe just triggering a new comparison from gitHub will be enough to fix it.

@alexandrevryghem
Copy link
Copy Markdown
Member Author

@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 main yet. Could you maybe give some examples of files that shouldn't be included in the diff but are present in yours?

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 main does seem like a reasonable amount of changes

@FrancescoMolinaro
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor

@FrancescoMolinaro FrancescoMolinaro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug performance / caching Related to performance, caching or embedded objects

Projects

Status: 👀 Under Review

Development

Successfully merging this pull request may close these issues.

Size regression in main.js bundle caused by standalone component migration

6 participants