Skip to content

Commit 5dca8a5

Browse files
committed
Clear timeout of resetting update state with new updates
This resolves an issue where a previous timeout could wipe the state, and leave the UI in a broken state.
1 parent f84a360 commit 5dca8a5

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/components/Gist.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class Gist extends Component {
155155
if (updateGistStatus.succeeded) {
156156
const prevGistUpdateStatus = getStatus({ gists }, `gists.meta.${gistId}.updateStatus`);
157157
if (prevGistUpdateStatus.pending) {
158-
setTimeout(() => resetUpdateGistStatus(gistId), 1500);
158+
this.resettingUpdate = setTimeout(() => resetUpdateGistStatus(gistId), 1500);
159159
}
160160
}
161161
}
@@ -186,6 +186,13 @@ class Gist extends Component {
186186
const { gistId, updateGist } = this.props;
187187
const { description, files } = this.state;
188188

189+
// We may have a timer already set to "reset" the
190+
// state of the update request if a previous request
191+
// succeeded. If that is the case, we need to end the
192+
// timer.
193+
// For more, see `componentDidUpdate`
194+
clearTimeout(this.resettingUpdate);
195+
189196
updateGist(gistId, {
190197
description,
191198
files

0 commit comments

Comments
 (0)