Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(client): re-read the storage's standing with the figures beside it
Elian Doranb091f98ade47
diff --git a/apps/client/src/widgets/type_widgets/options/database.css b/apps/client/src/widgets/type_widgets/options/database.cssindex 966460a41f..ad47bf81c6 100644--- a/apps/client/src/widgets/type_widgets/options/database.css+++ b/apps/client/src/widgets/type_widgets/options/database.css@@ -1,8 +1,6 @@.database-info .database-persistence {- /* A card option's value gives way once the description beside it has to wrap, and breaks- wherever it must: at 55px "Best-effort" loses its second half to a line of its own, where it- reads as a word in its own right. This value is one short word at either setting, so it keeps- its width and the sentence wraps instead. */+ /* "Best-effort" reads as a word of its own once it breaks in two, so the value holds its+ width and the description beside it wraps instead. */.tn-card-option-value {flex-shrink: 0;white-space: nowrap;diff --git a/apps/client/src/widgets/type_widgets/options/database.spec.tsx b/apps/client/src/widgets/type_widgets/options/database.spec.tsxindex 7eb02eb66b..3377496f87 100644--- a/apps/client/src/widgets/type_widgets/options/database.spec.tsx+++ b/apps/client/src/widgets/type_widgets/options/database.spec.tsx@@ -253,6 +253,25 @@ describe("what the database is", () => {.toContain("database.info_persistence_best_effort_description");});+ it("reads the storage's standing again with the figures, since the grant can land later", async () => {+ standalone.enabled = true;+ INFO = { ...DATABASE_INFO, filePath: null };+ let granted = false;+ setStorageManager({ persisted: async () => granted });+ renderPage();+ await settle();++ expect(infoValues()[1]).toBe("database.info_persistence_best_effort");++ // Standalone asks for the grant at startup and the browser can answer after this page is+ // already open, so the row follows the card's own refresh rather than only its mounting.+ granted = true;+ button("cleanup-button")?.click();+ await settle();++ expect(infoValues()[1]).toBe("database.info_persistence_persistent");+ });+it("leaves out the persistence row where the browser does not answer for the storage", async () => {// A database on disk stays there whatever the browser thinks, and a browser old enough to// lack `navigator.storage` has nothing to report.diff --git a/apps/client/src/widgets/type_widgets/options/database.tsx b/apps/client/src/widgets/type_widgets/options/database.tsxindex 1a88392843..b33099e085 100644--- a/apps/client/src/widgets/type_widgets/options/database.tsx+++ b/apps/client/src/widgets/type_widgets/options/database.tsx@@ -123,7 +123,7 @@ function DatabaseInfo({ refreshToken }: { refreshToken: number }) {{/* Follows the storage it qualifies, and only where that storage is the browser's:a database on disk stays there whatever the browser thinks of it. */}- {isStandalone && <StoragePersistence />}+ {isStandalone && <StoragePersistence refreshToken={refreshToken} />}<OptionCardSection label={t("database.info_content")}><span className="tn-card-option-value">@@ -159,8 +159,11 @@ function DatabaseInfo({ refreshToken }: { refreshToken: number }) {* the browser's own reading of its own storage, and there is nothing in the database to base it on.* Nothing is shown where the browser does not report it, which is every build whose database is a* file on disk.+ *+ * Read again on `refreshToken`, like the figures beside it: the startup request can still be in+ * flight when this mounts, and the browser is free to change its mind afterwards.*/-function StoragePersistence() {+function StoragePersistence({ refreshToken }: { refreshToken: number }) {const [ persisted, setPersisted ] = useState<boolean | null>(null);useEffect(() => {@@ -170,7 +173,7 @@ function StoragePersistence() {.catch(() => {});return () => { current = false; };- }, []);+ }, [ refreshToken ]);if (persisted === null) {return null;