diff --git a/src/viewer/ui/Zoom.test.tsx b/src/viewer/ui/Zoom.test.tsx
new file mode 100644
index 0000000..ee2f116
--- /dev/null
+++ b/src/viewer/ui/Zoom.test.tsx
@@ -0,0 +1,51 @@
+///
+///
+///
+// A kept window stays drawn but hidden when closed, so its frames keep their state (the TradingView charts' zoom); a
+// plain one goes away; neither is drawn before its first open
+import { afterAll, beforeAll, expect, test } from 'bun:test';
+import { GlobalRegistrator } from '@happy-dom/global-registrator';
+
+// no animations here: the window opens and closes at once (Zoom's path for a browser without Element.animate); put back
+// afterwards, the other test files share the same classes
+let animate: unknown;
+beforeAll(() => {
+ GlobalRegistrator.register({ url: 'http://localhost:1237/' });
+ (globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }).IS_REACT_ACT_ENVIRONMENT = true;
+ const proto = Element.prototype as unknown as { animate?: unknown };
+ animate = proto.animate;
+ proto.animate = undefined;
+});
+afterAll(() => {
+ (Element.prototype as unknown as { animate?: unknown }).animate = animate;
+ GlobalRegistrator.unregister();
+});
+
+test('closed, a kept window stays hidden with its content, a plain one is gone', async () => {
+ const { act } = await import('react');
+ const { createRoot } = await import('react-dom/client');
+ const { Zoom } = await import('./Zoom');
+ document.body.innerHTML = '
';
+ const root = createRoot(document.getElementById('root')!);
+ const draw = (open: boolean, keep: boolean) => act(async () => root.render(
undefined}>));
+ const win = () => document.querySelector
('[data-chart-zoom]');
+
+ await draw(false, true);
+ expect(win()).toBeNull(); // never opened: nothing drawn, nothing loaded
+ await draw(true, true);
+ expect(win()?.style.visibility).toBe('');
+ const frame = document.querySelector('[data-frame]');
+ await draw(false, true);
+ expect(win()?.dataset.parked).toBe('on');
+ expect(win()?.style.visibility).toBe('hidden');
+ expect(win()?.hasAttribute('inert')).toBe(true);
+ expect(document.querySelector('[data-frame]')).toBe(frame); // the same frame, not a new one
+ await draw(true, true);
+ expect(win()?.dataset.parked).toBeUndefined();
+ expect(win()?.style.visibility).toBe('');
+ expect(document.querySelector('[data-frame]')).toBe(frame);
+ // no longer the kept one (another window opened): closed, it goes away
+ await draw(false, false);
+ expect(win()).toBeNull();
+ await act(async () => root.unmount());
+});
diff --git a/src/viewer/ui/Zoom.tsx b/src/viewer/ui/Zoom.tsx
index 3ef0e6a..0c0e7ad 100644
--- a/src/viewer/ui/Zoom.tsx
+++ b/src/viewer/ui/Zoom.tsx
@@ -21,11 +21,18 @@ const focusables = (root: HTMLElement): HTMLElement[] =>
// `heading`: what the title line shows when it is more than the words of `title` (a link); `oneLine`: the tools stay on the
// title's line on a phone too, wrapping only when they do not fit (the chart window, owner 2026-12-03: "I dont want to see
// intervals below line with ticker")
-export function Zoom({ open, title, onClose, children, tools, origin, narrow, heading, oneLine }: { open: boolean; title: string; onClose: () => void; children: React.ReactNode; tools?: React.ReactNode; origin?: React.RefObject; narrow?: boolean; heading?: React.ReactNode; oneLine?: boolean }) {
+// `keep`: closed, the window stays drawn but hidden (visibility, the same size, no events), so what lives in its frames
+// keeps its state for the next open (the TradingView charts' zoom and position, owner 2026-12-03: "next time I open (if not
+// pressed on ↻) the config for these charts should stay the same as it was before I closed"); a frame cannot be moved or
+// read, only kept
+export function Zoom({ open, title, onClose, children, tools, origin, narrow, heading, oneLine, keep }: { open: boolean; title: string; onClose: () => void; children: React.ReactNode; tools?: React.ReactNode; origin?: React.RefObject; narrow?: boolean; heading?: React.ReactNode; oneLine?: boolean; keep?: boolean }) {
const [mounted, setMounted] = useState(open);
+ // opened at least once: before that nothing is drawn, a kept window loads its frames only when first opened
+ const [opened, setOpened] = useState(open);
+ const root = useRef(null);
const panel = useRef(null);
const back = useRef(null);
- useEffect(() => { if (open) setMounted(true); }, [open]);
+ useEffect(() => { if (open) { setMounted(true); setOpened(true); } }, [open]);
useLayoutEffect(() => {
const p = panel.current;
const b = back.current;
@@ -49,7 +56,12 @@ export function Zoom({ open, title, onClose, children, tools, origin, narrow, he
let done = false;
grow.onfinish = () => {
done = true;
- if (open) { grow.cancel(); dim.cancel(); } else setMounted(false);
+ if (open) { grow.cancel(); dim.cancel(); return; }
+ // a kept window hides before its animation lets go of the shrunk look, so it never flashes back full size
+ if (root.current) root.current.style.visibility = 'hidden';
+ grow.cancel();
+ dim.cancel();
+ setMounted(false);
};
// a reopen while it shrinks stops the old animation; the new one starts from the card again
return () => { if (!done) { grow.cancel(); dim.cancel(); } };
@@ -86,11 +98,13 @@ export function Zoom({ open, title, onClose, children, tools, origin, narrow, he
const fromFrames = panel.current ? frameKeys(panel.current, (e) => { if (e.key === 'Escape') onClose(); }) : () => undefined;
return () => { window.removeEventListener('keydown', onKey); fromFrames(); };
}, [open, onClose, mounted]); // mounted: the window is drawn a moment after `open`, its frames with it
- if (!mounted) return null;
+ const parked = !mounted && !!keep && opened;
+ if (!mounted && !parked) return null;
// drawn into , not inside the card: a card in the packed columns with its own view-transition layer would let
// the next card paint over the window (owner 2026-11-24 found it)
return createPortal((
-
+
{/* the tools sit on the right next to ✕, as on the card next to ⤢ (owner 2026-11-24: "move all buttons to the right") */}