Skip to content

Commit 0ed6fa7

Browse files
fix dispatch after unmount
1 parent 8318a8a commit 0ed6fa7

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

tea-cup/src/TeaCup/Program.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ export class Program<Model, Msg> extends Component<ProgramProps<Model, Msg>, nev
6262
}
6363

6464
dispatch(msg: Msg) {
65+
if (this.currentSub === undefined) {
66+
return;
67+
}
6568
if (this.props.devTools && this.props.devTools.isPaused()) {
6669
// do not process messages if we are paused
6770
return;
@@ -89,7 +92,7 @@ export class Program<Model, Msg> extends Component<ProgramProps<Model, Msg>, nev
8992
const d = this.dispatch.bind(this);
9093

9194
newSub.init(d);
92-
prevSub && prevSub.release();
95+
prevSub?.release();
9396

9497
// perform commands in a separate timout, to
9598
// make sure that this dispatch is done
@@ -115,6 +118,11 @@ export class Program<Model, Msg> extends Component<ProgramProps<Model, Msg>, nev
115118
}
116119
}
117120

121+
componentWillUnmount() {
122+
this.currentSub?.release();
123+
this.currentSub = undefined;
124+
}
125+
118126
componentDidMount() {
119127
const { devTools } = this.props;
120128
if (devTools) {

0 commit comments

Comments
 (0)