Skip to content

fix(canvas): restore cached state after text and destroy - #2271

Merged
wang1212 merged 1 commit into
antvis:releasefrom
dajiaohuang:fix/canvas-renderer-style-cache-and-event-retention
Nov 13, 2026
Merged

wang1212 merged 1 commit into
antvis:releasefrom
dajiaohuang:fix/canvas-renderer-style-cache-and-event-retention

Conversation

@dajiaohuang

Copy link
Copy Markdown

Summary

  • Invalidate the optimized Canvas line-width cache after text rendering writes directly to the context, so a following path reapplies its requested stroke width.
  • Clear propagation paths on reused lifecycle events during Canvas.destroy() to release references to destroyed canvases and detached containers.
  • Add focused regression tests and a patch changeset.

Closes #2251 and #2253.

Validation

  • pnpm exec jest --config jest.unit.config.js --runInBand __tests__/unit/plugins/canvas-rendering-optimization.spec.ts __tests__/unit/dom/canvas-destroy-event-path.spec.ts — 2 suites, 2 tests passed.
  • Targeted ESLint passed for changed TypeScript files.
  • Prettier check passed for changed files.

@changeset-bot

changeset-bot Bot commented Oct 24, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d893445

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 29 packages
Name Type
@antv/g-canvas Patch
@antv/g-lite Patch
@antv/g-canvaskit Patch
@antv/g-mobile-canvas Patch
@antv/g-plugin-rough-canvas-renderer Patch
@antv/g-plugin-zdog-canvas-renderer Patch
@antv/g-web-components Patch
@antv/g-lottie-player Patch
@antv/g-mobile-svg Patch
@antv/g-mobile-webgl Patch
@antv/g-plugin-3d Patch
@antv/g-plugin-a11y Patch
@antv/g-plugin-annotation Patch
@antv/g-plugin-box2d Patch
@antv/g-plugin-control Patch
@antv/g-plugin-css-select Patch
@antv/g-plugin-device-renderer Patch
@antv/g-plugin-dragndrop Patch
@antv/g-plugin-gesture Patch
@antv/g-plugin-matterjs Patch
@antv/g-plugin-physx Patch
@antv/g-plugin-rough-svg-renderer Patch
@antv/g-plugin-yoga Patch
@antv/g-plugin-zdog-svg-renderer Patch
@antv/g-svg Patch
@antv/g-webgl Patch
@antv/g-webgpu Patch
@antv/g Patch
@antv/react-g Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Deleting the line-width cache entry lets subsequent default-width paths inherit text’s wider stroke, so the cache must reflect the actual context width and the regression test must cover this case.

1 open issue
What changed in this PR

This PR addresses Canvas stroke-width inconsistencies after text rendering and retained event references after canvas destruction, targeting issues #2251 and #2253.

Changes:

  • Adjusts the optimized renderer’s line-width cache after text rendering.
  • Clears reused event propagation paths during Canvas.destroy().
  • Adds focused regression tests and patch changesets for both packages.
File Description
packages/​g-lite/​src/​Canvas.ts Clears event paths during canvas destruction.
packages/​g-canvas/​src/​plugins/​canvas-renderer/​shapes/​styles/​Text.ts Deletes the cached line width after rendering text.
.changeset/​calm-paths-render.md Records patch releases for both fixes.
__tests__/​unit/​plugins/​canvas-rendering-optimization.spec.ts Tests stroke-width restoration after text rendering.
__tests__/​unit/​dom/​canvas-destroy-event-path.spec.ts Tests lifecycle event path cleanup on destruction.

Review effort: Balanced

);

// Text rendering sets lineWidth directly, bypassing the optimized context cache.
renderState.currentContext.delete('lineWidth');
@wang1212
wang1212 changed the base branch from master to release November 13, 2026 13:29
@wang1212
wang1212 merged commit 8fcee05 into antvis:release Nov 13, 2026
5 checks passed
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.

[g-canvas] Path lineWidth can be rendered incorrectly with enableRenderingOptimization

4 participants