{"record":{"id":"9ff6c9ee33650133","repo":"GrapesJS/grapesjs","slug":"selector-manager-not-found","errorCode":null,"errorMessage":"Selector Manager not found","messagePattern":"Selector Manager not found","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"packages/core/src/css_composer/index.ts","lineNumber":323,"sourceCode":"   */\n  addCollection(data: string | CssRuleJSON[], opts: AddCollectionOptions = {}, props = {}) {\n    const { em } = this;\n    const result: CssRule[] = [];\n    const parsedImportOpts: AddCollectionOptions = { ...opts, parsedImportSource: 'css' as const };\n\n    if (isString(data)) {\n      data = em.Parser.parseCss(data);\n      opts = parsedImportOpts;\n    }\n\n    const d = data instanceof Array ? data : [data];\n\n    for (var i = 0, l = d.length; i < l; i++) {\n      const rule = (d[i] || {}) as CssRuleJSON;\n      if (!rule.selectors) continue;\n\n      const sm = em?.Selectors;\n      if (!sm) console.warn('Selector Manager not found');\n      const sl = rule.selectors;\n      const sels = sl instanceof Array ? sl : [sl];\n      const newSels = [];\n\n      for (let j = 0, le = sels.length; j < le; j++) {\n        // @ts-ignore\n        const selec = sm.add(sels[j]);\n        newSels.push(selec);\n      }\n\n      const modelExists = this.get(newSels, rule.state, rule.mediaText, rule);\n      const model = this.add(newSels, rule.state, rule.mediaText, rule, opts);\n      const updateStyle = !modelExists || !opts.avoidUpdateStyle;\n      const style = rule.style || {};\n\n      isObject(props) && model.set(props, opts);\n\n      if (updateStyle) {","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/GrapesJS/grapesjs/blob/2bdeda85b82b8b9ceae42fd6558cbbcae5ec2d21/packages/core/src/css_composer/index.ts#L305-L341","documentation":"When loading CSS rules via the CSS composer (addCollection/addRules), each rule's selectors must be resolved against the editor's Selector Manager (em?.Selectors). If the EditorModel (em) is missing or has no Selectors module, the library cannot create/attach selectors for the rule and only logs this warning instead of throwing, so the rule is added without proper selector handling.","triggerScenarios":"Calling editor.Css.addCollection(rules) or addRules(rules) before the editor has fully initialized its module manager, or on a partially constructed / headless editor instance where em is undefined or em.Selectors was not created.","commonSituations":"Invoking CSS-loading APIs immediately after editor construction but before the 'load'/'ready' event; destroying the editor and reusing stale references; custom builds where the Selector Manager module was removed or initialization failed silently.","solutions":["Wait for editor initialization (editor.on('load') / await editor.ready) before calling addCollection or addRules","Pass the editor instance's em correctly — ensure addRules is called on editor.Css, not on a detached CssComposer constructed without an editor model","Check that em?.Selectors exists at runtime; if null, re-initialize the editor rather than continuing","Upgrade to a version where CssComposer is always constructed with the editor model (em) reference"],"exampleFix":"// before\neditor.Css.addCollection(rules); // may run before Selectors is ready\n// after\neditor.on('load', () => editor.Css.addCollection(rules));","handlingStrategy":"validation","validationCode":"if (!editor || !editor.em || !editor.em.Selectors) {\n  throw new Error('Editor Selector Manager not ready; cannot load CSS rules yet');\n}\neditor.Css.addCollection(rules);","typeGuard":"function isSelectorManagerReady(ed: any): ed is { em: { Selectors: object } } {\n  return !!ed && !!ed.em && !!ed.em.Selectors;\n}","tryCatchPattern":null,"preventionTips":["Load CSS rules only after the editor 'load'/'ready' event","Keep a single reference to the editor instance; never reuse destroyed editors","Assert em.Selectors exists in dev builds before calling Css APIs"],"tags":["css","initialization","selectors","grapesjs"],"backgroundTag":"selector-manager-not-initialized","analyzedSha":"2bdeda85b82b8b9ceae42fd6558cbbcae5ec2d21","analyzedAt":"2026-08-30T11:47:52.267Z","schemaVersion":2},"datasetVersion":"2026-08-30T13:17:10.514Z"}