File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -182,6 +182,18 @@ const MyWidgetsPage = () => {
182
182
noAccess : true ,
183
183
} )
184
184
}
185
+ } else if ( state . pendingWidgetHash && widgetList . page == widgetList . totalPages ) {
186
+ // special case to handle widget copy behavior
187
+ // because state.widgetHash and widgetList.instances are both updated concurrently, race conditions could occur
188
+ // to resolve this, set a special flag that's addressed AFTER the instance list is re-fetched
189
+ // widgetHash is updated only once widgetList.instances is fully populated
190
+ // unfortunately this is less responsive than the normal loading of instances, but oh well
191
+ let hash = state . pendingWidgetHash
192
+ let { pendingWidgetHash, ...stateCopy } = state
193
+ setState ( {
194
+ ...stateCopy ,
195
+ widgetHash : hash
196
+ } )
185
197
}
186
198
} , [ widgetList . instances , state . widgetHash ] )
187
199
@@ -246,11 +258,13 @@ const MyWidgetsPage = () => {
246
258
{
247
259
// Still waiting on the widget list to refresh, return to a 'loading' state and indicate a post-fetch change is coming.
248
260
onSettled : newInstId => {
249
- // Setting selectedInst to null again to avoid race conditions.
261
+ // race conditions require we reset selectedInst and widgetHash to null prior to updating those values
262
+ // instead, pendingWidgetHash will be used to update widgetHash once the instance list has fully reloaded
250
263
setState ( {
251
264
...state ,
252
265
selectedInst : null ,
253
- widgetHash : newInstId
266
+ widgetHash : null ,
267
+ pendingWidgetHash : newInstId
254
268
} )
255
269
256
270
setWidgetList ( {
You can’t perform that action at this time.
0 commit comments