diff --git a/src/js/dataLayer/requests.js b/src/js/dataLayer/requests.js index 208c5df6..7c9833ac 100644 --- a/src/js/dataLayer/requests.js +++ b/src/js/dataLayer/requests.js @@ -1363,9 +1363,8 @@ export class Requests { } async loadCurrentUserLists({ reload = false } = {}) { - const currentUser = this.dataStore.$currentUser.get(); - if (!currentUser) return; - await this.loadActorLists(currentUser.did, { reload }); + if (!this.api.isAuthenticated) return; + await this.loadActorLists(this.api.session.did, { reload }); } async loadListsWithMembershipForActor( diff --git a/src/js/plugins/pluginService.js b/src/js/plugins/pluginService.js index bf3ebf91..29fe5644 100644 --- a/src/js/plugins/pluginService.js +++ b/src/js/plugins/pluginService.js @@ -1137,6 +1137,7 @@ export class PluginService extends ReactiveStore { } async getPostComposerInit({ kind, replyTo, replyRoot, quotedPost }) { + await this._waitForInitialPluginLoad(); const listeners = this.registries.eventListeners.get("post-composer-open"); if (!listeners || listeners.size === 0) return null; const context = { kind, replyTo, replyRoot, quotedPost }; diff --git a/src/js/views/search.view.js b/src/js/views/search.view.js index 04615302..cff588e9 100644 --- a/src/js/views/search.view.js +++ b/src/js/views/search.view.js @@ -175,6 +175,12 @@ export default async function searchView({ async function hydrateAndPruneRecentProfiles() { try { if (!isAuthenticated) return; + try { + await dataLayer.preferencesProvider.requirePreferences(); + } catch (error) { + console.warn("Failed to load recent search profiles", error); + return; + } const entries = dataLayer.derived.$recentSearchProfiles.get() ?? []; if (entries.length === 0) return; const dids = entries.map((entry) => entry.did); diff --git a/tests/unit/specs/dataLayer/requests.test.js b/tests/unit/specs/dataLayer/requests.test.js index bf67e4a0..479cb268 100644 --- a/tests/unit/specs/dataLayer/requests.test.js +++ b/tests/unit/specs/dataLayer/requests.test.js @@ -4214,7 +4214,7 @@ describe("loadActorLists", () => { }); describe("loadCurrentUserLists", () => { - it("should do nothing when there is no current user", async () => { + it("should do nothing when not authenticated", async () => { let called = false; const mockApi = { getActorLists: async () => { @@ -4232,11 +4232,12 @@ describe("loadCurrentUserLists", () => { assert.deepEqual(called, false); }); - it("should load the current user's lists", async () => { + it("should load the session user's lists without waiting for the current user profile", async () => { const dataStore = new DataStore(createSessionState(null)); - dataStore.$currentUser.set({ did: "did:plc:me" }); let requestedDid = null; const mockApi = { + isAuthenticated: true, + session: { did: "did:plc:me" }, getActorLists: async (did) => { requestedDid = did; return { lists: [{ uri: "l1" }], cursor: null }; diff --git a/tests/unit/specs/plugins/pluginService.test.js b/tests/unit/specs/plugins/pluginService.test.js index 3131f6bd..b76f28bb 100644 --- a/tests/unit/specs/plugins/pluginService.test.js +++ b/tests/unit/specs/plugins/pluginService.test.js @@ -2472,6 +2472,12 @@ describe("binaryCache host methods", () => { }); describe("getPostComposerInit", () => { + function makeLoadedService() { + const { service } = makeService(); + service._completeInitialLoad(); + return service; + } + function addListener(service, pluginId, handler) { let listeners = service.registries.eventListeners.get("post-composer-open"); if (!listeners) { @@ -2482,13 +2488,13 @@ describe("getPostComposerInit", () => { } it("returns null when no listeners are registered", async () => { - const { service } = makeService(); + const service = makeLoadedService(); const result = await service.getPostComposerInit({ kind: "post" }); assert.deepEqual(result, null); }); it("returns null when listeners contribute no ops and no cursor", async () => { - const { service } = makeService(); + const service = makeLoadedService(); addListener(service, "noop", async () => ({ ops: [], cursor: null })); addListener(service, "alsoNoop", async () => null); const result = await service.getPostComposerInit({ kind: "post" }); @@ -2496,7 +2502,7 @@ describe("getPostComposerInit", () => { }); it("appends text from a single listener", async () => { - const { service } = makeService(); + const service = makeLoadedService(); addListener(service, "sig", async () => ({ ops: [{ op: "append", text: "\n\n— signed" }], cursor: null, @@ -2506,7 +2512,7 @@ describe("getPostComposerInit", () => { }); it("composes set/append/prepend across multiple listeners in order", async () => { - const { service } = makeService(); + const service = makeLoadedService(); addListener(service, "alpha", async () => ({ ops: [{ op: "set", text: "middle" }], cursor: null, @@ -2524,7 +2530,7 @@ describe("getPostComposerInit", () => { }); it("last setCursor wins; nulls do not clobber prior cursor", async () => { - const { service } = makeService(); + const service = makeLoadedService(); addListener(service, "alpha", async () => ({ ops: [{ op: "append", text: "a" }], cursor: 0, @@ -2542,7 +2548,7 @@ describe("getPostComposerInit", () => { }); it("ignores listeners that throw", async () => { - const { service } = makeService(); + const service = makeLoadedService(); addListener(service, "alpha", async () => { throw new Error("boom"); }); @@ -2562,7 +2568,7 @@ describe("getPostComposerInit", () => { }); it("passes context through to each listener", async () => { - const { service } = makeService(); + const service = makeLoadedService(); let captured = null; addListener(service, "alpha", async (context) => { captured = context; @@ -2579,6 +2585,23 @@ describe("getPostComposerInit", () => { quotedPost: undefined, }); }); + + it("waits for the initial plugin load before reading listeners", async () => { + const { service } = makeService(); + let result = null; + const pending = service + .getPostComposerInit({ kind: "post" }) + .then((value) => { + result = value; + }); + addListener(service, "late", async () => ({ + ops: [{ op: "append", text: "late" }], + cursor: null, + })); + service._completeInitialLoad(); + await pending; + assert.deepEqual(result, { text: "late", cursor: null }); + }); }); describe("user-granted fetch origins", () => {