Skip to content

An open source design system that's fully customizable and agent ready

TypeScript

fix(cli): strip astryx- (not stale xds-) prefix for theme override keys (#3527)

Aldo Ryandaa18ca6b7f982
diff --git a/.changeset/cli-theming-override-key-prefix.md b/.changeset/cli-theming-override-key-prefix.md
new file mode 100644
index 0000000000..8bb016a546
--- /dev/null
+++ b/.changeset/cli-theming-override-key-prefix.md
@@ -0,0 +1,6 @@
+---
+'@astryxdesign/cli': patch
+---
+
+[fix] `astryx component <Name>` now prints the correct `defineTheme` component-override key. The theming example stripped a stale `xds-` prefix (left over from the astryx rename) instead of `astryx-`, so it advertised keys like `astryx-base-table` / `astryx-button`. Those double-prefix to `.astryx-astryx-*` selectors at runtime and silently match nothing. Keys are now the stable class name minus `astryx-` (e.g. `base-table`, `button`), which is what `generateThemeRules` expects (#3458).
+@ryanda9910
diff --git a/packages/cli/src/lib/component-format.mjs b/packages/cli/src/lib/component-format.mjs
index e82a403757..78a28f70de 100644
--- a/packages/cli/src/lib/component-format.mjs
+++ b/packages/cli/src/lib/component-format.mjs
@@ -7,9 +7,20 @@
import {discoverComponents, findComponentReadme, resolveImportPath} from './component-discovery.mjs';
import {loadDocs} from './component-loader.mjs';
-/** Derive the theme component key from a theming target (strips 'xds-' prefix). */
+/**
+ * Derive the `defineTheme` component-override key from a theming target.
+ *
+ * Override keys are the component's stable class name with the `astryx-`
+ * namespace prefix stripped — `generateThemeRules` re-adds the prefix when it
+ * builds the `.astryx-*` selector. So `astryx-base-table` → key `base-table`
+ * (→ `.astryx-base-table`), and `astryx-button` → key `button`.
+ *
+ * Keep the `astryx-` literal in sync with packages/core/src/naming.ts
+ * (NAMESPACE / classPrefix), the same way build-theme.mjs mirrors it.
+ * <!-- SYNC: packages/core/src/naming.ts (namespace prefix source of truth) -->
+ */
function targetKey(target) {
- return target.className.replace(/^xds-/, '');
+ return target.className.replace(/^astryx-/, '');
}
function dataAttrForName(name) {
diff --git a/packages/cli/src/lib/component-format.test.mjs b/packages/cli/src/lib/component-format.test.mjs
index 2ded2d2814..a997c2de84 100644
--- a/packages/cli/src/lib/component-format.test.mjs
+++ b/packages/cli/src/lib/component-format.test.mjs
@@ -51,3 +51,45 @@ describe('formatFull sub-component rendering', () => {
expect(out).not.toContain('astryx component XDSButtonGroup');
});
});
+
+describe('formatFull theming override keys', () => {
+ // Regression guard: the `defineTheme` component-override key is the stable
+ // class name with the `astryx-` prefix stripped — `generateThemeRules`
+ // re-adds the prefix to build the `.astryx-*` selector. targetKey() used to
+ // strip a dead `xds-` prefix (from before the astryx rename), so the printed
+ // example advertised `astryx-*` keys. Those double-prefix to
+ // `.astryx-astryx-*` at runtime and silently match nothing. See issue #3458.
+ it('prints override keys without the astryx- prefix (single-word component)', () => {
+ const docs = {
+ name: 'Button',
+ description: 'A button.',
+ theming: {targets: [{className: 'astryx-button', visualProps: ['variant']}]},
+ };
+ const out = formatFull(docs);
+
+ expect(out).toContain("'button': {");
+ // The full DOM class must not appear as an override key.
+ expect(out).not.toContain("'astryx-button': {");
+ });
+
+ it('prints override keys without the astryx- prefix (compound Table classes)', () => {
+ const docs = {
+ name: 'Table',
+ description: 'A table.',
+ theming: {
+ targets: [
+ {className: 'astryx-base-table'},
+ {className: 'astryx-table-cell'},
+ ],
+ },
+ };
+ const out = formatFull(docs);
+
+ // Correct keys: class name minus the astryx- prefix.
+ expect(out).toContain("'base-table': {");
+ expect(out).toContain("'table-cell': {");
+ // The verbatim DOM class names must not be advertised as override keys.
+ expect(out).not.toContain("'astryx-base-table': {");
+ expect(out).not.toContain("'astryx-table-cell': {");
+ });
+});