Skip to content

Commit eb876a6

Browse files
authored
frontend: don't stop polling after an error (regression) (#140)
commit 953537f ("Replace jquery w/ axios") / PR #126, which was supposed to be a straightforward port of existing functionality from one library to another, moved the logic that queues a new game state request from a jQuery `.complete()` callback, which runs regardless of whether the request succeeded or not, to a React `.setState()` completion callback, which only runs if the request succeeded (since that's the only case where `setState()` is called). This appears to have been unintentional, and it has the effect of stopping state updates altogether after a single one fails, with the only recourse being to refresh the page. This is clearly a bad user experience, and me and my friends have personally experienced it frequently in every game we've played for the last few weeks. Fix the problem by moving the logic into a `.finally()` callback, which will execute regardless of whether the request succeeded or failed.
1 parent 964cc4e commit eb876a6

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

frontend/ui/game.tsx

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -148,20 +148,18 @@ export class Game extends React.Component {
148148
state_id: state_id,
149149
})
150150
.then(({ data }) => {
151-
this.setState(
152-
(oldState) => {
153-
const stateToUpdate = { game: data };
154-
if (oldState.game && data.created_at != oldState.game.created_at) {
155-
stateToUpdate.codemaster = false;
156-
}
157-
return stateToUpdate;
158-
},
159-
() => {
160-
setTimeout(() => {
161-
this.refresh();
162-
}, 2000);
151+
this.setState((oldState) => {
152+
const stateToUpdate = { game: data };
153+
if (oldState.game && data.created_at != oldState.game.created_at) {
154+
stateToUpdate.codemaster = false;
163155
}
164-
);
156+
return stateToUpdate;
157+
});
158+
})
159+
.finally(() => {
160+
setTimeout(() => {
161+
this.refresh();
162+
}, 2000);
165163
});
166164
}
167165

0 commit comments

Comments
 (0)