{"record":{"id":"8ee3d48804277ba6","repo":"ssssssss-team/spider-flow","slug":"overlays-may-not-be-stateful","errorCode":null,"errorMessage":"Overlays may not be stateful.","messagePattern":"Overlays may not be stateful\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"spider-flow-web/src/main/resources/static/js/codemirror/codemirror.js","lineNumber":8250,"sourceCode":"\n      getOption: function(option) {return this.options[option]},\n      getDoc: function() {return this.doc},\n\n      addKeyMap: function(map$$1, bottom) {\n        this.state.keyMaps[bottom ? \"push\" : \"unshift\"](getKeyMap(map$$1));\n      },\n      removeKeyMap: function(map$$1) {\n        var maps = this.state.keyMaps;\n        for (var i = 0; i < maps.length; ++i)\n          { if (maps[i] == map$$1 || maps[i].name == map$$1) {\n            maps.splice(i, 1);\n            return true\n          } }\n      },\n\n      addOverlay: methodOp(function(spec, options) {\n        var mode = spec.token ? spec : CodeMirror.getMode(this.options, spec);\n        if (mode.startState) { throw new Error(\"Overlays may not be stateful.\") }\n        insertSorted(this.state.overlays,\n                     {mode: mode, modeSpec: spec, opaque: options && options.opaque,\n                      priority: (options && options.priority) || 0},\n                     function (overlay) { return overlay.priority; });\n        this.state.modeGen++;\n        regChange(this);\n      }),\n      removeOverlay: methodOp(function(spec) {\n        var this$1 = this;\n\n        var overlays = this.state.overlays;\n        for (var i = 0; i < overlays.length; ++i) {\n          var cur = overlays[i].modeSpec;\n          if (cur == spec || typeof spec == \"string\" && cur.name == spec) {\n            overlays.splice(i, 1);\n            this$1.state.modeGen++;\n            regChange(this$1);\n            return","sourceCodeStart":8232,"sourceCodeEnd":8268,"githubUrl":"https://github.com/ssssssss-team/spider-flow/blob/c799cca99c7d064673dc79e6ef06a08bbc0e292d/spider-flow-web/src/main/resources/static/js/codemirror/codemirror.js#L8232-L8268","documentation":"Overlays re-tokenize the visible document on every render and must be stateless — a mode with startState() needs persistent state that overlays don't support. addOverlay throws if the resolved mode defines startState.","triggerScenarios":"cm.addOverlay({token: fn, startState: fn}) or addOverlay('someMode') / addOverlay({name: 'javascript'}) where the underlying mode is stateful (most C-like modes are).","commonSituations":"Trying to overlay a full language mode (e.g. 'xml', 'javascript') instead of a small stateless highlighter, or a custom overlay spec that copied a template including startState.","solutions":["Write a stateless overlay: a {token: function(stream){...}} spec without startState/copyState","If you need a stateful mode's highlighting, set it as the editor's main mode instead of an overlay","Strip startState from your overlay spec (track any needed flags with closures over plain variables only if they reset per token — state cannot persist)"],"exampleFix":"// before\ncm.addOverlay({name: \"javascript\"}); // stateful\n// after\ncm.addOverlay({\n  token: function(stream) {\n    if (stream.match(\"TODO\")) { return \"keyword\"; }\n    while (stream.next() != null) {}\n    return null;\n  }\n});","handlingStrategy":"validation","validationCode":"function canAddOverlay(cm, spec) {\n  var mode = spec.token ? spec : CodeMirror.getMode(cm.options, spec);\n  return !(mode && typeof mode.startState === \"function\");\n}\nif (!canAddOverlay(cm, spec)) throw new Error(\"Overlay spec must be stateless\");","typeGuard":"function isStatelessMode(mode) {\n  return mode && typeof mode.token === \"function\" && typeof mode.startState !== \"function\";\n}","tryCatchPattern":"try {\n  cm.addOverlay(spec);\n} catch (e) {\n  if (/stateful/.test(e.message)) {\n    cm.setOption(\"mode\", spec); // use as main mode instead\n  } else { throw e; }\n}","preventionTips":["Overlays only accept {token: fn} specs or modes without startState — don't pass full language mode names","Copy overlay templates carefully and delete startState/copyState/indent stubs","Need rich stateful highlighting? Set the mode via the 'mode' option, not addOverlay"],"tags":["codemirror","overlay","mode"],"backgroundTag":"invalid-argument-value","analyzedSha":"c799cca99c7d064673dc79e6ef06a08bbc0e292d","analyzedAt":"2026-09-08T13:47:08.225Z","contentChangedAt":"2026-09-08T13:47:08.225Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}