Repository navigation
feat(cli): built themes keep componentIcons slot functions - #9829
Conversation
…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.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
AI review status for this pull request.
|
… 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.
2fcb657 to
f48a61e
Compare
There was a problem hiding this comment.
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}whiledefineThemeskipsundefined, so anundefinedslot in an imported or spreadcomponentIconsmap erases the inherited slot in the built theme; for example, a child withchildSlots = {'code-block-copy': undefined}renders CodeBlock's copy button withcopywhen built andclockat runtime. - The changeset and the theme-authoring doc say a slot function imported into the theme file is carried, but
theme build --familyrejects 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 callscopySlotinline) 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; followconstbindings 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}}`, |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
|
Addressed in 4f67c8c:
New regression fixtures: an imported child map with |
There was a problem hiding this comment.
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, failstheme buildwith 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 theseenguard instaticValueto 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; |
There was a problem hiding this comment.
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.
…hich built themes now carry
9742d22 to
b012104
Compare
|
Second round, now rebased on #9828's latest head (#9829 head b012104):
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. |
There was a problem hiding this comment.
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 recipeauthor-a-themegives for shipping a built theme, the built module keeps the theme source's relative slot import, which--icons-specifierdoes not retarget, so it fails to load withERR_MODULE_NOT_FOUND; please state that limit in the changeset and thecomponentIconsparagraph ofauthor-a-theme(or carry slot imports through--out), and add an--outfixture 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)) |
There was a problem hiding this comment.
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."}, |
There was a problem hiding this comment.
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.
| * 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'})}, |
There was a problem hiding this comment.
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.
|
Third round, in e9d9f82:
|
There was a problem hiding this comment.
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]
…states only its reason
…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
…nto icons/ast087-slots-build-functions
The merge commit's lint hook reformatted this unrelated file; it now matches main again.
…nto icons/ast087-slots-build-functions
There was a problem hiding this comment.
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]
…nto icons/ast087-slots-build-functions
There was a problem hiding this comment.
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
…nto icons/ast087-slots-build-functions
There was a problem hiding this comment.
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]
…nto icons/ast087-slots-build-functions
There was a problem hiding this comment.
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]
There was a problem hiding this comment.
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]
PR Analysis Report🔎 Preview ·
|
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./builtsubpaths 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
theme buildtraces 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.null, requests) in an inlinecomponentIconsobject 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. Anundefinedslot is left out, so the inherited one stays, as indefineTheme.__componentIcons), a package theme (componentIconsand__componentIcons), and family members (the parent's values, then the member's own) all carry their slot functions.componentIconsis 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.ERR_THEME_INVALIDbefore anything is written (FR19). The error says to move it to its own module.Current specification
architecture:theme-compilation: item 7 (a built theme carriescomponentIconsfunctions) 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
astryx theme buildnow succeeds for themes whose slot functions are imported; it failed for them before.__componentIconsbesidecomponentIconsonly 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.Design and alternatives
resolveIconImportsgains afieldoption (iconsorcomponentIcons), so one tracer, with its mutation, cycle, and package-privacy checks, serves both fields. ForcomponentIcons, an inline object may hold static values and per-slot references. Rejected: a second tracer, which would drift from the icon rules.Evidence
build.component-icons.test.mjsruns native Node over built and runtime themes:undefinedslot; 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.slotand asObjectload correctly.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
Testing
pnpm vitest run --project node packages/cli/api/theme packages/cli/test/core-doc-quality.test.mjs packages/cli/test/experimental-isolation.test.mjstsc --project packages/cli/tsconfig.strict.json).