Skip to content

Commit

Permalink
BUGFIX: Remove race condition in watchNodeInformationChanges
Browse files Browse the repository at this point in the history
By using the `takeLatest` higher-order saga, this changes makes sure
that all attempts at fetching additional node metadata are cancelled
once a new node-related action is triggered.

Without this stale `fetchAdditionalNodeMetadata` calls may corrupt the
in-memory node cache, which leads to further problems downstream.

This became apparent after #3756.
  • Loading branch information
grebaldi committed May 20, 2024
1 parent c9a48b5 commit 2a29d84
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions packages/neos-ui-sagas/src/CR/Policies/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {select, take, put, fork} from 'redux-saga/effects';
import {select, take, put, fork, takeLatest} from 'redux-saga/effects';

Check failure on line 1 in packages/neos-ui-sagas/src/CR/Policies/index.js

View workflow job for this annotation

GitHub Actions / Code style

'take' is defined but never used

import {actions, actionTypes, selectors} from '@neos-project/neos-ui-redux-store';
import backend from '@neos-project/neos-ui-backend-connector';
Expand All @@ -22,8 +22,7 @@ function * fetchAdditionalNodeMetadata(nodesWithoutAdditionalMetadata) {
}

export function * watchNodeInformationChanges() {
while (true) {
const action = yield take([actionTypes.CR.Nodes.MERGE, actionTypes.CR.Nodes.ADD, actionTypes.CR.Nodes.SET_STATE]);
yield takeLatest([actionTypes.CR.Nodes.MERGE, actionTypes.CR.Nodes.ADD, actionTypes.CR.Nodes.SET_STATE], function * (action) {
const nodeMap = (action.type === actionTypes.CR.Nodes.SET_STATE) ? action.payload.nodes : action.payload.nodeMap;
const state = yield select();

Expand All @@ -39,10 +38,10 @@ export function * watchNodeInformationChanges() {
});

if (nodesWithoutAdditionalMetadata.length === 0) {
continue;
return;
}

yield fork(fetchAdditionalNodeMetadata, nodesWithoutAdditionalMetadata);
}
});
}

0 comments on commit 2a29d84

Please sign in to comment.