-
Notifications
You must be signed in to change notification settings - Fork 80
Open
Description
Problem
When there is an item set in a collection in Onyx, and Onyx.update is called with two merge updates where the first sets the collection item to null in order to remove it, and the second one sets a property of the object to null, then the item remains unchanged in the collection when it should be set to an empty object.
Please see the related App issue for more context.
Issue example
// Given we have a report action to set into Onyx
window.Onyx.set('reportActions_8865516015258724', {
'5738984309614092595': {
reportActionID: '5738984309614092595',
someKey: 'someValue',
},
});
const queuedUpdates = [
{
key: 'reportActions_8865516015258724',
onyxMethod: 'merge',
value: {
'5738984309614092595': null,
},
},
{
onyxMethod: 'merge',
key: 'reportActions_8865516015258724',
value: {
'5738984309614092595': {
pendingAction: null,
},
},
},
];
window.Onyx.update(queuedUpdates);
// Then the object under the key 5738984309614092595 in the collection reportActions_8865516015258724, should be set to an empty object, but it's actually set to the original value.
window.Onyx.get('reportActions_8865516015258724').then((val) => console.log('Result after updates', val['5738984309614092595']));
Proof that setting an action to an empty object will remove it from the UI in Expensify/App
// Get actions from a report. Replace the id (8865516015258724) with the reportID you want to test.
window.Onyx.get('reportActions_8865516015258724').then((val) => {
const actionsArray = Object.values(val);
actionsArray.sort((a, b) => new Date(a.created) - new Date(b.created));
// Replace the most recent action with an empty object
const replacedActionID = actionsArray[actionsArray.length - 1].reportActionID;
actionsArray[actionsArray.length - 1] = {};
const sortedActions = actionsArray.reduce((acc, action) => {
acc[action.reportActionID ?? replacedActionID] = action;
return acc;
}, {});
console.log('console test sortedActions', sortedActions);
// Set the new collection into Onyx
window.Onyx.set('reportActions_8865516015258724', sortedActions);
// You should see that the most recent action is removed from the UI
});
Solution
Find the root cause and fix it.
Metadata
Metadata
Assignees
Labels
No labels