From b3f37058a2e954deeae74b11ad077a44128f7f82 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 3 Feb 2026 14:44:32 +0000 Subject: [PATCH] Defer profile modal data loading to improve responsiveness Co-authored-by: PR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> --- js/ui/profileModalController.js | 88 +++++++++++++------------ tests/profile-modal-controller.test.mjs | 3 + 2 files changed, 48 insertions(+), 43 deletions(-) diff --git a/js/ui/profileModalController.js b/js/ui/profileModalController.js index f0a77b31..6939d687 100644 --- a/js/ui/profileModalController.js +++ b/js/ui/profileModalController.js @@ -7403,52 +7403,54 @@ export class ProfileModalController { const shouldStayInMenu = keepMenuView && isMobile; this.setMobileView(shouldStayInMenu ? "menu" : "pane"); - const activeHex = this.normalizeHexPubkey(this.getActivePubkey()); + setTimeout(() => { + const activeHex = this.normalizeHexPubkey(this.getActivePubkey()); - if (target === "history") { - void this.populateProfileWatchHistory(); - } else if (target === "relays") { - this.populateProfileRelays(); - void this.refreshRelayHealthPanel({ - forceRefresh: true, - reason: "pane-select", - }); - } else if (target === "messages") { - this.resumeProfileMessages(); - void this.populateProfileMessages({ reason: "pane-select" }); - void this.refreshDmRelayPreferences(); - } else if (target === "wallet") { - this.refreshWalletPaneState(); - } else if (target === "storage") { - this.populateStoragePane(); - } else if (target === "hashtags") { - this.populateHashtagPreferences(); - if (activeHex && this.hashtagPreferencesService) { - this.hashtagPreferencesService - .load(activeHex, { allowPermissionPrompt: true }) - .catch(noop); + if (target === "history") { + void this.populateProfileWatchHistory(); + } else if (target === "relays") { + this.populateProfileRelays(); + void this.refreshRelayHealthPanel({ + forceRefresh: true, + reason: "pane-select", + }); + } else if (target === "messages") { + this.resumeProfileMessages(); + void this.populateProfileMessages({ reason: "pane-select" }); + void this.refreshDmRelayPreferences(); + } else if (target === "wallet") { + this.refreshWalletPaneState(); + } else if (target === "storage") { + this.populateStoragePane(); + } else if (target === "hashtags") { + this.populateHashtagPreferences(); + if (activeHex && this.hashtagPreferencesService) { + this.hashtagPreferencesService + .load(activeHex, { allowPermissionPrompt: true }) + .catch(noop); + } + this.refreshHashtagBackgroundStatus(); + } else if (target === "subscriptions") { + if (activeHex && this.subscriptionsService) { + this.subscriptionsService + .loadSubscriptions(activeHex, { allowPermissionPrompt: true }) + .catch(noop); + } + void this.populateSubscriptionsList(); + this.refreshSubscriptionsBackgroundStatus(); + } else if (target === "blocked") { + if (activeHex && this.services.userBlocks) { + this.services.userBlocks.loadBlocks(activeHex).catch(noop); + } + this.populateBlockedList(); + } else if (target === "safety") { + this.refreshModerationSettingsUi(); + this.syncLinkPreviewSettingsUi(); } - this.refreshHashtagBackgroundStatus(); - } else if (target === "subscriptions") { - if (activeHex && this.subscriptionsService) { - this.subscriptionsService - .loadSubscriptions(activeHex, { allowPermissionPrompt: true }) - .catch(noop); - } - void this.populateSubscriptionsList(); - this.refreshSubscriptionsBackgroundStatus(); - } else if (target === "blocked") { - if (activeHex && this.services.userBlocks) { - this.services.userBlocks.loadBlocks(activeHex).catch(noop); - } - this.populateBlockedList(); - } else if (target === "safety") { - this.refreshModerationSettingsUi(); - this.syncLinkPreviewSettingsUi(); - } - this.callbacks.onSelectPane(target, { controller: this }); - this.callbacks.onPaneShown(target, { controller: this }); + this.callbacks.onSelectPane(target, { controller: this }); + this.callbacks.onPaneShown(target, { controller: this }); + }, 0); } populateProfileRelays(relayEntries = null) { diff --git a/tests/profile-modal-controller.test.mjs b/tests/profile-modal-controller.test.mjs index 06f79d4e..3bcc27d8 100644 --- a/tests/profile-modal-controller.test.mjs +++ b/tests/profile-modal-controller.test.mjs @@ -1026,6 +1026,7 @@ test('show()/hide() toggle panes, trap focus, and refresh the wallet pane', asyn focusBefore.focus(); await controller.show('wallet'); + await new Promise((resolve) => setTimeout(resolve, 0)); assert.equal(adminRefreshes, 1); assert.equal(walletRefreshes, 2); @@ -1258,6 +1259,7 @@ test('history pane lazily initializes the watch history renderer', async () => { // First show: Should call ensureInitialLoad but NOT refresh (optimized) controller.setActivePubkey(defaultActorHex); await controller.show('history'); + await new Promise((resolve) => setTimeout(resolve, 0)); await Promise.resolve(); assert.ok(capturedConfig); @@ -1286,6 +1288,7 @@ test('history pane lazily initializes the watch history renderer', async () => { // Switch back to history. Renderer is still alive and initialized. // Should call refresh + resume. controller.selectPane('history'); + await new Promise((resolve) => setTimeout(resolve, 0)); await Promise.resolve(); assert.deepEqual(historyCalls, [