Skip to content

Comments

Lazy-load geospatial map code (9.x)#4447

Merged
kshepherd merged 3 commits intoDSpace:dspace-9_xfrom
ybnd:defer-geospatial-map-components_9.x
Jun 12, 2025
Merged

Lazy-load geospatial map code (9.x)#4447
kshepherd merged 3 commits intoDSpace:dspace-9_xfrom
ybnd:defer-geospatial-map-components_9.x

Conversation

@ybnd
Copy link
Member

@ybnd ybnd commented Jun 11, 2025

References

Add references/links to any related issues or PRs. These may include:

Description

This PR moves some code & libraries required for geospatial maps out of the main bundle:

  • Leaflet, providers & marker clusters
  • Terraformer
  • The two components that use these libraries

Maps are only show on a small number of pages. Making these components lazy saves us about 60 kB (gzipped).

This PR can also serve as a demo of the new @defer block introduced in Angular 17 -- we can likely leverage it for further improvements.

Instructions for Reviewers

Most importantly: maps should work as they did before.
I tested this on the /browse/map page, with geospatialMapViewer.enableBrowseMap: true in the Angular configuration.

Check Webpack bundle sizes before and after this PR:

  • npm run build:stats
  • webpack-bundle-analyzer dist/browser/stats.json

Code related to geospatial maps should now be outside of main.js; you can highlight it with the following regex: (geospatial-map|leaflet|@terraformer)
Before:

After:
+

Checklist

This checklist provides a reminder of what we are going to look for when reviewing your PR. You do not need to complete this checklist prior creating your PR (draft PRs are always welcome).
However, reviewers may request that you complete any actions in this list if you have not done so. If you are unsure about an item in the checklist, don't hesitate to ask. We're here to help!

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

@ybnd ybnd self-assigned this Jun 11, 2025
@ybnd ybnd added the performance / caching Related to performance, caching or embedded objects label Jun 11, 2025
@ybnd ybnd mentioned this pull request Jun 11, 2025
12 tasks
@ybnd ybnd changed the title Lazy-load geospatial map code Lazy-load geospatial map code (9.x) Jun 11, 2025
According to the Angular docs it should be possible to "trigger" the different states of the @defer block
https://angular.dev/guide/templates/defer#testing-defer-blocks
...but I wasn't able to get this example to work either.

This was the only case where we directly test an inner component's reflected inputs, so IMO it makes sense to "let it go".
@ybnd ybnd force-pushed the defer-geospatial-map-components_9.x branch from 363d2bf to c147354 Compare June 11, 2025 14:27
@ybnd ybnd requested a review from kshepherd June 11, 2025 14:30
@tdonohue tdonohue added the port to main This PR needs to be ported to `main` branch for the next major release label Jun 11, 2025
@tdonohue tdonohue moved this to 🙋 Needs Reviewers Assigned in DSpace Maintenance (9.x, 8.x, 7.6.x) Jun 11, 2025
@tdonohue tdonohue removed the port to main This PR needs to be ported to `main` branch for the next major release label Jun 11, 2025
Copy link
Member

@kshepherd kshepherd left a comment

Choose a reason for hiding this comment

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

+1 tested and reviewed, important fix to lower resource overhead. this is a port of main which i've also approved

@github-project-automation github-project-automation bot moved this from 🙋 Needs Reviewers Assigned to 👍 Reviewer Approved in DSpace Maintenance (9.x, 8.x, 7.6.x) Jun 12, 2025
@tdonohue tdonohue added this to the 9.1 milestone Jun 12, 2025
@tdonohue tdonohue added the 1 APPROVAL pull request only requires a single approval to merge label Jun 12, 2025
@kshepherd
Copy link
Member

merging immediately as the changes requested on the 9.x port are made here too

@kshepherd kshepherd merged commit d0464c4 into DSpace:dspace-9_x Jun 12, 2025
29 checks passed
@github-project-automation github-project-automation bot moved this from 👍 Reviewer Approved to ✅ Done in DSpace Maintenance (9.x, 8.x, 7.6.x) Jun 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

1 APPROVAL pull request only requires a single approval to merge performance / caching Related to performance, caching or embedded objects

Projects

Development

Successfully merging this pull request may close these issues.

3 participants