Skip to content

Use getTopicPageUrl for Topic Discovery More About link (same method topic tags uses) - #14334

Merged
LilyL0u merged 5 commits into
latestfrom
construct-more-about-href-with-topidId
Aug 21, 2026
Merged

Use getTopicPageUrl for Topic Discovery More About link (same method topic tags uses)#14334
LilyL0u merged 5 commits into
latestfrom
construct-more-about-href-with-topidId

Conversation

@LilyL0u

@LilyL0u LilyL0u commented Aug 20, 2026

Copy link
Copy Markdown
Contributor

Fix for bug spotted https://bbc-tpg.slack.com/archives/C03RMKNL7GC/p1787236298096979

It looks like we were getting the href with topicUrl from pageData.metadata.topics which was data from the BFF fetch. It seems that sometimes this topicUrl field is missing and sometimes it is populated. This could be a BFF bug.

However, I saw that the original topic tags component dealt with getting the URL in a different way that doesn't rely on this field from the BFF. So I have changed the way the code works so that the new Topic Discovery component uses the same function to construct the 'More about' href as the old Topic Tags component does.

We could look into why there are missing URLs in the BFF, but this is a quicker fix for now and also fits with already-existing methods of doing things.

This pull request introduces a new utility function, getTopicPageUrl, to centralize and standardize the construction of topic page URLs across the application. The function is now used in both the TopicDiscovery and TopicTags components, replacing previously duplicated or inconsistent URL-building logic. Comprehensive tests have also been added to ensure correct URL generation for various scenarios.

Refactoring and Code Reuse:

  • Added a new utility function getTopicPageUrl in src/app/lib/utilities/getTopicPageUrl/index.ts to generate both relative and absolute topic URLs, supporting custom topicsPath, variants, and public/private service domains.
  • Updated TopicDiscovery and TopicTags components to use the new getTopicPageUrl utility, replacing their local URL-building logic with calls to this shared function for consistency and maintainability. [1] [2] [3] [4]

Component Logic Updates:

  • Refactored TopicDiscovery to use buildTopicPageUrl for constructing topic URLs, ensuring consistent link generation in both UI and analytics tracking. [1] [2] [3]
  • Refactored TopicTags to use buildTopicPageUrl for all topic tag links, removing the previous inline URL logic and ensuring absolute URLs where needed. [1] [2]

Absolute or relative link paths

I retained the ability for Topic Tags to use an absolute link as this component is used on AMP pages and if we used a relative link on an AMP cache it could resolve to a different domain. This is how it was in the code already.

Topic Discovery does not show on AMP pages so we do not need an absolute link and a relative link is supposed to make testing on other environments easier due to being able to stay on the same environment when clicking (however if the renderer_env query disappears then this doesn't work anyway...)

Testing:

  • Added a new test suite for getTopicPageUrl covering relative and absolute URLs, public/private domains, custom topic paths, and variant handling.…ared utility

Looking at the page this bug was found on http://localhost:7081/romania/articles/cp8xgjgrykjo?renderer_env=live
you will see that the More About links all have hrefs and lead to topic pages now. If you look on live, the 3rd and 4th Topic Tab More About links do not have an href and do not work.

Resolves JIRA:

Summary

A very high-level summary of easily-reproducible changes that can be understood by non-devs, and why these changes where made.

Code changes

  • List key code changes that have been made.

Testing

  1. List the steps required to test this PR.

Useful Links

Copilot AI lite review requested due to automatic review settings August 20, 2026 16:39

Copilot AI left a comment

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.

Pull request overview

This PR addresses a production issue where Topic Discovery “More about” links sometimes render without an href due to missing topicUrl data from the BFF, by standardising URL construction via a shared utility.

Changes:

  • Added a shared getTopicPageUrl utility to build topic page URLs (relative by default; absolute when required).
  • Updated TopicDiscovery and TopicTags to use the shared utility for consistent topic link generation (with TopicDiscovery falling back when topicUrl is missing).
  • Added unit tests for getTopicPageUrl covering relative/absolute, variants, and custom topicsPath.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
src/app/lib/utilities/getTopicPageUrl/index.ts Introduces a centralized topic URL builder (relative/absolute, variant, topicsPath).
src/app/lib/utilities/getTopicPageUrl/index.test.ts Adds unit coverage for URL construction scenarios.
src/app/components/TopicTags/index.tsx Replaces inline URL building with getTopicPageUrl (absolute links retained for AMP/cache safety).
src/app/components/TopicDiscovery/index.tsx Uses getTopicPageUrl as a fallback when BFF topicUrl is missing; reuses the constructed URL for link + analytics.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/app/components/TopicDiscovery/index.tsx
@LilyL0u
LilyL0u merged commit a32ffb1 into latest Aug 21, 2026
17 checks passed
@LilyL0u
LilyL0u deleted the construct-more-about-href-with-topidId branch August 21, 2026 12:57
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.

4 participants