Skip to content

Commit f7ab65f

Browse files
committed
fix: handle state change with identical or missing currentWidgetId
The pi exhibited an issue where a current widget could become stuck and never continue to the next widget. It seems to be caused by clicking on the current widget in the tab. Added some logging in case there are other edge cases.
1 parent 80bd084 commit f7ab65f

File tree

1 file changed

+31
-16
lines changed

1 file changed

+31
-16
lines changed

app/javascript/components/widget-controller.jsx

Lines changed: 31 additions & 16 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 = () => {
@@ -139,12 +150,16 @@ export class WidgetController extends React.Component {
139150
};
140151

141152
switchToPage = id => {
142-
this.setState({
143-
currentWidgetId: id,
144-
nextWidgetId: null,
145-
prevWidgetId: null,
146-
transitionTime: null,
147-
});
153+
this.setState(({ currentWidgetId }) =>
154+
currentWidgetId !== id
155+
? {
156+
currentWidgetId: id,
157+
nextWidgetId: null,
158+
prevWidgetId: null,
159+
transitionTime: null,
160+
}
161+
: {},
162+
);
148163
};
149164

150165
handleClicks = ({ target }) => {

0 commit comments

Comments
 (0)