diff options
author | 2023-02-05 12:29:43 +0100 | |
---|---|---|
committer | 2023-02-05 19:29:43 +0800 | |
commit | 3e598b3baa3f4fcfd29e7da1aea7aa027831884d (patch) | |
tree | 83cf56308e19d1570034fb1ac8872ed896063744 | |
parent | f9a5b3edb971e451487f282af1e8eaa58c3ed348 (diff) | |
download | refined-github-3e598b3baa3f4fcfd29e7da1aea7aa027831884d.tar.gz refined-github-3e598b3baa3f4fcfd29e7da1aea7aa027831884d.tar.zst refined-github-3e598b3baa3f4fcfd29e7da1aea7aa027831884d.zip |
Improve `releases-tab` reliability (#6298)
-rw-r--r-- | source/features/releases-tab.tsx | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/source/features/releases-tab.tsx b/source/features/releases-tab.tsx index 5a5ab7c4..e304267b 100644 --- a/source/features/releases-tab.tsx +++ b/source/features/releases-tab.tsx @@ -38,7 +38,11 @@ async function fetchFromApi(): Promise<number> { return repository.releases.totalCount; } -export const getReleaseCount = cache.function(async () => pageDetect.isRepoRoot() ? parseCountFromDom() : fetchFromApi(), { +// Release count can be not found in DOM if: +// - It is disabled by repository owner on the home page (release DOM element won't be there) +// - It only contains pre-releases (count badge won't be shown) +// For this reason, if we can't find a count from the DOM, we ask the API instead (see #6298) +export const getReleaseCount = cache.function(async () => await parseCountFromDom() || fetchFromApi(), { maxAge: {hours: 1}, staleWhileRevalidate: {days: 3}, cacheKey: getCacheKey, @@ -80,8 +84,10 @@ async function addReleasesTab(): Promise<false | void> { // Trigger a reflow to push the right-most tab into the overflow dropdown (second attempt #4254) window.dispatchEvent(new Event('resize')); + const dropdownMenu = await elementReady('.js-responsive-underlinenav .dropdown-menu ul'); + appendBefore( - select('.js-responsive-underlinenav .dropdown-menu ul')!, + dropdownMenu!, '.dropdown-divider', // Won't exist if `more-dropdown` is disabled createDropdownItem('Releases', buildRepoURL('releases'), { 'data-menu-item': 'rgh-releases-item', |