From 840bf907170871aa73fe453d854597b59400dcd7 Mon Sep 17 00:00:00 2001 From: Aaron Date: Wed, 27 Nov 2024 22:00:23 +0800 Subject: [PATCH] fix: fix error occurred when setRenderer (#1861) * fix: fix error occured when setRenderer * chore: commit changeset --- .changeset/tidy-bulldogs-give.md | 5 +++++ __tests__/demos/bugfix/index.ts | 1 + __tests__/demos/bugfix/switch-renderer.ts | 13 +++++++++++++ __tests__/main.ts | 2 +- __tests__/unit/abstract-renderer.spec.ts | 1 - packages/g-lite/src/Canvas.ts | 2 -- 6 files changed, 20 insertions(+), 4 deletions(-) create mode 100644 .changeset/tidy-bulldogs-give.md create mode 100644 __tests__/demos/bugfix/switch-renderer.ts diff --git a/.changeset/tidy-bulldogs-give.md b/.changeset/tidy-bulldogs-give.md new file mode 100644 index 000000000..62ae85f66 --- /dev/null +++ b/.changeset/tidy-bulldogs-give.md @@ -0,0 +1,5 @@ +--- +'@antv/g-lite': patch +--- + +fix: fix error occured when setRenderer diff --git a/__tests__/demos/bugfix/index.ts b/__tests__/demos/bugfix/index.ts index abcffb7b7..7a0e746ff 100644 --- a/__tests__/demos/bugfix/index.ts +++ b/__tests__/demos/bugfix/index.ts @@ -10,3 +10,4 @@ export { test_pick } from './1747'; export { issue_1760 } from './1760'; export { textWordWrap } from './textWordWrap'; export { group_with_stroke } from './group-with-stroke'; +export { switchRenderer } from './switch-renderer'; diff --git a/__tests__/demos/bugfix/switch-renderer.ts b/__tests__/demos/bugfix/switch-renderer.ts new file mode 100644 index 000000000..342ee0a9e --- /dev/null +++ b/__tests__/demos/bugfix/switch-renderer.ts @@ -0,0 +1,13 @@ +import { Renderer } from '@antv/g-canvas'; + +export async function switchRenderer(context) { + const { canvas } = context; + + await canvas.ready; + + const renderer = new Renderer(); + + canvas.setRenderer(renderer); + + console.log('switched'); +} diff --git a/__tests__/main.ts b/__tests__/main.ts index 01ca9f768..a318549c7 100644 --- a/__tests__/main.ts +++ b/__tests__/main.ts @@ -155,7 +155,7 @@ plot(); async function plot() { if (currentContainer) { currentContainer.remove(); - if (canvas) canvas.destroy(false); + if (canvas) canvas.destroy(); if (prevAfter) prevAfter(); } currentContainer = document.createElement('div'); diff --git a/__tests__/unit/abstract-renderer.spec.ts b/__tests__/unit/abstract-renderer.spec.ts index 4beca7f0e..7444d7d10 100644 --- a/__tests__/unit/abstract-renderer.spec.ts +++ b/__tests__/unit/abstract-renderer.spec.ts @@ -22,7 +22,6 @@ describe('Abstract renderer', () => { enableRenderingOptimization: false, enableDirtyRectangleRendering: true, enableDirtyRectangleRenderingDebug: false, - enableRenderingOptimization: false, enableSizeAttenuation: true, }); diff --git a/packages/g-lite/src/Canvas.ts b/packages/g-lite/src/Canvas.ts index 947378806..a9129568f 100644 --- a/packages/g-lite/src/Canvas.ts +++ b/packages/g-lite/src/Canvas.ts @@ -423,8 +423,6 @@ export class Canvas extends EventTarget implements ICanvas { if (this.context.rBushRoot) { // clear rbush this.context.rBushRoot.clear(); - this.context.rBushRoot = null; - this.context.renderingContext.root = null; } if (!skipTriggerEvent) {