Environment: Obsidian 1.15.0/1.15.1 desktop (Linux). Also reproduced standalone with pele@1.13.0 (dist/pele.js) in Chrome 150 — no Obsidian involved.
Summary: On a diagram that is scaled down to fit its container, clicking the zoom-in (+) button applies the zoom for a single frame, then resets it back to the fitted size. The zoom-out (−) button stays disabled and the reset button disappears again. Happens in both the reading view and the editor.
Steps to reproduce (standalone):
<!doctype html>
<style>
body { margin: 0 }
.markdown-preview { width: 700px; margin: 0 auto; padding: 20px; box-sizing: border-box }
.mermaid { overflow-x: auto } /* as Obsidian styles .mermaid */
</style>
<div class="markdown-preview">
<div class="mermaid" id="m"></div>
</div>
<script type="module">
import * as pele from "https://esm.sh/pele@1.13.0";
pele.mount(document.getElementById("m"), `
flowchart LR
A[A fairly long node label that wraps] --> B[Another fairly long label here too] --> C[Yet another fairly long node label]`, { zoom: {} });
</script>Click the + button (top right of the diagram).
Conditions: the bug bites only when the container's height sits between the zoom bar's resting height and its grown height (~58–90px with default 24px buttons):
- Container taller than the grown bar → the bar never overflows → zoom persists (expected).
- Container shorter than the resting bar → the scrollbar exists from the start, so no size change occurs on click → zoom persists (but the bar is mostly clipped).
- In between (typical scaled-down
flowchart LRin Obsidian's readable line-length column) → resets on every click.
Observed (instrumented log):
rest: viewBox="0 0 751 82" svg 618.0x67.5 bar[in:grid out(dim) reset:none]
after-click: viewBox="135 14 513 55" svg 660x71 bar[in:grid out:grid reset:grid]
RO fire: container 660x71 -> 645x71, scrollHeight 90 (vertical scrollbar appeared)
t+80ms: viewBox="0 0 751 82" svg 618.0x67.5 bar[in(dim) reset:none] <-- zoom goneAnalysis:
- At rest the bar holds zoom-in + disabled zoom-out (reset hidden).
- Clicking + enables the reset button, growing the bar by ~28px. With
position: absoluteinside the container, the bar's bottom (~90px) now exceeds the container height (~71px). Absolutely positioned children extend the scrollable area, sooverflow-x: auto(which computesoverflow-ytoauto) produces a vertical scrollbar; the container's client width shrinks by the scrollbar width (660→645). - The mount's container ResizeObserver fires: the available width changed, so the diagram re-renders, and
zoom.resized()→settle()resets the scale to fit. - Resetting hides the reset button again → the bar shrinks → the scrollbar disappears → the state is stable until the next click. Every
+click repeats the cycle (one-frame zoom flash).
Expected: the zoom persists until the user zooms out or resets.
Verified workarounds (CSS, in the consuming app):
.mermaid { min-height: 96px }— the grown bar never overflows; zoom persists and all three buttons stay visible. Verified on the repro above..mermaid { overflow-y: hidden }— also works, but the reset button is partially clipped on short diagrams.
Possible fix directions: keep the bar inside the container's scrollable area (e.g., anchor it to the bottom edge when the drawing is shorter than the bar, or constrain its growth), and/or don't settle() on a resize caused by the bar itself.
Activity
2Thanks for picking this up — a PR sounds good.
Two things I measured that may save you some time:
-
There are two reset paths from the same event. The container resize fires
zoom.resized()→settle(), but it also triggers a re-render of the diagram (available width changed 660→645), and the re-render path callszoom.refresh(), which also resets to fit. Ignoring scrollbar-caused resizes alone leaves the second path resetting the zoom — so either prevent the scrollbar, or preserve scale acrossrefresh(), or both. -
On "fixed footprint": if the full 3-button height is always reserved (
visibility: hiddeninstead ofdisplay: nonefor the resting reset button), the overflow stops changing — but for containers shorter than the full bar (~86px with the default 24px buttons), the bar then overflows at rest, giving a permanent scrollbar or a clipped bar on every short diagram. My 4-node variant (container 55px) shows that state: zoom sticks only because the scrollbar is already there. Anchoring the bar tobottomfor short drawings keeps it out of the scrollable area in all three ranges, since top-overflow doesn't extend the scrollable area — the tradeoff is visual overlap with content above the diagram.
Context in case it matters: Obsidian styles .mermaid { overflow-x: auto } and pele itself sets position: relative on the element when the controls mount.
Happy to re-run my instrumented harness against the PR across all three height ranges (< 58px, 58–90px, > 90px) if useful.
Thanks for the standalone repro and the instrumented log, the feedback loop is really clear. I'd like to work on this. My idea is to make sure the zoom bar can't grow the container's scrollable area, for example by giving it a fixed footprint so it doesn't change size when the reset button appears, or by keeping it out of the scroll overflow. I'd also make the ResizeObserver ignore size changes that come only from a scrollbar appearing, so a manual zoom doesn't get reset to fit. I'll check it against your repro for all three height ranges. Happy to open a PR if that sounds good.