Skip to content

Commit e9b7c7e

Browse files
committed
fix: Cannot read properties of null (reading 'removeChild')
1 parent 9a12572 commit e9b7c7e

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/widget.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ if (typeof window !== 'undefined') {
1414
global.React = React;
1515
}
1616

17+
Widget.prototype.removeLocalDomNodes = function() {
18+
// If this widget has directly created DOM nodes, delete them and exit.
19+
if (this.domNodes.length > 0) {
20+
$tw.utils.each(this.domNodes, function(domNode) {
21+
domNode?.parentNode?.removeChild?.(domNode);
22+
});
23+
this.domNodes = [];
24+
}
25+
};
26+
1727
class ReactWidgetImpl<
1828
IProps extends ITWReactProps = ITWReactPropsDefault,
1929
> extends Widget implements IReactWidget<IProps> {
@@ -82,7 +92,6 @@ class ReactWidgetImpl<
8292

8393
destroy() {
8494
// this only works after tiddlywiki 5.3.0
85-
this.domNodes = [];
8695
super.destroy?.();
8796
this.root?.unmount?.();
8897
}

0 commit comments

Comments
 (0)