Skip to content

Commit 34d8523

Browse files
committed
fix(navbar): handle products without a purchaseUrl
ProductLearnMoreLink crashed SSG for any product lacking a purchaseUrl: the product matched in config but baseHref was undefined, so addUtmParams called undefined.includes() and failed the build. Query Filters (a library with no product page) was the first such product. Now: render no commercial CTA for products without a purchase page, and guard addUtmParams against a falsy URL (defense in depth).
1 parent f07a885 commit 34d8523

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/theme/NavbarItem/ProductLearnMoreLink.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ const defaultLink = {
2020

2121
// Add UTM parameters to URL
2222
function addUtmParams(url, productId) {
23+
if (!url) {
24+
return url;
25+
}
2326
const utmParams = new URLSearchParams({
2427
utm_source: 'developer-docs',
2528
utm_medium: 'navbar',
@@ -40,6 +43,14 @@ export default function ProductLearnMoreLink() {
4043
// Get product config or use default
4144
const product = productId && productConfig[productId];
4245

46+
// A product may exist in config without a purchaseUrl (e.g. a developer
47+
// library with no product page). It has no commercial "learn more"
48+
// destination, so render nothing rather than crash on an undefined URL.
49+
const isProductWithoutPurchaseUrl = product && !product.purchaseUrl;
50+
if (isProductWithoutPurchaseUrl) {
51+
return null;
52+
}
53+
4354
const linkText = product ? `Learn more about ${product.label}` : defaultLink.label;
4455
const baseHref = product ? product.purchaseUrl : defaultLink.href;
4556
const linkHref = addUtmParams(baseHref, productId);

0 commit comments

Comments
 (0)