Skip to content

Build your personal knowledge base with Trilium Notes

client/media player: fix an issue with keyboard shortcuts hints merged from multiple attachment renderers

Adorian Doran0557bc8e24d0
diff --git a/apps/client/src/widgets/react/ImageViewer.spec.tsx b/apps/client/src/widgets/react/ImageViewer.spec.tsx
index edb21e05bb..d9b19e2aa5 100644
--- a/apps/client/src/widgets/react/ImageViewer.spec.tsx
+++ b/apps/client/src/widgets/react/ImageViewer.spec.tsx
@@ -2,6 +2,7 @@ import { type ComponentChildren, render } from "preact";
import { act } from "preact/test-utils";
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+import appContext from "../../components/app_context";
import Component from "../../components/component";
import { collectShortcutHints } from "../../services/shortcut_hints";
import { ParentComponent } from "./react_utils";
@@ -87,6 +88,18 @@ describe("ImageViewer", () => {
]);
});
+ it("registers nothing on the app root, whose hints would be collected in every context", () => {
+ // A standalone Preact root mounted by the content renderer is hosted by appContext itself, and
+ // every chain the dispatcher walks ends there — so its hints would join every other widget's.
+ const container = document.createElement("div");
+ act(() => render(
+ <ParentComponent.Provider value={appContext}><ImageViewer src="x" /></ParentComponent.Provider>,
+ container
+ ));
+
+ expect(collectShortcutHints(appContext)).toEqual([]);
+ });
+
it("wires up the interactive zoom behavior", () => {
renderViewer({ src: "x" });
const props = transformWrapperSpy.mock.calls[0][0];
diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx
index 2003a7484d..a5d32b8b02 100644
--- a/apps/client/src/widgets/react/hooks.tsx
+++ b/apps/client/src/widgets/react/hooks.tsx
@@ -1179,7 +1179,12 @@ export function useContextualShortcutHints(hints: ShortcutHintDefinition | (() =
hintsRef.current = hints;
useEffect(() => {
- if (!parentComponent) return;
+ // A standalone Preact root mounted by the content renderer (a media player in a collection tile,
+ // an included note) is hosted by appContext itself. Every chain the dispatcher walks ends there,
+ // so registering would make these hints show up in *every* context — e.g. a played collection
+ // tile adding its Playback section to the image viewer's. Contextual hints need a host that
+ // sits inside the focused chain; the root never does.
+ if (!parentComponent || parentComponent === appContext) return;
const provider: ShortcutHintProvider = (collector) => {
const current = hintsRef.current;