sindresorhus/refined-github

Error when the merge commit is hidden in `first-published-tag-for-merged-pr` feature #3813

mcornella posted onGitHub

Test URL: https://github.com/sindresorhus/refined-github/pull/1986

Console error:

Uncaught (in promise) TypeError: Cannot read property 'textContent' of null
    at MutationObserver.first_published_tag_for_merged_pr_init (refined-github.js:7402)
    at observeElement (refined-github.js:4716)
    at init (refined-github.js:7416)
    at runFeature (refined-github.js:2114)
    at setupPageLoad (refined-github.js:2122)
    at refined-github.js:2155
first_published_tag_for_merged_pr_init @ refined-github.js:7402
observeElement                         @ refined-github.js:4716
init                                   @ refined-github.js:7416
runFeature                             @ refined-github.js:2114
setupPageLoad                          @ refined-github.js:2122
(anonymous)                            @ refined-github.js:2155
async function (async)
(anonymous)                            @ refined-github.js:2155
add                                    @ refined-github.js:2156
async function (async)
add                                    @ refined-github.js:2141
(anonymous)                            @ refined-github.js:7412
(anonymous)                            @ refined-github.js:8132
(anonymous)                            @ refined-github.js:8133

This happens when the merge commit is hidden by the N hidden items GitHub feature: image

There are two options:

  1. Change the assertion that there'll always be a merge commit in the DOM and return when it is null/undefined:

     diff --git a/source/features/first-published-tag-for-merged-pr.tsx b/source/features/first-published-tag-for-merged-pr.tsx
     index 15acdc4c..b66d66e9 100644
     --- a/source/features/first-published-tag-for-merged-pr.tsx
     +++ b/source/features/first-published-tag-for-merged-pr.tsx
     @@ -21,7 +21,12 @@ const getFirstTag = cache.function(async (commit: string): Promise<string | unde
      });
    
      async function init(): Promise<void> {
     -    const mergeCommit = select(`.TimelineItem.js-details-container.Details a[href^="/${getRepo()!.nameWithOwner}/commit/" i] > code.link-gray-dark`)!.textContent!;
     +    const mergeCommit = select(`.TimelineItem.js-details-container.Details a[href^="/${getRepo()!.nameWithOwner}/commit/" i] > code.link-gray-dark`)?.textContent;
     +
     +    if (!mergeCommit) {
     +        return;
     +    }
     +
          const tagName = await getFirstTag(mergeCommit);
    
          if (!tagName) {
  2. Get the merge commit via the API when it isn't found.


Not worth the api call IMHO. When a made the feature I knew about the issue. The issue usually only happens on very old PR's that have many other Issues/PR's referencing to it after it was merged.
The link you gave has the issue stated above.

posted by yakov116 over 4 years ago

However I still want it to fail loudly when it breaks. Otherwise if the feature breaks due to a DOM change on GitHub the feature wil not exist until someone notices that it's missing.

posted by yakov116 over 4 years ago

Makes sense. Thanks!

posted by mcornella over 4 years ago

Fund this Issue

$0.00
Funded

Pull requests