From 0afaf4358fd358e3b7e2fa963803e70db808da7d Mon Sep 17 00:00:00 2001 From: Christian Fehmer Date: Thu, 21 May 2026 08:51:45 +0200 Subject: [PATCH] fix: tags not getting loaded (@fehmer) (#7988) fixes #7990 --- frontend/src/ts/auth.tsx | 4 +++- frontend/src/ts/collections/results.ts | 8 ++++---- frontend/src/ts/collections/tags.ts | 11 +++++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/frontend/src/ts/auth.tsx b/frontend/src/ts/auth.tsx index f0956823bc59..17efe71182ba 100644 --- a/frontend/src/ts/auth.tsx +++ b/frontend/src/ts/auth.tsx @@ -10,6 +10,7 @@ import { import Ape from "./ape"; import { waitForPresetsReady } from "./collections/presets"; +import { waitForTagsReady } from "./collections/tags"; import { updateFromServer as updateConfigFromServer } from "./config/remote"; import * as DB from "./db"; import { authEvent } from "./events/auth"; @@ -66,8 +67,9 @@ async function getDataAndInit(): Promise { try { console.log("getting account data"); const snapshot = await DB.initSnapshot(); - //TODO: always load presets for now, remove when __nonReactive is removed from presets collection + //TODO: preload collections for now, remove when __nonReactive is removed from collections await waitForPresetsReady(); + await waitForTagsReady(); if (snapshot === false) { throw new Error( diff --git a/frontend/src/ts/collections/results.ts b/frontend/src/ts/collections/results.ts index a9146207224c..c348577d686b 100644 --- a/frontend/src/ts/collections/results.ts +++ b/frontend/src/ts/collections/results.ts @@ -31,9 +31,9 @@ import { isAuthenticated } from "../states/core"; import { getLastResult, setLastResult } from "../states/snapshot"; import { getActiveTagsOnce, + getTagsOnce, reconcileLocalTagPB, saveLocalTagPB, - __nonReactive as tagsNonReactive, } from "./tags"; import { applyIdWorkaround } from "./utils/misc"; @@ -215,9 +215,9 @@ const resultsCollection = createCollection( queryKey: queryKeys.root(), queryFn: async () => { if (!isAuthenticated()) return []; - const knownTagIds = new Set( - tagsNonReactive.getTags().map((it) => it._id), - ); + const tagIds = await getTagsOnce(); + + const knownTagIds = new Set([...tagIds.map((it) => it._id)]); //const options = parseLoadSubsetOptions(ctx.meta?.loadSubsetOptions); const response = await Ape.results.get({ diff --git a/frontend/src/ts/collections/tags.ts b/frontend/src/ts/collections/tags.ts index a101c873bece..494441d66f59 100644 --- a/frontend/src/ts/collections/tags.ts +++ b/frontend/src/ts/collections/tags.ts @@ -73,6 +73,13 @@ export async function getActiveTagsOnce() { }); } +// oxlint-disable-next-line typescript/explicit-function-return-type +export async function getTagsOnce() { + return queryOnce((q) => { + return q.from({ tag: tagsCollection }); + }); +} + type ActionType = { insertTag: { name: string; @@ -242,6 +249,10 @@ const actions = { // --- Public API --- +export async function waitForTagsReady(): Promise { + await tagsCollection.stateWhenReady(); +} + export async function insertTag( params: ActionType["insertTag"], ): Promise {