Skip to content

Commit 1c5b04e

Browse files
authored
site: replace isCancelled with cancelledRef (ant-design#56415)
1 parent 330c5be commit 1c5b04e

2 files changed

Lines changed: 16 additions & 14 deletions

File tree

.dumi/theme/common/BehaviorMap/BehaviorMap.tsx

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,22 @@ const BehaviorMap: React.FC<BehaviorMapProps> = ({ data }) => {
106106

107107
const mermaidCode = useMermaidCode(data);
108108

109+
const cancelledRef = useRef<boolean>(false);
110+
109111
useEffect(() => {
110-
let isCancelled = false;
112+
cancelledRef.current = false;
111113

112114
const renderChart = async () => {
113-
if (!chartRef.current || !mermaidCode) return;
115+
if (!chartRef.current || !mermaidCode) {
116+
return;
117+
}
114118

115119
try {
116-
const mermaidModule = await import('mermaid');
117-
const mermaid = mermaidModule.default;
120+
const mermaid = (await import('mermaid')).default;
118121

119-
if (isCancelled) return;
122+
if (cancelledRef.current) {
123+
return;
124+
}
120125

121126
mermaid.initialize({
122127
startOnLoad: false,
@@ -130,18 +135,15 @@ const BehaviorMap: React.FC<BehaviorMapProps> = ({ data }) => {
130135
},
131136
});
132137

133-
let mermaidChartCounter = 0;
134-
mermaidChartCounter += 1;
135-
const id = `mermaid-${Date.now()}-${mermaidChartCounter}`;
138+
const id = `mermaid-${Date.now()}`;
136139

137140
const { svg } = await mermaid.render(id, mermaidCode);
138141

139-
if (!isCancelled && chartRef.current) {
142+
if (!cancelledRef.current && chartRef.current) {
140143
chartRef.current.innerHTML = svg;
141144
}
142-
} catch (error) {
143-
if (!isCancelled && chartRef.current) {
144-
console.error('Mermaid render error:', error);
145+
} catch {
146+
if (!cancelledRef.current && chartRef.current) {
145147
chartRef.current.innerHTML = 'Render Error';
146148
}
147149
}
@@ -150,7 +152,7 @@ const BehaviorMap: React.FC<BehaviorMapProps> = ({ data }) => {
150152
renderChart();
151153

152154
return () => {
153-
isCancelled = true;
155+
cancelledRef.current = true;
154156
};
155157
}, [mermaidCode]);
156158

.dumi/theme/common/BezierVisualizer/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const locales = {
2020
},
2121
};
2222

23-
const BezierVisualizer = (props: BezierVisualizerProps) => {
23+
const BezierVisualizer: React.FC<BezierVisualizerProps> = (props) => {
2424
const { value } = props;
2525
const [locale] = useLocale(locales);
2626

0 commit comments

Comments
 (0)