{"record":{"id":"4208e3bb72316f8a","repo":"siyuan-note/siyuan","slug":"inline-style-s-must-use-the-same-fields-in-ligh","errorCode":null,"errorMessage":"inline style [%s] must use the same fields in light and dark themes","messagePattern":"inline style \\[(.+?)\\] must use the same fields in light and dark themes","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/model/inline_style.go","lineNumber":696,"sourceCode":"\t\tif style.Light == nil || style.Dark == nil {\n\t\t\treturn nil, fmt.Errorf(\"inline style [%s] must define light and dark themes\", id)\n\t\t}\n\n\t\tlight, err := normalizeInlineStyleTheme(style.Light)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid light theme of inline style [%s]: %w\", id, err)\n\t\t}\n\t\tdark, err := normalizeInlineStyleTheme(style.Dark)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid dark theme of inline style [%s]: %w\", id, err)\n\t\t}\n\t\tlightColor, lightBackground := light.Color != \"\", light.BackgroundColor != \"\"\n\t\tdarkColor, darkBackground := dark.Color != \"\", dark.BackgroundColor != \"\"\n\t\tif !lightColor && !lightBackground {\n\t\t\treturn nil, fmt.Errorf(\"inline style [%s] must define color or backgroundColor\", id)\n\t\t}\n\t\tif lightColor != darkColor || lightBackground != darkBackground {\n\t\t\treturn nil, fmt.Errorf(\"inline style [%s] must use the same fields in light and dark themes\", id)\n\t\t}\n\n\t\tret = append(ret, &InlineStyle{ID: id, Name: name, Hidden: style.Hidden, Light: light, Dark: dark})\n\t}\n\treturn ret, nil\n}\n\nfunc normalizeInlineStyleBuiltin(builtin *InlineStyleBuiltin) (ret *InlineStyleBuiltin, err error) {\n\tret = newEmptyInlineStyleBuiltin()\n\tif builtin == nil {\n\t\treturn ret, nil\n\t}\n\n\tcolorIndexes := make(map[int]struct{}, len(builtin.Colors))\n\tfor _, color := range builtin.Colors {\n\t\tif color == nil {\n\t\t\treturn nil, errors.New(\"builtin color must not be null\")\n\t\t}","sourceCodeStart":678,"sourceCodeEnd":714,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/8641553a1f07374001902d3ce773285db1292b2d/kernel/model/inline_style.go#L678-L714","documentation":"Light and dark themes of one inline style must be field-symmetric: if light sets Color, dark must set Color too, and likewise for BackgroundColor (presence must match, though values may differ). Mixed field usage would make rendering inconsistent between color schemes, so normalization rejects the style.","triggerScenarios":"setInlineStylesData receives an InlineStyle where, e.g., Light sets only Color while Dark sets only BackgroundColor, or one theme sets both fields and the other only one; loadInlineStyles reads such an asymmetric entry from disk.","commonSituations":"Manually editing dark-mode JSON and changing which field is used; scripts generating dark themes by swapping roles (background-on-dark, color-on-light); copy-pasting theme objects and deleting a field in one of them.","solutions":["Make both themes use the same field(s): if light uses Color, set Color in dark as well (values may differ per mode).","Normalize programmatically: compute lightColor/lightBackground booleans and darkColor/darkBackground booleans and fix the dark entry to match before saving.","Rewrite the on-disk inline-styles JSON so the light and dark theme objects use identical field sets."],"exampleFix":"// before\nLight: &InlineStyleTheme{Color: \"#ff0000\"},\nDark:  &InlineStyleTheme{BackgroundColor: \"#3a2a2a\"} // field mismatch\n// after\nLight: &InlineStyleTheme{Color: \"#ff0000\"},\nDark:  &InlineStyleTheme{Color: \"#ff6b6b\"}","handlingStrategy":"validation","validationCode":"for (const s of styles) { const l = !!s.Light.Color, lb = !!s.Light.BackgroundColor, d = !!s.Dark.Color, db = !!s.Dark.BackgroundColor; if (l !== d || lb !== db) throw new Error(`style ${s.ID} uses different fields in light and dark themes`); }","typeGuard":"const themesAreFieldSymmetric = (s: InlineStyle): boolean => (!!s.Light.Color === !!s.Dark.Color) && (!!s.Light.BackgroundColor === !!s.Dark.BackgroundColor);","tryCatchPattern":"try { await saveStyles(styles) } catch (e) { if (/same fields in light and dark/.test(String(e))) { /* align the dark theme's field usage with light, then retry */ } }","preventionTips":["Build dark themes by cloning the light theme and changing only values, never field presence","Derive dark colors from light colors with a fixed transform in tooling","Add a symmetry assertion to any script that generates or migrates inline styles"],"tags":["validation","consistency","inline-styles","theming"],"backgroundTag":"conflicting-config-options","analyzedSha":"8641553a1f07374001902d3ce773285db1292b2d","analyzedAt":"2026-09-11T16:08:28.414Z","contentChangedAt":"2026-09-11T16:08:28.414Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}