Skip to content

Commit 6649ca8

Browse files
committed
refactor: Simplify chart big number renderer by directly rendering to the element and improve cleanup logic for unmounting components
1 parent ed5329d commit 6649ca8

File tree

1 file changed

+11
-14
lines changed
  • src/webviews/webview-side/chart-big-number-renderer

1 file changed

+11
-14
lines changed

src/webviews/webview-side/chart-big-number-renderer/index.ts

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,12 @@ export const activate: ActivationFunction = (_context: RendererContext<unknown>)
2121

2222
const chartBigNumberOutput = DeepnoteChartBigNumberOutputSchema.parse(data);
2323

24-
const root = document.createElement('div');
25-
element.appendChild(root);
26-
2724
ReactDOM.render(
2825
React.createElement(ChartBigNumberOutputRenderer, {
2926
output: chartBigNumberOutput,
3027
metadata: blockMetadata
3128
}),
32-
root
29+
element
3330
);
3431
} catch (error) {
3532
console.error('Error rendering chart big number:', error);
@@ -42,23 +39,23 @@ export const activate: ActivationFunction = (_context: RendererContext<unknown>)
4239
},
4340

4441
disposeOutputItem(id?: string) {
45-
// Cleanup if needed
42+
// If undefined, all cells are being removed.
4643
if (id == null) {
44+
for (let i = 0; i < document.children.length; i++) {
45+
const child = document.children.item(i);
46+
if (child == null) {
47+
continue;
48+
}
49+
ReactDOM.unmountComponentAtNode(child);
50+
}
4751
return;
4852
}
53+
4954
const element = document.getElementById(id);
5055
if (element == null) {
5156
return;
5257
}
53-
const roots = element.getElementsByTagName('div');
54-
for (let i = 0; i < roots.length; i++) {
55-
const root = roots.item(i);
56-
if (root == null) {
57-
continue;
58-
}
59-
ReactDOM.unmountComponentAtNode(root);
60-
element.removeChild(root);
61-
}
58+
ReactDOM.unmountComponentAtNode(element);
6259
}
6360
};
6461
};

0 commit comments

Comments
 (0)