Skip to content

Commit a82cf33

Browse files
committed
fix: bypass detail cache for updated notifications & await popup init
- Pass forceRefresh=true in createDetailFetchTask when updated_at changed, preventing stale PR/issue state from LRU cache - Await popup init() to surface unhandled rejections cleanly
1 parent e796826 commit a82cf33

3 files changed

Lines changed: 38 additions & 5 deletions

File tree

src/background/service-worker.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -251,10 +251,10 @@ async function fetchWithConcurrencyLimit(tasks, limit = 5) {
251251
* @param {Array} detailedNotifications - Array to update with details
252252
* @returns {Function} Async function to fetch details
253253
*/
254-
function createDetailFetchTask(notification, index, detailedNotifications) {
254+
function createDetailFetchTask(notification, index, detailedNotifications, forceRefresh = false) {
255255
return async () => {
256256
try {
257-
const details = await github.getNotificationDetails(notification);
257+
const details = await github.getNotificationDetails(notification, forceRefresh);
258258
updateNotificationDetails(detailedNotifications[index], details, notification.subject.type);
259259
return { success: true, id: notification.id, index };
260260
} catch (error) {
@@ -452,7 +452,7 @@ async function checkNotifications() {
452452
if (priorityNotifications.length > 0) {
453453
priorityResults = await fetchWithConcurrencyLimit(
454454
priorityNotifications.map(({ notification: n, index }) =>
455-
createDetailFetchTask(n, index, detailedNotifications),
455+
createDetailFetchTask(n, index, detailedNotifications, true),
456456
),
457457
CONCURRENCY.PRIORITY,
458458
);
@@ -482,7 +482,7 @@ async function checkNotifications() {
482482
if (backgroundNotifications.length > 0) {
483483
fetchWithConcurrencyLimit(
484484
backgroundNotifications.map(({ notification: n, index }) =>
485-
createDetailFetchTask(n, index, detailedNotifications),
485+
createDetailFetchTask(n, index, detailedNotifications, true),
486486
),
487487
CONCURRENCY.BACKGROUND,
488488
)

src/popup/popup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1080,5 +1080,5 @@ window.addEventListener("beforeunload", () => {
10801080
document.body.classList.add("transitions-enabled");
10811081
});
10821082
// Then initialize (showView will set the correct width)
1083-
init();
1083+
await init();
10841084
})();

tests/service-worker.test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -900,6 +900,39 @@ describe("service-worker", () => {
900900
expect(call[0].map((n) => n.id)).not.toContain("A");
901901
});
902902
});
903+
904+
it("should pass forceRefresh=true when fetching details for updated notifications", async () => {
905+
const oldNotif = makeRawNotif("X");
906+
oldNotif.subject.url = "https://api.github.com/repos/owner/repo/issues/1";
907+
const updatedNotif = {
908+
...oldNotif,
909+
updated_at: "2024-06-01T00:00:00Z", // newer than stored
910+
};
911+
912+
mockGithub.getNotifications.mockResolvedValue({
913+
items: [updatedNotif],
914+
hasMore: false,
915+
});
916+
917+
// Stored version has old updated_at → needsUpdate = true
918+
mockStorageFunctions.getNotifications
919+
.mockResolvedValueOnce([makeStoredNotif("X")]) // existingIds
920+
.mockResolvedValueOnce([makeStoredNotif("X")]) // safeBasic re-read
921+
.mockResolvedValueOnce([makeStoredNotif("X")]); // mergeAndSaveIfCurrent
922+
923+
mockGithub.getNotificationDetails.mockResolvedValue({
924+
state: "closed",
925+
user: { login: "alice", avatar_url: "https://example.com/a.png", html_url: "" },
926+
});
927+
928+
messageHandler({ action: "refresh" }, {}, vi.fn());
929+
await new Promise((resolve) => setTimeout(resolve, 150));
930+
931+
// getNotificationDetails must be called with forceRefresh=true
932+
expect(mockGithub.getNotificationDetails).toHaveBeenCalled();
933+
const [, forceRefresh] = mockGithub.getNotificationDetails.mock.calls[0];
934+
expect(forceRefresh).toBe(true);
935+
});
903936
});
904937
});
905938

0 commit comments

Comments
 (0)