Skip to content

ref: cache getSitemapAsArray call to reduce redundant calls#1894

Merged
dcshzj merged 2 commits intomainfrom
ref/optimise-sitemap-array
Mar 23, 2026
Merged

ref: cache getSitemapAsArray call to reduce redundant calls#1894
dcshzj merged 2 commits intomainfrom
ref/optimise-sitemap-array

Conversation

@dcshzj
Copy link
Copy Markdown
Contributor

@dcshzj dcshzj commented Mar 18, 2026

Problem

We are calling getSitemapAsArray repeatedly, especially when generating a large collection page which uses getReferenceLinkHref on every item in the collection.

Solution

Breaking Changes

  • Yes - this PR contains breaking changes
  • No - this PR is backwards compatible

Improvements:

  • Cache the result of getSitemapAsArray inside a new derived property inside the site-wide props.
  • Refactor all usages of getReferenceLinkHref to use the new siteMapArray site-wide prop.

Before & After Screenshots

Screen.Recording.2026-03-18.at.14.12.54.mov

Tests

  • Go to Isomer Studio and publish any site with a collection.
  • Verify that the collection index page is the same as it was previously.
  • Randomly sample two of the components that changed in this PR.
  • For each of the component that changed, verify that the reference link is still resolving to the correct final permalink.

Copilot AI review requested due to automatic review settings March 18, 2026 06:23
@dcshzj dcshzj requested a review from a team as a code owner March 18, 2026 06:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors reference-link resolution to use a precomputed sitemap array (siteMapArray) instead of converting the sitemap tree on every call, and wires that derived data through IsomerSiteProps/rendering and UI components.

Changes:

  • Update getReferenceLinkHref to accept sitemapArray: IsomerSitemap[] and migrate call sites to pass site.siteMapArray.
  • Introduce siteMapArray as a derived site prop (IsomerDerivedSiteProps) and populate it in RenderEngine via getSitemapAsArray(site.siteMap).
  • Update affected tests/stories/helpers to provide siteMapArray.

Reviewed changes

Copilot reviewed 30 out of 30 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
packages/components/src/utils/getTextAsHtml.ts Passes site.siteMapArray into getReferenceLinkHref when rendering link marks.
packages/components/src/utils/getReferenceLinkHref.ts Changes API to accept a precomputed sitemap array (and removes internal conversion).
packages/components/src/utils/tests/getReferenceLinkHref.test.ts Updates tests to build and pass EXAMPLE_SITEMAP_ARRAY.
packages/components/src/types/site.ts Adds IsomerDerivedSiteProps with required siteMapArray and composes it into IsomerSiteProps.
packages/components/src/templates/next/layouts/Collection/utils/processCollectionItems.ts Passes site.siteMapArray into getReferenceLinkHref for collection item URLs.
packages/components/src/templates/next/components/internal/Vica/VicaWidget.tsx Updates Vica widget asset/reference URL conversion to use siteMapArray.
packages/components/src/templates/next/components/internal/Navbar/Navbar.tsx Updates navbar URL processing to use siteMapArray.
packages/components/src/templates/next/components/internal/Footer/Footer.tsx Updates footer/social/contact/legal link resolution to use siteMapArray.
packages/components/src/templates/next/components/internal/ContentPageHeader/ContentPageHeader.tsx Updates header button link resolution to use siteMapArray.
packages/components/src/templates/next/components/complex/* Updates multiple complex components’ button/link href resolution to use siteMapArray.
packages/components/src/templates/next/components/complex/CollectionBlock/utils/getCollectionParent.ts Switches collection parent lookup to site.siteMapArray.
packages/components/src/templates/next/components/complex/CollectionBlock/utils/tests/getCollectionParent.test.ts Adds siteMapArray to fixtures (but currently not kept in sync with siteMap).
packages/components/src/templates/next/components/complex/CollectionBlock/utils/tests/getCollectionPages.test.ts Adds siteMapArray to fixtures.
packages/components/src/stories/helpers/generateSiteConfig.ts Adds siteMapArray to default story site config.
packages/components/src/interfaces/internal/Vica.ts Updates Vica prop typing to require siteMapArray (instead of siteMap).
packages/components/src/engine/render.tsx Derives siteMapArray inside RenderEngine from siteMap before rendering layouts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

@datadog-opengovsg
Copy link
Copy Markdown

datadog-opengovsg bot commented Mar 18, 2026

✅ Tests

🎉 All green!

❄️ No new flaky tests detected
🧪 All tests passed

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 117e065 | Docs | Was this helpful? Give us feedback!

@dcshzj dcshzj merged commit 3494925 into main Mar 23, 2026
18 of 22 checks passed
@dcshzj dcshzj deleted the ref/optimise-sitemap-array branch March 23, 2026 05:30
dcshzj added a commit that referenced this pull request Mar 23, 2026
* ref: cache getSitemapAsArray call to reduce redundant calls

* fix: update based on Copilot comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants