{"record":{"id":"ce27516e5074886c","repo":"siyuan-note/siyuan","slug":"inline-styles-count-exceeds-the-d-item-limit","errorCode":null,"errorMessage":"inline styles count exceeds the %d item limit","messagePattern":"inline styles count exceeds the (.+?) item limit","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":645,"sourceCode":"\thidden := map[int]struct{}{}\n\tfor _, index := range styles.Builtin.Hidden.AV {\n\t\thidden[index] = struct{}{}\n\t}\n\tret := make([]int, 0, neutralAVColorIndex)\n\tfor index := minBuiltinColorIndex; index <= neutralAVColorIndex; index++ {\n\t\tif _, ok := hidden[index]; !ok {\n\t\t\tret = append(ret, index)\n\t\t}\n\t}\n\tif len(ret) == 0 {\n\t\treturn []int{neutralAVColorIndex}\n\t}\n\treturn ret\n}\n\nfunc normalizeInlineStyles(styles []*InlineStyle, generateIDs bool) (ret []*InlineStyle, err error) {\n\tif maxInlineStyles < len(styles) {\n\t\treturn nil, fmt.Errorf(\"inline styles count exceeds the %d item limit\", maxInlineStyles)\n\t}\n\tret = make([]*InlineStyle, 0, len(styles))\n\tids := make(map[string]struct{}, len(styles))\n\tfor _, style := range styles {\n\t\tif style == nil {\n\t\t\treturn nil, errors.New(\"inline style must not be null\")\n\t\t}\n\n\t\tid := strings.TrimSpace(style.ID)\n\t\tif id == \"\" && generateIDs {\n\t\t\tfor {\n\t\t\t\tid = ast.NewNodeID()\n\t\t\t\tif _, exists := ids[id]; !exists {\n\t\t\t\t\tbreak\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif !ast.IsNodeIDPattern(id) {","sourceCodeStart":627,"sourceCodeEnd":663,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/inline_style.go#L627-L663","documentation":"normalizeInlineStyles enforces a maximum number of custom inline styles (maxInlineStyles). When the supplied styles array is longer, the kernel rejects it rather than truncating. It is raised both when loading a file with too many entries and when saving (setInlineStylesData) with too many submitted styles.","triggerScenarios":"Calling SetInlineStyles/SetInlineStylesData with a styles array exceeding maxInlineStyles, or loading an inline styles file that contains more than the limit.","commonSituations":"Importing a styles collection from another workspace, a sync/merge bug duplicating entries, or scripted bulk generation of custom styles.","solutions":["Reduce the styles array to at most maxInlineStyles entries before saving","Deduplicate identical styles (same id/colors) to cut the count","Split rarely used styles out and delete the file if regeneration from defaults is acceptable"],"exampleFix":"// before: POST SetInlineStylesData with styles.length > maxInlineStyles\n{\"styles\": [ ...1000 items... ]}\n// after\n{\"styles\": styles.slice(0, maxInlineStyles)}","handlingStrategy":"validation","validationCode":"if (styles.length > maxInlineStyles) {\n  styles = dedupeById(styles).slice(0, maxInlineStyles);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await fetchPost('/api/attr/setInlineStylesData', {styles});\n} catch (e) {\n  if (String(e).includes('count exceeds')) {\n    logging.warn('too many inline styles; trim the list before saving');\n  }\n}","preventionTips":["Check style count before bulk import","Deduplicate styles with identical colors before saving","Prune unused custom styles periodically"],"tags":["limit","inline-styles","validation"],"backgroundTag":"value-out-of-range","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}