Skip to content

fix(canvas): detect non-scaleX transforms and honor shader value cache#122

Merged
chiefcll merged 1 commit into
mainfrom
fix/canvas-transform-and-shader-cache
Jul 2, 2026
Merged

fix(canvas): detect non-scaleX transforms and honor shader value cache#122
chiefcll merged 1 commit into
mainfrom
fix/canvas-transform-and-shader-cache

Conversation

@chiefcll

@chiefcll chiefcll commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes the two correctness bugs from the Canvas2D hot-path review (docs/canvas-renderer-review.md, items 1 and 2):

  • addQuad missed scaleY-only transforms. hasTransform checked only ta !== 1, so any transform with scaleX === 1 — scaleY-only, rotation, skew — was silently dropped and the node drew untransformed. Now checks all four matrix components: ta !== 1 || td !== 1 || tb !== 0 || tc !== 0.

  • CanvasShaderNode.update never used its value cache. On a shader-value-cache hit it assigned this.computed = computed and then unconditionally fell through to recompute, allocate a fresh computed object, and re-register the key. Added the missing early return, matching WebGlShaderNode.update. Cache hits now skip the recompute and allocation.

Tests

  • Three addQuad transform-detection cases (scaleY-only, rotation-only, identity skip) in CanvasRenderer.test.ts
  • New CanvasShaderNode.test.ts covering cache miss, cache hit, and unchanged-key paths

🤖 Generated with Claude Code

Two correctness bugs in the Canvas2D backend:

- addQuad detected a transform only when ta !== 1, so scaleY-only,
  rotation, and skew transforms with scaleX === 1 were silently dropped
  and the node drew untransformed. Check all four matrix components.

- CanvasShaderNode.update assigned cached shader values on a value-key
  hit but fell through to recompute anyway, making the canvas shader
  value cache dead code. Add the missing early return, matching
  WebGlShaderNode.update.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@chiefcll chiefcll merged commit b1e732d into main Jul 2, 2026
1 check passed
@chiefcll chiefcll deleted the fix/canvas-transform-and-shader-cache branch July 2, 2026 20:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant