{"record":{"id":"0598d5df826c953a","repo":"plotly/plotly.js","slug":"insertion-removal-are-incompatible-with-edits-to","errorCode":null,"errorMessage":"Insertion & removal are incompatible with edits to the same index.","messagePattern":"Insertion & removal are incompatible with edits to the same index\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/plot_api/manage_arrays.js","lineNumber":134,"sourceCode":"    var objVal;\n    var adding, prefix;\n\n    // first make the add and edit changes\n    for(i = 0; i < componentNums.length; i++) {\n        componentNum = componentNums[i];\n        objEdits = edits[componentNum];\n        objKeys = Object.keys(objEdits);\n        objVal = objEdits[''],\n        adding = isAddVal(objVal);\n\n        if(componentNum < 0 || componentNum > componentArray.length - (adding ? 0 : 1)) {\n            Loggers.warn('index out of range', componentType, componentNum);\n            continue;\n        }\n\n        if(objVal !== undefined) {\n            if(objKeys.length > 1) {\n                Loggers.warn(\n                    'Insertion & removal are incompatible with edits to the same index.',\n                    componentType, componentNum);\n            }\n\n            if(isRemoveVal(objVal)) {\n                deletes.push(componentNum);\n            } else if(adding) {\n                if(objVal === 'add') objVal = {};\n                componentArray.splice(componentNum, 0, objVal);\n                if(componentArrayFull) componentArrayFull.splice(componentNum, 0, {});\n            } else {\n                Loggers.warn('Unrecognized full object edit value',\n                    componentType, componentNum, objVal);\n            }\n\n            if(firstIndexChange === -1) firstIndexChange = componentNum;\n        } else {\n            for(j = 0; j < objKeys.length; j++) {","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/plotly/plotly.js/blob/1d090e0b5ffb8d0fdf6e0e4ff51d3f3cf67f1314/src/plot_api/manage_arrays.js#L116-L152","documentation":"In a per-index edit, the '' key is reserved for insertion (add value) or removal (remove value) of the object at that index. If the same index edit object also contains other property keys, Plotly warns that insertion/removal cannot be combined with property edits on the same index, and proceeds (insert/remove wins for '', other keys remain dubious).","triggerScenarios":"Building an edit like edits[2] = {'': null, text: 'new'} (remove plus edit) or {'': newObj, x: 5} (insert plus edit) in one relayout/React-style payload.","commonSituations":"Generic reducers that merge 'set value' and 'remove item' actions for the same array element, or edit builders that always attach the '' slot alongside collected property changes.","solutions":["Issue the remove/insert ('' key) and the property edits as separate operations on different indices or separate calls.","If the intent is replacement, either remove then insert, or edit the existing properties without the '' key.","Refactor edit-building code so '' is only present when the operation is purely add/remove.","Log and assert your edit objects in development to catch mixed '' + property payloads early."],"exampleFix":"// before\nedits[2] = { '': REMOVE, text: 'x' }; // mixed remove + edit\n// after\nedits[2] = { '': REMOVE }; // remove only\n// separately:\nedits[1] = { text: 'x' };","handlingStrategy":"validation","validationCode":"function assertNoMixedRemoveEdit(edits) {\n  for (const [idx, obj] of Object.entries(edits)) {\n    if (obj && '' in obj && Object.keys(obj).length > 1) {\n      throw new Error(`Index ${idx}: cannot combine insert/remove with property edits`);\n    }\n  }\n}","typeGuard":"function isPureAddOrRemove(objEdits) { return objEdits != null && (Object.keys(objEdits).length === 1 && '' in objEdits); }","tryCatchPattern":null,"preventionTips":["Keep the '' key exclusively for pure insert/remove operations.","Split combined operations into sequential calls (remove/insert, then edit).","Validate built edit payloads in development with assertNoMixedRemoveEdit."],"tags":["relayout","array-edits","api-misuse"],"backgroundTag":"incompatible-edit-combination","analyzedSha":"1d090e0b5ffb8d0fdf6e0e4ff51d3f3cf67f1314","analyzedAt":"2026-09-02T22:03:39.906Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}