Merged
Conversation
When a project is loaded via the directory picker, all .md files are opened as tabs with paths relative to the project root (e.g. "components/database.md"). Sub-model links in the SVG carry the raw DSL value (e.g. "./components/database.md" or "../components/database.md"), which never matched the tab paths exactly, causing openOrSwitchToTab to open a blank new tab instead of switching to the existing one. The blank tab produced an empty SVG, which made svg-pan-zoom crash with a non-finite SVGMatrix error. Replace the single exact-path lookup with a three-stage search: 1. Exact match on the raw or ./-stripped path 2. Suffix match — handles ../ references where the tab path is rooted at the project directory but the DSL ref is relative to the current model 3. Basename match — fallback when there is exactly one open tab with that filename (safe because multi-file projects rarely reuse filenames) When projectLoaded is true and no match is found, return early with a console warning instead of creating a blank tab (which would crash svg-pan-zoom on the empty SVG). The blank-tab fallback is kept only for server-managed mode where the user may legitimately start editing a new sub-model. Also defer svg-pan-zoom init to requestAnimationFrame with a cancellation guard (_panZoomRafId) to prevent initialization on detached SVG elements during rapid tab switches. All panZoomInstance.destroy() calls are wrapped in try/catch to silence already-destroyed errors.
Path-based matching was unreliable: DSL refs are relative to the current model file (./components/db.md) while tabs store project-root-relative paths (components/db.md), and ../ refs make path normalization even harder. Simplify openOrSwitchToTab to extract only the filename (basename) from the submodel href and compare it against the basename of every open tab's path. This works regardless of directory nesting, ../ traversals, or OS path separators.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When a project is loaded via the directory picker, all .md files are
opened as tabs with paths relative to the project root (e.g.
"components/database.md"). Sub-model links in the SVG carry the raw DSL
value (e.g. "./components/database.md" or "../components/database.md"),
which never matched the tab paths exactly, causing openOrSwitchToTab to
open a blank new tab instead of switching to the existing one. The blank
tab produced an empty SVG, which made svg-pan-zoom crash with a
non-finite SVGMatrix error.
Replace the single exact-path lookup with a three-stage search:
the project directory but the DSL ref is relative to the current model
filename (safe because multi-file projects rarely reuse filenames)
When projectLoaded is true and no match is found, return early with a
console warning instead of creating a blank tab (which would crash
svg-pan-zoom on the empty SVG). The blank-tab fallback is kept only for
server-managed mode where the user may legitimately start editing a new
sub-model.
Also defer svg-pan-zoom init to requestAnimationFrame with a cancellation
guard (_panZoomRafId) to prevent initialization on detached SVG elements
during rapid tab switches. All panZoomInstance.destroy() calls are
wrapped in try/catch to silence already-destroyed errors.