Skip to content

Conversation

@alexandrevryghem
Copy link
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
artlowel and others added 3 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
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

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

@alexandrevryghem
Copy link
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.

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

Labels

bug merge conflict 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

5 participants