{"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":"validation","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/9f775e8a12daef8255556097396f9b2739078892/kernel/model/inline_style.go#L678-L714","documentation":"Light and dark themes must use the SAME property set: either both define Color, or both define BackgroundColor (or both define both). Mixed usage — e.g. light uses Color while dark uses only BackgroundColor — would make the styled span's appearance property change with the theme, so normalizeInlineStyles rejects the whole save/load.","triggerScenarios":"Calling model.SetInlineStyles / model.SetInlineStylesData with Light{Color: X} and Dark{BackgroundColor: Y}; clearing one property in one theme while keeping it in the other; JSON config where one theme's field was deleted or renamed; copying a color into the wrong field (Color vs BackgroundColor) for one theme.","commonSituations":"Designing a dark mode variant as \"background highlight instead of text color\" (a common style instinct, but not allowed per style); a merge that dropped a field from one theme; a UI bug resetting one picker but not the other.","solutions":["Set the same field(s) on both themes: give dark its own Color if light uses Color","To visually adapt for dark mode, change the VALUE (e.g. light Color #111 -> dark Color #eee), not the field","Keep both Color and BackgroundColor on both themes if the style uses both","Validate parity client-side: hasColor(light)==hasColor(dark) && hasBg(light)==hasBg(dark) before calling the API"],"exampleFix":"// before\nLight: &InlineStyleTheme{Color: \"#c00\"},\nDark:  &InlineStyleTheme{BackgroundColor: \"#3a2b2b\"} // different field\n// -> inline style [id] must use the same fields in light and dark themes\n// after\nLight: &InlineStyleTheme{Color: \"#c00\"},\nDark:  &InlineStyleTheme{Color: \"#ff8a8a\"} // same field, dark-appropriate value","handlingStrategy":"validation","validationCode":"func themesUseSameFields(l, d *InlineStyleTheme) bool {\n\tlc, lb := l.Color != \"\", l.BackgroundColor != \"\"\n\tdc, db := d.Color != \"\", d.BackgroundColor != \"\"\n\treturn lc == dc && lb == db\n}","typeGuard":null,"tryCatchPattern":"if _, _, err := model.SetInlineStylesData(cfg); err != nil {\n\tif strings.Contains(err.Error(), \"must use the same fields\") {\n\t\t// mirror field usage across themes and retry\n\t}\n\treturn err\n}","preventionTips":["Always build light and dark themes from one template so field usage stays in sync","Adapt dark mode by changing color VALUES, never by switching Color<->BackgroundColor","Validate field parity client-side before each save"],"tags":["go","validation","consistency","themes"],"backgroundTag":"conflicting-config-options","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"}