{"record":{"id":"4159c08f76ab64c6","repo":"plotly/plotly.js","slug":"bad-argument-to-arraydefaultkey-name","errorCode":null,"errorMessage":"bad argument to arrayDefaultKey: <name>","messagePattern":"bad argument to arrayDefaultKey: <name>","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/plot_api/plot_template.js","lineNumber":233,"sourceCode":"            }\n        }\n        return out;\n    }\n\n    return {\n        newItem: newItem,\n        defaultItems: defaultItems\n    };\n};\n\nfunction validItemName(name) {\n    return name && typeof name === 'string';\n}\n\nfunction arrayDefaultKey(name) {\n    var lastChar = name.length - 1;\n    if(name.charAt(lastChar) !== 's') {\n        Lib.warn('bad argument to arrayDefaultKey: ' + name);\n    }\n    return name.slice(0, -1) + 'defaults';\n}\nexports.arrayDefaultKey = arrayDefaultKey;\n\n/**\n * arrayEditor: helper for editing array items that may have come from\n *     template defaults (in which case they will not exist in the input yet)\n *\n * @param {object} parentIn: the input container (eg gd.layout)\n * @param {string} containerStr: the attribute string for the container inside\n *     `parentIn`.\n * @param {object} itemOut: the _full* item (eg gd._fullLayout.annotations[0])\n *     that we'll be editing. Assumed to have been created by `arrayTemplater`.\n *\n * @returns {object}: {modifyBase, modifyItem, getUpdateObj, applyUpdate}, all functions:\n *     modifyBase(attr, value): Add an update that's *not* related to the item.\n *         `attr` is the full attribute string.","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/plotly/plotly.js/blob/1d090e0b5ffb8d0fdf6e0e4ff51d3f3cf67f1314/src/plot_api/plot_template.js#L215-L251","documentation":"arrayDefaultKey(name) derives a plural-to-singular defaults key (e.g. 'annotations' -> 'annotationdefaults') by chopping the last character. It warns when the given name does not end in 's', because the result would almost certainly not be the intended defaults attribute name. This is an internal template/defaults helper, so the warning usually points at schema/attribute wiring, not user layout code.","triggerScenarios":"Calling arrayDefaultKey with a name that does not end in 's', e.g. arrayDefaultKey('shape') or arrayDefaultKey('layout'), typically from a custom template or defaults code (defaultsTemplate) registering an array container whose plural name is misformed.","commonSituations":"Authors of custom trace/layout templates or plugins wiring new array containers; typos in container names inside defaults template code.","solutions":["Pass the plural attribute name ending in 's', e.g. arrayDefaultKey('annotations') -> 'annotationdefaults'.","Fix the container name in your defaultsTemplate wiring so it is the standard plural form used in the plot schema.","If the container genuinely has no plural form, do not use arrayDefaultKey; provide the defaults key explicitly."],"exampleFix":"// before\narrayDefaultKey('annotation');\n// after\narrayDefaultKey('annotations'); // -> 'annotationdefaults'","handlingStrategy":"validation","validationCode":"function checkPluralName(name) {\n  if (typeof name !== 'string' || !name.endsWith('s')) throw new Error(`arrayDefaultKey expects a plural name ending in 's', got: ${name}`);\n  return name;\n}\narrayDefaultKey(checkPluralName('annotations'));","typeGuard":"const isPluralString = (n) => typeof n === 'string' && n.length > 0 && n.endsWith('s');","tryCatchPattern":null,"preventionTips":["Pass the standard schema plural names (annotations, shapes, images, etc.).","Double-check container names when wiring custom defaults templates.","Do not reuse arrayDefaultKey for non-plural containers.","Add an assertion in your template code during development."],"tags":["internal-api","template","schema"],"backgroundTag":"invalid-argument-name","analyzedSha":"1d090e0b5ffb8d0fdf6e0e4ff51d3f3cf67f1314","analyzedAt":"2026-09-02T22:03:39.906Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-10T02:17:09.455Z"}