From 4bf3605fd2b7223c7859e39e77e0507dc600b32e Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 14 Jan 2026 04:05:23 +0000 Subject: [PATCH] Fix: Ensure history pane refreshes on subsequent visits This change ensures that the profile history pane refreshes its content when the user navigates back to it, addressing a bug where stale data could be displayed. It implements an optimized strategy: - On the first load, `ensureInitialLoad` is called, which handles the initial fetch internally. - On subsequent visits (when the renderer is already initialized), `refresh({ force: true })` is called explicitly to update the list. The unit test `history pane lazily initializes the watch history renderer` was updated to reflect this behavior, verifying that `ensureInitialLoad` is called once and `refresh` is called on subsequent opens. --- js/ui/profileModalController.js | 7 +++- tests/profile-modal-controller.test.mjs | 50 ++++++++++++++++++++----- 2 files changed, 46 insertions(+), 11 deletions(-) diff --git a/js/ui/profileModalController.js b/js/ui/profileModalController.js index 1bef60f3..f6a022e3 100644 --- a/js/ui/profileModalController.js +++ b/js/ui/profileModalController.js @@ -5850,7 +5850,12 @@ export class ProfileModalController { } try { - await renderer.ensureInitialLoad({ actor: primaryActor }); + const state = typeof renderer.getState === "function" ? renderer.getState() : {}; + if (state.initialized) { + await renderer.refresh({ actor: primaryActor, force: true }); + } else { + await renderer.ensureInitialLoad({ actor: primaryActor }); + } if (!this.boundProfileHistoryVisibility) { this.boundProfileHistoryVisibility = () => { diff --git a/tests/profile-modal-controller.test.mjs b/tests/profile-modal-controller.test.mjs index aea54f44..f14c3730 100644 --- a/tests/profile-modal-controller.test.mjs +++ b/tests/profile-modal-controller.test.mjs @@ -1212,10 +1212,13 @@ test('admin mutations invoke accessControl stubs and update admin DOM', async () test('history pane lazily initializes the watch history renderer', async () => { const historyCalls = []; let capturedConfig = null; + let isInitialized = false; const fakeRenderer = { + getState: () => ({ initialized: isInitialized }), ensureInitialLoad: async ({ actor }) => { historyCalls.push(['ensure', actor]); + isInitialized = true; }, refresh: async ({ actor, force }) => { historyCalls.push(['refresh', actor, force]); @@ -1228,6 +1231,7 @@ test('history pane lazily initializes the watch history renderer', async () => { }, destroy: () => { historyCalls.push(['destroy']); + isInitialized = false; }, }; @@ -1248,26 +1252,52 @@ test('history pane lazily initializes the watch history renderer', async () => { controller.populateBlockedList = () => {}; controller.refreshWalletPaneState = () => {}; + // First show: Should call ensureInitialLoad but NOT refresh (optimized) controller.setActivePubkey(defaultActorHex); await controller.show('history'); await Promise.resolve(); assert.ok(capturedConfig); assert.equal(capturedConfig.viewSelector, '#profilePaneHistory'); - assert.deepEqual(historyCalls.slice(0, 3), [ + + // Expect ensure + resume, NO refresh on first load + assert.deepEqual(historyCalls.slice(0, 2), [ ['ensure', defaultActorHex], - ['refresh', defaultActorHex, true], ['resume'], ]); assert.ok(typeof controller.boundProfileHistoryVisibility === 'function'); - await controller.hide(); - await Promise.resolve(); + // Reset calls for second pass + while (historyCalls.length) historyCalls.pop(); - assert.equal( - historyCalls.some((entry) => Array.isArray(entry) && entry[0] === 'destroy'), - true, - ); - assert.equal(controller.profileHistoryRenderer, null); - assert.equal(controller.boundProfileHistoryVisibility, null); + // Switch to another pane (should pause but NOT destroy) + controller.selectPane('account'); + await Promise.resolve(); + + assert.equal(historyCalls.length > 0, true, 'Should have recorded calls after switching pane'); + assert.equal(historyCalls[historyCalls.length - 1][0], 'pause'); + + // Clear calls + while (historyCalls.length) historyCalls.pop(); + + // Switch back to history. Renderer is still alive and initialized. + // Should call refresh + resume. + controller.selectPane('history'); + await Promise.resolve(); + + assert.deepEqual(historyCalls, [ + ['refresh', defaultActorHex, true], + ['resume'], + ]); + + // Finally hide and destroy + await controller.hide(); + await Promise.resolve(); + + assert.equal( + historyCalls.some((entry) => Array.isArray(entry) && entry[0] === 'destroy'), + true + ); + assert.equal(controller.profileHistoryRenderer, null); + assert.equal(controller.boundProfileHistoryVisibility, null); });