Skip to content

feat(cli): built themes keep componentIcons slot functions - #9829

Merged
imdreamrunner merged 20 commits into
mainfrom
icons/ast087-slots-build-functions
Nov 5, 2026
Merged

imdreamrunner merged 20 commits into
mainfrom
icons/ast087-slots-build-functions

Conversation

@imdreamrunner

@imdreamrunner imdreamrunner commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Stack: #9828 → #9829. This PR carries slot functions in built themes; merge it right after #9828, which refuses them until then. The slots are specified by #10045, which merges first.

User need

#9828 lets a theme map a component's own icon role through defineTheme({componentIcons}). A slot function, such as ({copied}) => ({icon: copied ? 'checkDouble' : 'copy'}), is how a theme follows component state. Built themes (astryx theme build, and the ./built subpaths shipped themes expose) must resolve slots the same way as the source theme. With #9828 alone, a theme with a slot function fails the build. Theme authors who ship built themes need those functions carried.

Problem and solution fit

  • Function carrying. theme build traces each slot function to the import that supplies it, with the same static tracing that carries function icon entries. The built module imports the function from there. No authored source is evaluated or copied.
  • Static slots beside functions. Static values (names, null, requests) in an inline componentIcons object are written as JSON next to imported slots and spreads. A child can then add a static slot on top of a base's slot functions. An undefined slot is left out, so the inherited one stays, as in defineTheme.
  • Inherited slots. A built base module (followed through __componentIcons), a package theme (componentIcons and __componentIcons), and family members (the parent's values, then the member's own) all carry their slot functions.
  • Public read. The built theme's componentIcons is the static view computed from the carried values, so it reads back what the runtime theme's does (FR18, INV15). The view code reads no global and declares only reserved names, so an imported binding cannot shadow it.
  • Failure. A slot function defined in the theme file still fails the build with ERR_THEME_INVALID before anything is written (FR19). The error says to move it to its own module.

Current specification

  • architecture:theme-compilation: item 7 (a built theme carries componentIcons functions) and INV15 (built and runtime resolve slots alike; public views match).
  • architecture:icon-resolution-and-component-slots: theme build change coupling.
  • spec:AST-087: FR18 and FR19.

Public delta and caller burden

  • No API or type change. astryx theme build now succeeds for themes whose slot functions are imported; it failed for them before.
  • The built output gains __componentIcons beside componentIcons only when a slot value is a function. Themes without slot functions emit the same output as with feat(Icon): a theme maps a component's own icon role by slot, starting with CodeBlock's copy button #9828.
  • Caller burden: keep slot functions in their own module and import them into the theme file, as function icon entries already require. A per-slot import works too:
import {copySlot} from './slots.mjs';
export default defineTheme({
  name: 'brand',
  extends: baseTheme,
  componentIcons: {'code-block-copy': copySlot, 'table-sort-indicator': null},
});

Design and alternatives

  • resolveIconImports gains a field option (icons or componentIcons), so one tracer, with its mutation, cycle, and package-privacy checks, serves both fields. For componentIcons, an inline object may hold static values and per-slot references. Rejected: a second tracer, which would drift from the icon rules.
  • Family output carries a member's own slot functions only through a named import of the whole map, matching how family output takes icon registries. A member without one may still add static slots over its parent's functions.

Evidence

build.component-icons.test.mjs runs native Node over built and runtime themes:

  • A base with an imported slot map; a child with inline static slots, an imported per-slot function, and an undefined slot; a grandchild extending the BUILT child. Every slot resolves the same for each state, the static view matches, and CodeBlock's copy button renders the same.
  • Static-only slots write JSON with no import.
  • A package theme's slot functions are carried.
  • A family build with inherited slot functions.
  • Slot maps imported as slot and as Object load correctly.
  • An inline slot function, and a function beside a spread map, fail before writing.

All theme-build tests pass (38 files, 449 tests with doc quality and goldens). pnpm review:pre --base icons/ast087-slots-code-block: 838 authored lines, no findings.

Scope

  • One capability is added.
  • Unrelated fixes, cleanup, and policy changes were removed or split.
  • Consumer docs, focused tests, and migration evidence ship with the feature.
  • Public text and artifacts contain no internal Meta context.

Testing

  • pnpm vitest run --project node packages/cli/api/theme packages/cli/test/core-doc-quality.test.mjs packages/cli/test/experimental-isolation.test.mjs
  • CLI strict typecheck (tsc --project packages/cli/tsconfig.strict.json).

…g with CodeBlock's copy button

defineTheme({componentIcons}) maps a component icon slot to a shared icon
name, null, a partial {icon, variant, size} request, or a pure function of
the slot's state. One shared resolution applies caller content, then the
theme's slot, then the component's fallback, field by field, and ignores a
malformed field with one development warning. CodeBlock's copy button is the
first slot, code-block-copy, with state {copied}. The static view reads back
through theme.componentIcons; theme build carries static slot values and
fails on a slot function. Component docs, the CLI, and the docsite registry
list a component's slots.
@vercel

vercel Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
astryx Ready Ready Preview Nov 5, 2026 6:52pm UTC

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 3, 2026
@astracat-bot

astracat-bot Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Nov 5, 2026, 6:32 PM UTC

… values

DefinedTheme['componentIcons'] keeps the same shape as a Partial<Record>, so
documentation that names DefinedTheme does not have to enumerate every icon
name a slot may hold.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes. Built themes now carry imported slot functions and match runtime in the tested shapes, but three issues need fixing first.

  • The build merges {...base, ...own} while defineTheme skips undefined, so an undefined slot in an imported or spread componentIcons map erases the inherited slot in the built theme; for example, a child with childSlots = {'code-block-copy': undefined} renders CodeBlock's copy button with copy when built and clock at runtime.
  • The changeset and the theme-authoring doc say a slot function imported into the theme file is carried, but theme build --family rejects a member's per-slot import ('parity-copy-again': copySlot) and accepts only a named import of the whole map, so please document that rule (and fix the test comment that calls copySlot inline) or carry per-slot imports in family output.
  • A static request that uses a theme-file constant, such as {size: SIZE}, fails the build once any slot function is present, and the error blames slot functions; follow const bindings for static values or take them from the resolved theme.

Regression fixtures for the first and third cases would keep them fixed.

[Automated review]

const base = render(value.base);
const own = render(value.own);
return {
expression: `{...${base.expression}, ...${own.expression}}`,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This spread keeps an own undefined value. defineTheme's mergeComponentIcons skips such a value, so the inherited slot stays at runtime. Take childSlots = {'code-block-copy': undefined} over a base with copySlot: the built theme resolves copy, but the runtime theme resolves clock and checkDouble. For componentIcons, emit a merge that skips own undefined entries. Family output reaches the same spread through familyComponentIcons.

(node?.type === 'UnaryExpression' && node.operator === 'void')
)
return undefined;
if (node?.type !== 'ObjectExpression') return NOT_STATIC;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An identifier inside a static request (other than undefined) ends here as NOT_STATIC. So {size: SIZE} with const SIZE = 'xsm' fails the build once any slot function is present, and slotValue reports it as a slot function defined in the theme file. Follow const bindings here, as slotValue does, to carry it.

'@astryxdesign/cli': patch
---

[feat] `astryx theme build` keeps a theme's `componentIcons` slot functions. The built module imports each slot function from the module the theme source imports it from, writes static slot values beside it as JSON, and reads back the same static `componentIcons` view, so component icon slots resolve the same for the built theme as for the runtime theme. This includes slots inherited from a built, package, or family base. A slot function defined in the theme file still fails the build: move it to its own module and import it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In --family output, a member's own per-slot import ('parity-copy-again': copySlot) fails with "must supply componentIcons slot functions through a named import for family output". Please say that a family member supplies its own slot functions through a named import of its whole componentIcons map. The same applies to the new paragraph in author-a-theme.doc.mjs.

@imdreamrunner

Copy link
Copy Markdown
Contributor Author

Addressed in 4f67c8c:

  • undefined own slots: a theme's own slot values now merge over its base's through a generated function that skips an undefined slot, as defineTheme does. This covers an imported or spread map, and a family member's imported map. Inside one object, an undefined slot stays (void 0), as in the source. The static view also leaves out undefined slots. A built base module is read through its export, like a package theme, so its generated code is never traced.
  • Family rule: the changeset and author-a-theme now say that, in --family output, a member supplies its own slot functions through a named import of its whole componentIcons map. The test comment is corrected, and the family error message names the rule.
  • Constants in static requests: static values follow unmutated const bindings ({size: SIZE}, const DISMISS = {…}). A value that is neither static nor imported now gets an error that says so.

New regression fixtures: an imported child map with 'code-block-copy': undefined over a base slot function; const values in static requests beside a slot function; a spread followed by an undefined slot in one object; and a family member importing a map with an undefined slot. Without the fix, these fail.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes. The undefined merge and the family import rule are fixed, and built themes now match runtime in every tested shape, but one issue remains.

  • Once a theme has any slot function, a static request field that reads a constant other than a bare theme-file const, such as {size: SIZES.compact} or {size: COMPACT} imported from another module, fails theme build with an error that says to move the slot functions, although the same theme builds without a slot function; please carry those values (member access on unmutated constants, imported bindings as imports), scope the seen guard in staticValue to the current path, and word the error for a static value.

A smaller, non-blocking point: a root's inline undefined slot is kept as void 0 in __componentIcons, so a runtime theme that extends the built root lists that slot in its static componentIcons; passing a root's own values through the same merge would drop it.

[Automated review]

(node?.type === 'UnaryExpression' && node.operator === 'void')
)
return undefined;
if (node?.type !== 'ObjectExpression') return NOT_STATIC;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any request field other than a literal or a bare theme-file const ends here as NOT_STATIC. So {size: SIZES.compact} (local const SIZES), or {size: COMPACT} imported from another module, fails the build once a slot function is present, and the error says to move the slot functions. The same theme builds without a slot function. Follow member access on unmutated constants, carry imported bindings as imports (a whole imported slot value already works), and scope seen to the current path: a request that reads one constant twice also fails here.

…template's componentIcons example builds

The icon slot architecture record's baseline points to ComponentIconSlotMap
and each owning component's docs for Core's slots. The theme template's
componentIcons example is a static value, which astryx theme build carries.
theme build traces each slot function to the import that supplies it and
writes static slot values beside it as JSON, including slots inherited from
a built, package, or family base. The built module keeps the values as
__componentIcons and reads back the same static componentIcons view as the
runtime theme. A slot function defined in the theme file still fails the
build.
A theme's own componentIcons merge over its base's through a generated
function that skips an undefined slot, so an imported or family map that
leaves a slot undefined keeps the inherited one. Inside one object, an
undefined slot stays, as in the source. Static requests read unmutated
const bindings. A built base module is read through its export, like a
package theme. The docs say a family member supplies its own slot functions
through a named import of its whole map.
…rted values

A static slot value may read unmutated const bindings, member reads on them,
and imported bindings, which the module imports. The const guard is scoped
to the current path, so one constant read twice is carried. A root's own
slot values pass through the theme merge, so an undefined slot is dropped as
defineTheme drops it. A value that is neither static nor imported gets an
error that says so.
@imdreamrunner
imdreamrunner force-pushed the icons/ast087-slots-build-functions branch from 9742d22 to b012104 Compare November 4, 2026 00:33
@imdreamrunner

Copy link
Copy Markdown
Contributor Author

Second round, now rebased on #9828's latest head (#9829 head b012104):

  • Static values in requests: slot values are now carried as data. That covers JSON literals, unmutated const bindings and member reads on them (SIZES.compact, SIZES.icons.dismiss), and imported bindings, which the module imports ({size: COMPACT} from ./sizes.mjs). The const guard is scoped to the current path, so one constant read twice is carried.
  • Error wording: a function defined in the theme file gets "The slot function for X is defined in the theme file". Any other non-static value gets "The value for X is neither a static value nor an imported binding". The header no longer blames slot functions.
  • Root undefined slots: a root's own values pass through the same theme merge, so an undefined slot is dropped, and a runtime theme extending the built root reads the same static componentIcons keys.
  • The theme template's slot-function example is restored here, since this PR carries slot functions.

New fixtures cover: member reads and an imported constant in requests beside a slot function; one constant read by two slots; a computed value rejected with the new message; and a runtime child of the built root compared with a runtime child of the source root.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requesting changes. The earlier undefined-merge, family-rule and constant findings are fixed, and built themes written beside their source now match runtime in every tested shape; one issue remains.

  • With -o dist/theme.css, the recipe author-a-theme gives for shipping a built theme, the built module keeps the theme source's relative slot import, which --icons-specifier does not retarget, so it fails to load with ERR_MODULE_NOT_FOUND; please state that limit in the changeset and the componentIcons paragraph of author-a-theme (or carry slot imports through --out), and add an --out fixture that loads the built module.

Two smaller points do not block: the theme template's restored example writes the slot function inline, which theme build rejects, and a --family root that imports a map with an undefined slot keeps that key in __componentIcons, so a runtime theme extending it lists the slot in its static view.

[Automated review]

const componentIconPrelude =
carriesSlotFunctions && componentIconInfo
? componentIconInfo.imports
.map(binding => importStatement(binding))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With --out into another directory, this import keeps the theme source's relative specifier. dist/<theme>.js then imports ./slots from dist/ and fails with ERR_MODULE_NOT_FOUND; --icons-specifier rewrites only the registry import. Please document the limit (or carry slot imports through --out) and add a fixture that loads the built module from the output directory.

{type: 'prose', text: "A registry entry can be a function of `{size, variant}`. The built theme keeps the function, so `Icon` asks it for the size and variant it renders, as the runtime theme does, including for entries inherited from a built or package theme. The built theme's `icons` field and the registry its module re-exports are React nodes, with each function read at size `md`. A function written in the theme file itself cannot be carried, so the build fails; move it into the registry module."},
{type: 'prose', text: "A theme that lists `iconVariants` also writes an `IconVariantMap` augmentation into `<theme>.variants.d.ts`, so `Icon`'s `variant` accepts those names wherever the theme's types load. Its declaration carries the list too, so a theme that extends the built theme types `variant` in its icon entries by that list."},
{type: 'prose', text: "A built theme keeps its `componentIcons` names, `null` values, and static requests, so component slots resolve the same for the built theme as for the runtime theme. A slot function cannot be written into the module, so a theme with one fails the build: use a static value, or apply the source theme at runtime."},
{type: 'prose', text: "A built theme keeps its `componentIcons`. Names, `null` values, and static requests are written into the module. A slot function stays a function: the module imports it from the module the theme source imports it from, so component slots resolve the same for the built theme as for the runtime theme. The built theme's `componentIcons` field leaves out slot functions, as the runtime theme's does. A slot function defined in the theme file fails the build: move it to its own module and import it. In `--family` output, a member supplies its own slot functions through a named import of its whole `componentIcons` map."},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This paragraph follows the -o dist/theme.css recipe, but the slot import is written as the theme source spells it. It resolves from dist/ only when a module exists there under that specifier, and --icons-specifier does not change it. Please say so, as the registry paragraph does for icons.

Comment thread packages/cli/assets/theme.template.ts Outdated
* Reference: `astryx docs icons`; each component's docs list its slots.
*/
// componentIcons: {'code-block-copy': 'clock'},
// componentIcons: {'code-block-copy': ({copied}) => ({icon: copied ? 'checkDouble' : 'copy'})},

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-blocking: uncommented, this inline slot function fails astryx theme build with "The slot function for "code-block-copy" is defined in the theme file." An imported slot, with a note to keep it in its own module, would match author-a-theme.

…cs state the --out rule for slot imports

A family member's imported componentIcons map always passes through the
slot merge, so a root drops an undefined slot as defineTheme does. The
changeset and author-a-theme say that the module keeps each slot import as
the theme source spells it, which --icons-specifier does not change, so with
--out elsewhere a module must answer to it from the output directory. A
fixture builds with --out and loads the module. The theme template imports
its example slot function.
@imdreamrunner

Copy link
Copy Markdown
Contributor Author

Third round, in e9d9f82:

  • --out: documented in the changeset and in the componentIcons paragraph of author-a-theme. The module keeps each slot import as the theme source spells it, and --icons-specifier does not change it, so with --out in another directory a module must answer to that specifier from the output directory. This matches the icon registry rule. A new fixture builds src/theme.mjs with out: 'dist/theme.css', checks that the import is kept as written, supplies dist/slots.mjs, and loads the built module, which resolves every slot like the runtime theme.
  • Family root with an undefined slot: a family member's imported map now always passes through the slot merge, so a root drops the slot. A runtime theme extending the family root now reads the same static keys as one extending the source root (a new fixture checks this). The parity checks also compare the static view's keys exactly.
  • Theme template: the example now imports copySlot, and the comment shows its body and says to keep it in its own module.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommending approval. The --out limit for slot imports is now stated in the changeset and author-a-theme, with a fixture that loads the output, and the family-root undefined slot and the template example are fixed; built themes match runtime in every tested shape.

This builds on #9828 and lands after it.

[Automated review]

…de-block

# Conflicts:
#	docs/specs/components/CodeBlock/CodeBlock.spec.md
#	packages/cli/test/__golden__/no-icon-set/search-icon-set.json
#	packages/cli/test/__golden__/no-icon-set/search-icon-set.txt
The merge commit's lint hook reformatted this unrelated file; it now
matches main again.

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommending approval. Built themes now carry imported componentIcons slot functions and resolve every tested slot, state and static view like the runtime theme, including through built, package and family bases; a slot function written in the theme file still fails the build with a message that names the slot.

Approval is pending CI: the test workflows run only for pull requests to main, so they have not run on this head. This builds on #9828 and lands after it.

[Automated review]

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommending approval. Built themes now carry imported componentIcons slot functions and resolve every tested slot, state and static view like the runtime theme, including through built, package and family bases; a slot function written in the theme file still fails the build with a message that names the slot.

Approval is pending CI: the test workflows run only for pull requests to main, so they have not run on this head. This builds on #9828 and lands after it.

[Automated review]

…de-block

# Conflicts:
#	packages/cli/test/__golden__/no-icon-set/search-icon-set.json
#	packages/cli/test/__golden__/no-icon-set/search-icon-set.txt

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommending approval. Built themes now carry imported componentIcons slot functions and resolve every tested slot, state and static view like the runtime theme, including through built and package bases and in --family output; a slot function written in the theme file still fails the build with a message that names the slot.

Approval is pending CI: the test workflows run only for pull requests to main, so they have not run on this head. This builds on #9828 and lands after it.

[Automated review]

@astracat-bot astracat-bot Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommending approval. Built themes now carry imported componentIcons slot functions and resolve every tested slot, state and static view like the runtime theme, including through built and package bases and in --family output; a slot function written in the theme file still fails the build before anything is written.

No blocking findings. CI's test workflows run only for pull requests into main, so they have not run on this head; this pull request lands after #9828, which it builds on.

[Automated review]

@imdreamrunner
imdreamrunner changed the base branch from icons/ast087-slots-code-block to main November 5, 2026 18:13
main now carries #9828 as one squash commit; this merge keeps main's version
of everything #9828 contained and leaves only this branch's own change:
built themes keep componentIcons slot functions.

@astracat-bot astracat-bot Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Recommending approval.

Built themes now carry imported componentIcons slot functions and resolve every tested slot, state and static view like the runtime theme, including through built and package bases and in --family output; a slot function written in the theme file still fails the build before anything is written. No blocking findings.

[Automated review]

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 0894191

⏳ Building… Until it's ready, Storybook · Sandbox open the branch's previous preview.

Package size: measured; main has no measurement of the merge base to compare yet.

API changes: none in this pull request

Committed API report behind this build: cli 19 rows, core 23 rows; run pnpm api:report.

Not run on this PR: add ci:run-visual, ci:run-a11y or ci:run-rtl to run them.


Generated by PR Enrichment workflow | View full report

@imdreamrunner
imdreamrunner merged commit 7fb5cab into main Nov 5, 2026
61 of 62 checks passed
imdreamrunner added a commit that referenced this pull request Nov 5, 2026
main now carries #9828 and #9829 as squash commits; this merge keeps main's
version of everything they contained and leaves only this branch's own
change: the timestamp-copy slot.
imdreamrunner added a commit that referenced this pull request Nov 5, 2026
main now carries #9828, #9829, and #9830 as squash commits; this merge keeps
main's version of everything they contained and leaves only this branch's
own change: the table-sort-indicator slot, listed beside timestamp-copy in
the slot map and its type test.
@github-actions
github-actions Bot deleted the icons/ast087-slots-build-functions branch November 6, 2026 06:04

This branch was successfully deployed

1 active deployment
Preview — 08941917 Deployed Nov 5, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant