fix(joint-core): guard against non-invertible screen CTM#3342
Open
kumilingus wants to merge 2 commits into
Open
fix(joint-core): guard against non-invertible screen CTM#3342kumilingus wants to merge 2 commits into
kumilingus wants to merge 2 commits into
Conversation
…veTransformation When a target SVG element is nested under an ancestor with a singular transform (e.g. scale(0)), its getScreenCTM() returns a matrix with det = 0. Calling .inverse() on such a matrix throws or produces a zero/NaN matrix, breaking getTransformToElement for any caller in that subtree. Detect this case and return null so getTransformToElement falls back to the identity matrix. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Guards V.getTransformToElement()’s underlying getRelativeTransformation() against non-invertible getScreenCTM() results (e.g., when an ancestor has scale(0)), preventing exceptions and allowing the API to gracefully fall back to the identity matrix.
Changes:
- Added an invertibility check for the target’s screen CTM before calling
.inverse()ingetRelativeTransformation(). - Added a regression test that reproduces a singular screen CTM and asserts
getTransformToElement()does not throw and returns identity.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| packages/joint-core/src/V/transform.mjs | Adds a determinant-based invertibility guard to avoid inverting singular screen CTMs. |
| packages/joint-core/test/vectorizer/vectorizer.js | Adds a QUnit regression test covering the singular-CTM fallback behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
QUnit fails the test automatically when an exception bubbles up, so the manual try/catch was redundant — and the unused `e` binding tripped the `no-unused-vars` rule. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
If an SVG element sits inside a zero-sized container (e.g. an
<svg>withwidth=0/height=0, a hidden<foreignObject>, or anything else the browser renders with no extent), itsgetScreenCTM()returns a zero matrix (a=b=c=d=0,det=0). We then call.inverse()on it insidegetRelativeTransformation(), which either throws or yields a NaN/zero matrix — andgetTransformToElement()breaks for everything in that subtree.This PR adds a determinant check in
getRelativeTransformation(). If the target's screen CTM isn't invertible, it returnsnullandgetTransformToElement()falls back to the identity matrix, same as it does for any other failure case.Regression test in
vectorizer.js:a=b=c=d=0anddet=0,getTransformToElement()doesn't throw and returns identity.Companion PR against
dev: #3341Test plan
yarn grunt karma:vectorizer— 453/453 pass🤖 Generated with Claude Code