{"record":{"id":"e89e2d72018ed01f","repo":"siyuan-note/siyuan","slug":"s-must-use-the-same-fields-in-light-and-dark-them","errorCode":null,"errorMessage":"%s must use the same fields in light and dark themes","messagePattern":"(.+?) 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":807,"sourceCode":"\nfunc normalizeInlineStyleThemePair(light, dark *InlineStyleTheme, description string) (normalizedLight,\n\tnormalizedDark *InlineStyleTheme, err error) {\n\tif light == nil || dark == nil {\n\t\treturn nil, nil, fmt.Errorf(\"%s must define light and dark themes\", description)\n\t}\n\tif normalizedLight, err = normalizeInlineStyleTheme(light); err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"invalid light theme of %s: %w\", description, err)\n\t}\n\tif normalizedDark, err = normalizeInlineStyleTheme(dark); err != nil {\n\t\treturn nil, nil, fmt.Errorf(\"invalid dark theme of %s: %w\", description, err)\n\t}\n\tlightColor, lightBackground := normalizedLight.Color != \"\", normalizedLight.BackgroundColor != \"\"\n\tdarkColor, darkBackground := normalizedDark.Color != \"\", normalizedDark.BackgroundColor != \"\"\n\tif !lightColor && !lightBackground {\n\t\treturn nil, nil, fmt.Errorf(\"%s must define color or backgroundColor\", description)\n\t}\n\tif lightColor != darkColor || lightBackground != darkBackground {\n\t\treturn nil, nil, fmt.Errorf(\"%s must use the same fields in light and dark themes\", description)\n\t}\n\treturn normalizedLight, normalizedDark, nil\n}\n\nfunc normalizeHiddenBuiltinColorIndexes(indexes []int, field string) (ret []int, err error) {\n\tret = make([]int, 0, len(indexes))\n\tseen := make(map[int]struct{}, len(indexes))\n\tmaxIndex := maxBuiltinColorIndex\n\tif field == \"av\" {\n\t\tmaxIndex = neutralAVColorIndex\n\t}\n\tfor _, index := range indexes {\n\t\tif index < minBuiltinColorIndex || maxIndex < index {\n\t\t\treturn nil, fmt.Errorf(\"hidden builtin %s index [%d] must be between %d and %d\", field, index,\n\t\t\t\tminBuiltinColorIndex, maxIndex)\n\t\t}\n\t\tif _, exists := seen[index]; exists {\n\t\t\tcontinue","sourceCodeStart":789,"sourceCodeEnd":825,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/model/inline_style.go#L789-L825","documentation":"When saving an inline style theme that supports both light and dark variants, both variants must populate the same set of fields: either both define color, or both define backgroundColor, or both define both. This validation in normalizeInlineStyleThemes rejects a pair where one variant sets a field the other omits, because rendering would have no dark-mode counterpart for a styled field.","triggerScenarios":"Calling the inline style theme configuration API (e.g. saving custom style settings that pass an InlineStyleTheme pair) with e.g. light={color:'#ff0000'} and dark={backgroundColor:'#00ff00'} — one variant uses color, the other uses backgroundColor; or light defines both fields while dark defines only one.","commonSituations":"Hand-editing the appearance/style configuration JSON or constructing the theme payload programmatically and filling only the light variant; a frontend or plugin sending a partially filled dark theme; migrating older config that only had light colors into a format that now requires dark values.","solutions":["Set the same fields on both light and dark variants: if the light theme defines color, the dark theme must also define color (and likewise for backgroundColor)","If a dark value is not known, explicitly set the field to an empty string on both variants rather than defining it on only one","Reorder fields so both variants consistently use color, or consistently use backgroundColor, instead of mixing"],"exampleFix":"// before\nlight:  {color: \"#ff0000\"}\ndark:   {backgroundColor: \"#330000\"}\n// after\nlight:  {color: \"#ff0000\"}\ndark:   {color: \"#ff5555\"}","handlingStrategy":"validation","validationCode":"function validInlineStylePair(light, dark) {\n  const fields = t => (t.color ? 1 : 0) + (t.backgroundColor ? 1 : 0);\n  return fields(light) > 0 && fields(light) === fields(dark);\n}","typeGuard":"const isTheme = t => t && typeof t === \"object\" && typeof t.color === \"string\" && typeof t.backgroundColor === \"string\";","tryCatchPattern":null,"preventionTips":["Always fill both light and dark variants together in one code path","Use empty strings, not omitted fields, for unset color/background","Mirror the field structure of both variants from a single template object"],"tags":["configuration","validation","inline-style","theme"],"backgroundTag":"schema-validation-failed","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"}