Skip to content

Build your personal knowledge base with Trilium Notes

fix(client): keep a hidden tab's title as it was left

Elian Doranc67c83b9b82c
diff --git a/apps/client/src/widgets/layout/InlineTitle.spec.ts b/apps/client/src/widgets/layout/InlineTitle.spec.ts
index 78ad7207e2..e811e8d27a 100644
--- a/apps/client/src/widgets/layout/InlineTitle.spec.ts
+++ b/apps/client/src/widgets/layout/InlineTitle.spec.ts
@@ -39,8 +39,17 @@ describe("observeTitleInView", () => {
const [ observer ] = observers;
expect(observer.options?.root).toBe(container);
- observer.callback([ { isIntersecting: false } as IntersectionObserverEntry ], {} as IntersectionObserver);
+ const report = (isIntersecting: boolean, width: number, height: number) => observer.callback(
+ [ { isIntersecting, boundingClientRect: { width, height } } as IntersectionObserverEntry ],
+ {} as IntersectionObserver);
+ report(false, 300, 40);
expect(onChange).toHaveBeenLastCalledWith(false);
+ report(true, 300, 40);
+ expect(onChange).toHaveBeenLastCalledWith(true);
+
+ // The title of a hidden tab has no box; it keeps the state it was left in.
+ report(false, 0, 0);
+ expect(onChange).toHaveBeenCalledTimes(2);
stop();
expect(observer.disconnect).toHaveBeenCalled();
diff --git a/apps/client/src/widgets/layout/InlineTitle.tsx b/apps/client/src/widgets/layout/InlineTitle.tsx
index 5c74a202c2..c30678031f 100644
--- a/apps/client/src/widgets/layout/InlineTitle.tsx
+++ b/apps/client/src/widgets/layout/InlineTitle.tsx
@@ -82,7 +82,12 @@ export default function InlineTitle() {
* navigation stack on iPhones) keeps its title in view while it moves.
*/
export function observeTitleInView(title: HTMLElement, onChange: (isInView: boolean) => void) {
- const observer = new IntersectionObserver((entries) => onChange(entries[0].isIntersecting), {
+ const observer = new IntersectionObserver(([ entry ]) => {
+ // A title with no box sits in a hidden tab, which shows it again as it was left.
+ const { width, height } = entry.boundingClientRect;
+ if (!entry.isIntersecting && !width && !height) return;
+ onChange(entry.isIntersecting);
+ }, {
root: title.closest(".scrolling-container"),
threshold: 0.85
});