DEV Community

Cover image for Your GitHub review is still pending
Nikita
Nikita

Posted on Edited on Originally published at nikita-dmitrienko.dev

Your GitHub review is still pending

A teammate kept leaving reviews half done. He'd open a pull request, add a few comments and move on without clicking "Submit review". The comments sat there marked "Pending". Only he could see them. The author waited for feedback that was already written.

It's an easy mistake. GitHub saves each comment the moment you add it, so it feels like you're done. People have been asking GitHub to make this clearer since 2022.

So I built Unsubmitted Review Alert. It notices the pending review and won't let you walk away from it quietly.

Demo: a pull request with two pending comments shows a reminder bar at the bottom; Finish review opens GitHub's review box

Reading the page

The extension asks for nothing beyond github.com: no token, no network requests, no storage. So the page is the only source of truth.

The best signal on it is the counter on GitHub's "Submit review" button, because GitHub's own React state renders it:

// content.js
const REVIEW_BUTTON = 'button[class*="ReviewMenuButton"]';
const REVIEW_BUTTON_COUNTER = '[data-component="ButtonCounter"]';

const count = toInt(reviewButton.querySelector(REVIEW_BUTTON_COUNTER));
Enter fullscreen mode Exit fullscreen mode

Snippets in this post are trimmed for reading. The full source is on GitHub.

One rule from day one: never match the word "Pending" in the page. GitHub uses it elsewhere, and a reminder that fires for nothing gets uninstalled.

Four ways to leave

GitHub mostly doesn't load new pages. Clicking a tab swaps the content in place, so the browser's "Leave site?" dialog never fires. One "are you sure?" turned into four guards:

  1. Link clicks. A capture listener on window, before GitHub's router.
  2. Turbo visits. turbo:before-visit, which Turbo lets you cancel.
  3. Back and Forward. The Navigation API's navigate event.
  4. Close, reload, new URL. beforeunload, Chrome's own dialog.

Clicks are the easy one. React listens at the root of the app and Turbo on the document, so a capture listener on window runs before both:

// content.js
function onClickCapture(event) {
  // ...is it a plain click on a link that leaves this pull request?
  if (!confirmLeaving()) {
    event.preventDefault();
    event.stopImmediatePropagation();
  }
}

window.addEventListener('click', onClickCapture, true);
Enter fullscreen mode Exit fullscreen mode

GitHub's keyboard shortcuts, like g i for Issues, click a link under the hood, so they land here too.

The Back button

This one was a real gap. If you got to the pull request from the PR list, Back stays inside GitHub's app. No page unload, no beforeunload, no prompt. popstate fires after the fact, so it's too late.

The Navigation API fires navigate before the history change reaches the page:

// content.js
navigation.addEventListener('navigate', (event) => {
  if (event.navigationType === 'traverse' && event.destination.sameDocument &&
      event.cancelable && leavesPendingPr(event.destination.url) && !confirmLeaving()) {
    event.preventDefault();
  }
});
Enter fullscreen mode Exit fullscreen mode

Cancel it there and popstate never fires. GitHub's router never hears about the Back press, so the URL and the page stay in sync.

No trapping. Cancelling a Back step uses up the page's user activation (HTML spec). Press Back twice and you're out, which is why the code checks event.cancelable instead of assuming.

The bug that wasn't mine

Then I tested on a real review. Discard it from the Overview tab, and the bar stays until you reload.

The API said the review was gone. But GitHub's own button still said "2", and the comments still said "Pending". The extension wasn't wrong about the page. The page was wrong.

So I read the code GitHub ships for the review box. In my own words, Discard does this:

if not confirm("Are you sure you want to cancel? You will lose all your pending comments.")
  stop                         # the box stays open
mark the Discard button as loading
send DELETE for the pending review
on error:   show the error, keep the box open
on success: Files changed reloads the page
            Overview closes the box. Nothing else.
Enter fullscreen mode Exit fullscreen mode

Submitting clears GitHub's local pending state. Discarding doesn't, and on Overview nothing reloads to hide it.

That gave me two signals I could trust. The Discard button goes into data-loading="true" only after you confirm. The box closes only on success.

// content.js
// Runs before GitHub's own click handler, which asks confirm() synchronously.
function watchDiscard(button) {
  setTimeout(() => {
    if (button.getAttribute('data-loading') !== 'true') return;
    discardState = { prKey, staleCount, done: false };
  }, 0);
}
Enter fullscreen mode Exit fullscreen mode

The setTimeout(..., 0) is the trick. My listener runs before GitHub's, so nobody has answered the confirm yet. By the next task the button is either loading or it isn't. Once the box closes, the stale count is ignored until the page shows a different one.

Matching GitHub's theme

The bar lives in a shadow root, so GitHub's CSS can't break it. But custom properties inherit through the shadow boundary, and all: initial doesn't reset them. So the bar reads GitHub's own color variables:

/* content.js (the bar's stylesheet) */
:host { all: initial; }
.bar {
  background: var(--bgColor-default, #ffffff);
  color: var(--fgColor-default, #1f2328);
}
Enter fullscreen mode Exit fullscreen mode

GitHub's Files changed tab with two pending comments and the reminder bar at the bottom, in GitHub's light theme

Testing without spamming GitHub

The content script only runs on github.com, so the fake pages have to live there. Playwright can route a real URL to a fixture:

// test/e2e.cjs
await context.route('https://github.com/**', (route) =>
  route.fulfill({ contentType: 'text/html', body: FIXTURES[new URL(route.request().url()).pathname] }));
Enter fullscreen mode Exit fullscreen mode

The real extension loads into Chrome for Testing, sees the real origin, and touches no real pull request. A second suite runs against public pull requests with GitHub's real routers.

Try it

With Chrome's Enhanced protection on, the install dialog may say the extension "is not trusted by Enhanced Safe Browsing". Chrome says that about new publishers for the first few months (Google's explanation).

If it misses a case or nags when it shouldn't, open an issue.

Top comments (0)