From 3ae7d4968b3b26a3e94df8a04e96fa6f3df38517 Mon Sep 17 00:00:00 2001 From: Syed Ali Abbas Zaidi Date: Fri, 13 Oct 2023 16:02:34 +0500 Subject: [PATCH] fix: href property issue in gatsby build --- src/utils.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/utils.js b/src/utils.js index debd1b1a7..bd3a311b3 100644 --- a/src/utils.js +++ b/src/utils.js @@ -138,9 +138,13 @@ export function convertKeyNames(object, nameMap) { * @returns {Object} */ export function parseURL(url) { - const parser = document?.createElement('a'); - parser.href = url; - return parser; + if (typeof document !== 'undefined') { + const parser = document?.createElement('a'); + parser.href = url; + return parser; + } + + return {}; } /** @@ -151,7 +155,8 @@ export function parseURL(url) { * @returns {string} */ export function getPath(url) { - return parseURL(url).pathname; + const urlData = parseURL(url); + return Object.keys(urlData).length === 0 ? '' : urlData?.pathname; } /**