diff --git a/common/changes/@visactor/vchart/refactor-react-vchart_2024-01-22-04-35.json b/common/changes/@visactor/vchart/refactor-react-vchart_2024-01-22-04-35.json new file mode 100644 index 0000000000..e2bfa166f1 --- /dev/null +++ b/common/changes/@visactor/vchart/refactor-react-vchart_2024-01-22-04-35.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "refactor: deprecated `useSyncRender` in react-vchart\n\n", + "type": "none", + "packageName": "@visactor/vchart" + } + ], + "packageName": "@visactor/vchart", + "email": "dingling112@gmail.com" +} \ No newline at end of file diff --git a/packages/react-vchart/src/charts/BaseChart.tsx b/packages/react-vchart/src/charts/BaseChart.tsx index 1eaf05d2e0..3753ae72b0 100644 --- a/packages/react-vchart/src/charts/BaseChart.tsx +++ b/packages/react-vchart/src/charts/BaseChart.tsx @@ -61,6 +61,7 @@ export interface BaseChartProps * use sync render * * @since 1.8.3 + * @deprecated 1.9.0 **/ useSyncRender?: boolean; } @@ -90,7 +91,6 @@ const BaseChart: React.FC = React.forwardRef((props, ref) => { const prevSpec = useRef(pickWithout(props, notSpecKeys)); const eventsBinded = React.useRef(null); const skipFunctionDiff = !!props.skipFunctionDiff; - const useSyncRender = !!props.useSyncRender; const parseSpec = (props: Props) => { if (hasSpec && props.spec) { @@ -134,13 +134,8 @@ const BaseChart: React.FC = React.forwardRef((props, ref) => { const renderChart = () => { if (chartContext.current.chart) { - if (useSyncRender) { - chartContext.current.chart.renderSync(); - handleChartRender(); - } else { - // eslint-disable-next-line promise/catch-or-return - chartContext.current.chart.renderAsync().then(handleChartRender); - } + chartContext.current.chart.renderSync(); + handleChartRender(); } }; @@ -160,18 +155,11 @@ const BaseChart: React.FC = React.forwardRef((props, ref) => { if (hasSpec) { if (!isEqual(eventsBinded.current.spec, props.spec, { skipFunction: skipFunctionDiff })) { eventsBinded.current = props; - if (useSyncRender) { - chartContext.current.chart.updateSpecSync(parseSpec(props), undefined, { - morph: false, - enableExitAnimation: false - }); - handleChartRender(); - } else { - // eslint-disable-next-line promise/catch-or-return - chartContext.current.chart - .updateSpec(parseSpec(props), undefined, { morph: false, enableExitAnimation: false }) // morph临时关掉 - .then(handleChartRender); - } + chartContext.current.chart.updateSpecSync(parseSpec(props), undefined, { + morph: false, + enableExitAnimation: false + }); + handleChartRender(); } return; } @@ -184,18 +172,11 @@ const BaseChart: React.FC = React.forwardRef((props, ref) => { ) { prevSpec.current = newSpec; - if (useSyncRender) { - chartContext.current.chart.updateSpecSync(parseSpec(props), undefined, { - morph: false, - enableExitAnimation: false - }); - handleChartRender(); - } else { - // eslint-disable-next-line promise/catch-or-return - chartContext.current.chart - .updateSpec(parseSpec(props), undefined, { morph: false, enableExitAnimation: false }) // morph临时关掉 - .then(handleChartRender); - } + chartContext.current.chart.updateSpecSync(parseSpec(props), undefined, { + morph: false, + enableExitAnimation: false + }); + handleChartRender(); } chartContext.current = { ...chartContext.current,