diff --git a/frontend/silk-foundation/src/jsMain/kotlin/com/varabyte/kobweb/silk/theme/SilkTheme.kt b/frontend/silk-foundation/src/jsMain/kotlin/com/varabyte/kobweb/silk/theme/SilkTheme.kt index 252b367ea..b9a588420 100644 --- a/frontend/silk-foundation/src/jsMain/kotlin/com/varabyte/kobweb/silk/theme/SilkTheme.kt +++ b/frontend/silk-foundation/src/jsMain/kotlin/com/varabyte/kobweb/silk/theme/SilkTheme.kt @@ -107,8 +107,10 @@ class MutableSilkTheme { RestrictedKind::class -> SilkLayer.RESTRICTED_STYLES GeneralKind::class -> SilkLayer.GENERAL_STYLES else -> error("Unknown kind: $kind") - }.layerName.takeIf { it.isNotEmpty() } // In case user passes in "" - finalLayer?.let { _cssLayersFor[name] = it } + }.layerName + finalLayer + .takeIf { it.isNotEmpty() } // If the user passes in "", no layer should be registered + ?.let { _cssLayersFor[name] = it } if (style is ExtendingCssStyle) { _cssStyleDependencies.getOrPut(style) { mutableListOf() }.add(style.baseStyle) diff --git a/frontend/silk-foundation/src/jsTest/kotlin/com/varabyte/kobweb/silk/CssStyleTest.kt b/frontend/silk-foundation/src/jsTest/kotlin/com/varabyte/kobweb/silk/CssStyleTest.kt index a199cc310..fba6e65c6 100644 --- a/frontend/silk-foundation/src/jsTest/kotlin/com/varabyte/kobweb/silk/CssStyleTest.kt +++ b/frontend/silk-foundation/src/jsTest/kotlin/com/varabyte/kobweb/silk/CssStyleTest.kt @@ -73,6 +73,21 @@ class CssStyleTest { .inOrder() } + + @Test + fun cssStyleEmptyLayerNameResultsInNoLayer() { + val stylesheet = StyleSheet() + // Styles must be non-empty to be registered + val BaseStyle = CssStyle.base { Modifier.color(Colors.Red) } + _SilkTheme = MutableSilkTheme().apply { + registerStyle("base-style", BaseStyle, layer = "") + }.let(::ImmutableSilkTheme) + SilkTheme.registerStylesInto(stylesheet) + val styleRule = stylesheet.cssRules.first() + assertThat(styleRule).isInstanceOf() + assertThat(styleRule.header).isEqualTo(".base-style") + } + @Test fun cssStyleExtendedClasses() { val BaseStyle = CssStyle { }