Skip to content

Commit 0f7704d

Browse files
committed
fix: handle state change with missing currentWidgetId
There is potentially a race condition between prefetch triggering onComplete and the onComplete for updated query from the state change. This functionality could use a refactor/rethink.
1 parent 51ae87b commit 0f7704d

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

app/javascript/components/widget-controller.jsx

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,27 @@ export class WidgetController extends React.Component {
113113
};
114114

115115
nextWidget = () => {
116-
this.setState(({ nextWidgetId }) =>
117-
nextWidgetId
118-
? {
119-
currentWidgetId: nextWidgetId,
120-
nextWidgetId: null,
121-
prevWidgetId: null,
122-
transitionTime: null,
123-
}
124-
: {},
125-
);
116+
this.setState(state => {
117+
const { nextWidgetId } = state;
118+
if (!nextWidgetId) {
119+
// eslint-disable-next-line
120+
console.error(
121+
`FATAL: nextWidgetId is undefined for nextWidget call. state: ${state}`,
122+
);
123+
return {
124+
currentWidgetId: null,
125+
nextWidgetId: null,
126+
prevWidgetId: null,
127+
transitionTime: null,
128+
};
129+
}
130+
return {
131+
currentWidgetId: nextWidgetId,
132+
nextWidgetId: null,
133+
prevWidgetId: null,
134+
transitionTime: null,
135+
};
136+
});
126137
};
127138

128139
prevWidget = () => {

0 commit comments

Comments
 (0)