Skip to content

Commit d70890e

Browse files
authored
Merge pull request #17541 from richard-cox/fix-load-race
Improve race conditions around detail/edit page --> list transitions
2 parents 4758d77 + 2035448 commit d70890e

3 files changed

Lines changed: 30 additions & 4 deletions

File tree

shell/plugins/dashboard-store/actions.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,11 +697,23 @@ export default {
697697
}
698698
}
699699

700+
const havePage = getters.havePage(type);
701+
700702
opt = opt || {};
701703
opt.url = getters.urlFor(type, id, opt);
702704

703705
const res = await dispatch('request', { opt, type });
704706

707+
if (!havePage && getters.havePage(type)) {
708+
// There may be a super edge case where list --> detail (whilst loading) --> list navigation causes the list's rows to disappear
709+
// Somehow the `findPage` from the list page returns before the `find`. The `find` then clears the page state in the cache.
710+
// If this has happened silently return (we don't care about result)
711+
// https://github.com/rancher/dashboard/issues/17524
712+
console.warn(`Prevented \`find\` action from polluting cache for type "${ type }" (currently represents a page).`); // eslint-disable-line no-console
713+
714+
return;
715+
}
716+
705717
if (!opt.transient) {
706718
await dispatch('load', { data: res, invalidatePageCache: opt.invalidatePageCache });
707719
}

shell/plugins/steve/__tests__/subscribe.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ describe('steve: subscribe', () => {
343343

344344
// call watch
345345
actions.watch({
346-
state, dispatch, getters, rootGetters
346+
state, dispatch, getters, rootGetters, commit
347347
}, {
348348
...obj,
349349
revision,
@@ -488,6 +488,7 @@ describe('steve: subscribe', () => {
488488
const state = {
489489
started: [],
490490
inError: {},
491+
queue: [],
491492
listenerManager: new SteveWatchEventListenerManager()
492493
};
493494
const _getters = {

shell/plugins/steve/subscribe.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ const sharedActions = {
553553
* @param {STEVE_WATCH_PARAMS} params
554554
*/
555555
watch({
556-
state, dispatch, getters, rootGetters
556+
state, dispatch, getters, rootGetters, commit
557557
}, params) {
558558
state.debugSocket && console.info(`Watch Request [${ getters.storeName }]`, JSON.stringify(params)); // eslint-disable-line no-console
559559
let {
@@ -620,6 +620,9 @@ const sharedActions = {
620620
if (debounceMs) {
621621
msg.debounceMs = debounceMs;
622622
}
623+
624+
// Anything in the queue will pollute the result set, so clear (and print to console so we know it's working)
625+
commit('clearFromQueue', { type, log: true });
623626
}
624627
}
625628

@@ -1556,10 +1559,20 @@ const defaultMutations = {
15561559
state.socketListenerManager = new SteveWatchEventListenerManager(state.config.namespace);
15571560
},
15581561

1559-
clearFromQueue(state, type) {
1562+
clearFromQueue(state, args) {
1563+
const safeArgs = typeof args === 'object' ? args : { type: args };
1564+
const { type, log } = safeArgs;
1565+
15601566
// Remove anything in the queue that is a resource update for the given type
15611567
state.queue = state.queue.filter((item) => {
1562-
return item.body?.type !== type;
1568+
const keep = item.body?.type !== type;
1569+
1570+
if (!keep && log) {
1571+
// eslint-disable-next-line no-console
1572+
console.info(`Clearing queued item of type \`${ type }\` from queue`, item);
1573+
}
1574+
1575+
return keep;
15631576
});
15641577
},
15651578
};

0 commit comments

Comments
 (0)