Skip to content

spec(public-component-api): each private data attribute has one owner module (INV23) - #9182

Merged
cixzhang merged 6 commits into
mainfrom
spec/private-attribute-owner
Oct 31, 2026
Merged

cixzhang merged 6 commits into
mainfrom
spec/private-attribute-owner

Conversation

@cixzhang

@cixzhang cixzhang commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

Maintainers get one place to name, change, and find each internal data-astryx-* attribute, so its selectors can't drift across hand-typed copies. People building with Astryx have nothing new to learn and can't mistake an internal attribute for a contract.

Exact decision needed

How Core and Lab own the data-astryx-* attributes they use internally, and which of these attributes are public.

Existing authority searched

  • architecture:public-component-api: INV12 (reachability makes something public; ./internal/* is the one exception) and INV9 (released APIs change deliberately). Neither says how an internal DOM attribute is named, owned, or kept out of the public surface.
  • architecture:react-component-runtime INV16 (a shared concern lives in one owner). It covers lifecycle and effects, not names.
  • spec:AST-066 FR6 uses data-astryx-theme as the theme scope. No record declares any other data-astryx-* attribute or a rule for private ones.
  • Source: about 36 data-astryx-* names across packages/core/src and packages/lab/src, plus one in packages/richtext/src, written by hand at their sites. The press selector is copied in 14 files, one selector is read but never written, two names are each declared in two files, and the attributes current records promise were never listed together. No lint rule covers them, and naming.ts's dataAttr() is used by only four names.

Decision

architecture:public-component-api gains INV23, a verification row, and a known-gaps bullet:

  • Each private attribute has one owner module in the package that writes it, packages/<package>/src/privateAttributes/<name>.stylex.ts. It holds the name and values and writes each selector once, as a literal in its own stylex.create call.
  • The owner exports only ready-made styles, the props or writer that set the attribute, and the runtime readers its package needs (a closest/matches helper or a getter), never the raw name or a selector. Callers in that package spread those exports and never write the attribute or its selector. No package imports another package's owner module through an internal path.
  • StyleX merges styles one whole property at a time, so an owner style carries every condition of each property it sets (rest and pointer states included). A caller does not set those properties again on the same element.
  • Outside owner modules and test files, a hand-typed data-astryx- string, template, or JSX attribute name, or a dataAttr() call that names a private attribute, fails @astryx/no-raw-private-attribute. Today's sites sit in the rule's baseline, which only shrinks, so main stays green. Tests may name private attributes because they assert the DOM.
  • Private attributes stay out of public exports, .doc.mjs, and Changesets, carry no compatibility promise, and may change in any release.
  • Public, changing only under INV9: data-astryx-theme and data-astryx-media (theme and media-surface scopes), data-astryx-aspect-ratio-override (AspectRatio FR3), data-astryx-token and data-astryx-token-value (ChatComposerTokenElement FR1), data-astryx-menu-press (the useMenuPress module), data-astryx-pressable (SegmentedControlItem FR7), and data-astryx-edge-comp (exported as EDGE_COMP_ATTR). Their owning code writes them at its own sites, and the lint allows their names.
  • The record's scope stays stable public packages; INV23 also reaches Lab source.
  • applies_to adds packages/lab/src/ and packages/richtext/src/.

Representative caller, before and after:

// before: every component writes the selector
transform: {default: 'scale(1)', ':active…': …, '[data-astryx-press="on"]': 'scale(0.98)'},

// after: the owner writes it once; the caller spreads a finished style
<button {...stylex.props(styles.base, pressStyles.shrink, inactive && pressStyles.shrinkOff)} />

Rejected alternatives

  • Exporting the selector as a stylex.defineConsts value for callers to use as a key. Compiled with StyleX 0.19 and Core's options, it emits a nested rule that matches a pressed ancestor rather than the element. Inside stylex.when.ancestor and when.descendant, it fails with Pseudo selector must start with ":" or "[".

Claim scope and non-goals

  • Records only. The lint rule, its baseline, and every owner module are follow-up implementation, listed as a known gap.
  • No public API changes here. Every attribute a current record promises or the package exports is on the public list; deprecating any of them would be a separate owner decision.
  • Swizzle behavior for ejected components that import an owner module stays with the swizzle owner.

Evidence and implementation relationship

  • A compile check with StyleX 0.19.0 and Core's Babel options. Owner-literal selectors, including when.ancestor with a marker imported from another .stylex.ts, compile to correct CSS. Callers that spread the exported styles contain no selector.
  • The same check confirmed the whole-property merge: a caller's transform conditions are replaced by an owner style that also sets transform.
  • Implementation follows in separate pull requests: the lint rule with its baseline, then the owner modules one attribute at a time.

Writing rubric results

  • R1 narration: none. INV23 and the gap bullet are present-tense statements about the system; "yet" appears only in the known-gaps list, which records current gaps.
  • R2 research in the record: none. The attribute survey and compile results are in this description, not the record.
  • R3 evidence naming a change: none. The verification row names the lint rule and public-API review.
  • R4 rejected alternatives over one line or outside a decision: none in the record. The defineConsts alternative is described only here.
  • R5 pull request or issue references remaining: none.
  • R6 ruled open questions still listing options: none.

Scope

  • This PR contains specification records only.
  • It records observable behavior and preserves equivalent internal implementations.
  • Any named internal mechanism is intentionally public, names its dependent caller/system, and explains why an equivalent implementation would not satisfy the contract.
  • Verification states the evidence layer and failure signal without prescribing CI job/workflow topology.
  • It records one intentional durable decision, not a rescue for a separable tagalong.
  • The canonical knowledge owner, affected current claims, and overlapping open work are named; any ownership collision is resolved or called out for human decision.
  • Adjacent API, visual, accessibility, composition, and implementation facts remain outside scope unless this exact decision depends on them.
  • Public text and artifacts contain no internal Meta context.

Validation

  • pnpm check:knowledge: Knowledge templates and records are aligned.
  • Prettier: applied.
  • git diff --check: clean.

@vercel

vercel Bot commented Oct 31, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
astryx Error Error Oct 31, 2026 7:45pm UTC

Request Review

@astracat-bot

astracat-bot Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

Review status Updated
🟢 Reviewed (for maintainers only) Oct 31, 2026, 7:56 PM UTC

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 31, 2026
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Oct 31, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 6be9e0f

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Oct 31, 2026

@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.

Changes requested: the direction of INV23 is approved, but the record contradicts two current component records and overstates how today's code conforms.

  • component:AspectRatio (FR3) and component:ChatComposerTokenElement (FR1) promise data-astryx-aspect-ratio-override, data-astryx-token and data-astryx-token-value. Name those attributes public in INV23, or amend those records in this pull request.
  • Line 235 says both public attributes are built with dataAttr(), but reset.css, generateThemeRules.ts and the CLI theme build write them otherwise. Reword the line, or list those sites in the INV23 gap.
  • @astryxdesign/richtext writes data-astryx-richtext-code-syntax but cannot import Core's ./internal/*, and applies_to lists no Lab path although INV23 binds Lab files.

Please also say whether tests may name a private attribute. The new head then needs a fresh /approve-spec.

[Automated review]

whose current signature cannot delegate gains a ref-taking signature beside
it; the old signature is deprecated under INV9.
- **INV23 — Each private data attribute has one owner module.** A
`data-astryx-*` attribute is private unless this invariant names it public.

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 makes every unnamed attribute private, including two that current component records promise: component:AspectRatio keeps data-astryx-aspect-ratio-override "for product CSS that targets it" (FR3), and component:ChatComposerTokenElement FR1 says the root MUST expose data-astryx-token, with data-astryx-token-value marked stable. Name these three attributes public here, or amend those records in this pull request.

compatibility promise, and may change in any release. The public data
attributes are `data-astryx-theme`, the theme scope (`spec:AST-066` FR6), and
`data-astryx-media`, the media-surface scope that theme compilation emits;
each is built with `dataAttr()` from `naming.ts` and changes only under INV9.

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.

Today neither public attribute is consistently built with dataAttr(). packages/core/src/reset.css:396 and :400 hand-type [data-astryx-media=…] (a CSS file cannot call it), generateThemeRules.ts:56-64 builds both names from dataAttrNamespace, and the CLI theme build hand-types [data-astryx-theme…]. The verification row exempts the public list, so nothing flags these sites. Reword this line to "named through naming.ts where code builds it", or list the sites in the INV23 gap.

The owner exports only ready-made styles that read the attribute and the
props or writer that set it, never the raw name or a selector. Every other
Core and Lab file spreads those exports and never writes the attribute or its
selector; Lab imports them through Core's `./internal/*` subpath (INV12).

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.

Only Core and Lab can reach ./internal/* (INV12), but @astryxdesign/richtext also writes a private attribute (data-astryx-richtext-code-syntax, CodeSyntaxPlugin.tsx:52). With the only owner in Core, it has no conforming path. Separately, INV23 binds Lab files, but applies_to lists no Lab path, so pnpm specs:for never shows this invariant for a Lab file.

`data-astryx-press`, `data-astryx-popover-fallback-close` (in Core and Lab),
`data-astryx-table-pinned` and `data-astryx-cell-gliding` (each named in two
files), `data-astryx-scrolling` (read but never written), the Chat
composer's `data-astryx-token`, `data-astryx-token-value`, and

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.

data-astryx-token and data-astryx-token-value are the exposed, stable serialization contract in component:ChatComposerTokenElement (FR1 and its interface table), and its .doc.mjs names the span. Listing them as private contradicts that current record.

@github-actions

github-actions Bot commented Oct 31, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

Preview: the links below open this branch's latest Vercel deployment, which can trail a new push until that push's deployment is ready.

📚 Storybook Preview

View Storybook for this PR

🧪 Sandbox Preview

View Sandbox for this PR

No new or modified components detected.

Bundle Size Summary

No component packages changed.

Published Package Size

No published package changed size (11 measured).

Download is the gzip tarball npm fetches; unpacked is what lands in node_modules.

Accessibility Audit

Status: Accessibility did not run on this pull request; add ci:run-a11y to run it. It runs after merges to main and before each release.


Generated by PR Enrichment workflow | Storybook | Sandbox | View full report

…tributes, per-package owners, and test exemption
@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Oct 31, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 225974f

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Oct 31, 2026

@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.

Changes requested. INV23's direction is approved at this head, but it still contradicts current records that this pull request leaves unchanged.

  • module:DropdownMenu/useMenuPress marks data-astryx-menu-press as stable, component:SegmentedControlItem FR7 passes data-astryx-pressable through, and DropdownMenu, ContextMenu and Selector require the menu marker, yet INV23 makes both attributes private and expects them to be deprecated. Name them (and the exported data-astryx-edge-comp) in INV23's public list, or amend those records here.
  • The sentence after INV23 still says the record applies to stable public packages, although applies_to now lists Lab and the gap requires Lab's Schedule to conform.

The red build-storybook check runs a script that landed on main after this branch was cut, so updating the branch should fix it. The amended head then needs a fresh /approve-spec.

[Automated review]

Comment on lines +236 to +240
any release. The public data attributes are `data-astryx-theme`, the theme
scope (`spec:AST-066` FR6); `data-astryx-media`, the media-surface scope that
theme compilation emits; `data-astryx-aspect-ratio-override`
(`component:AspectRatio` FR3); and `data-astryx-token` and
`data-astryx-token-value` (`component:ChatComposerTokenElement` FR1). They

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.

Current records also promise two attributes this list leaves private. module:DropdownMenu/useMenuPress marks data-astryx-menu-press as stable (line 149), and DropdownMenu FR5, ContextMenu FR5 and Selector FR7 require it. component:SegmentedControlItem FR7 passes a caller's data-astryx-pressable through. Name both here with their records, as this list already does for AspectRatio and ChatComposerTokenElement, and add the exported data-astryx-edge-comp. If they are meant to retire instead, amend those records in this pull request.

theme build, AspectRatio, and the Chat composer, and the lint rule allows
their names.

This record applies to stable public packages. Lab components are not stable

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.

applies_to now lists packages/lab/src/, and the INV23 gap requires Lab's Schedule to conform, but this sentence still limits the record to stable public packages. Say that INV23 also governs private attributes in Lab.

@github-actions github-actions Bot added the needs:spec-owner-review Current knowledge records await owner approval label Oct 31, 2026
@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec a9253c7

@github-actions github-actions Bot removed the needs:spec-owner-review Current knowledge records await owner approval label Oct 31, 2026

@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.

Changes requested: INV23's direction is approved at this head, but the record still conflicts with a current spec and leaves part of its own rule unworkable.

  • The new scope sentence limits the record to Core, which takes the published RichText package out of INV1–INV22 while line 68 and spec:AST-071 still rely on the old scope; keep "stable public packages" and add INV23's Lab reach, or amend those records here.
  • INV23 lets an owner export only styles and props or writers, so code that reads a private attribute at runtime (for example Popover.tsx:648 or DropdownMenuSubMenu.tsx:429) cannot conform by moving into an owner module, as the gap bullet expects; let owners also export the readers their package needs.
  • The gap bullet's "each named in two files" also covers data-astryx-press, whose selector is copied in 14 Core files.

The amended head then needs a fresh /approve-spec.

[Automated review]


This record applies to stable public packages. Lab components are not stable
public promises until promotion.
This record applies to the published Core package, and INV23 also applies to

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 replaces "applies to stable public packages" with Core only, so the published @astryxdesign/richtext (not canaryOnly) leaves INV1–INV22. Line 68 still says the record covers "stable Astryx components", and spec:AST-071 covers packages/richtext/src/** and leaves composition order to INV6. Suggest: "This record applies to stable public packages, and INV23 also applies to Lab source."

Comment on lines +222 to +225
written. The owner exports only ready-made styles that read the attribute and
the props or writer that set it, never the raw name or a selector. Every other
file in that package spreads those exports and never writes the attribute or
its selector, and no package imports another package's owner module through an

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.

Several private attributes are read at runtime, not only styled: Popover/Popover.tsx:648 and Popover/usePopover.tsx:58 call closest() on [data-astryx-popover-fallback-close], DropdownMenu/DropdownMenuSubMenu.tsx:429 reads data-astryx-submenu-regions, and Table/glidingDivider.ts:283 reads data-astryx-table-pinned. With exports limited to styles and props or writers, those readers cannot conform by moving into an owner module, as the gap bullet says they will. Let the owner also export the readers its package needs, still never the raw name or a selector.

Comment on lines +372 to +374
`data-astryx-press`, `data-astryx-popover-fallback-close`,
`data-astryx-table-pinned` and `data-astryx-cell-gliding` (each named in two
files), `data-astryx-scrolling` (read but never written), the Chat composer's

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.

"(each named in two files)" reads as covering data-astryx-press too, but its selector is copied in 14 Core source files. List it separately with its own count.

@cixzhang

Copy link
Copy Markdown
Contributor Author

/approve-spec 795cf8a

@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: INV23's direction is approved at this head, and every data-astryx-* attribute that a current record promises or the package exports is on its public list. One optional follow-up: ClickableCard.doc.mjs, SelectableCard.doc.mjs and Thumbnail.doc.mjs already name the private data-astryx-press in their --_press-overlay descriptions, so listing them in the INV23 gap bullet would help the press-owner follow-up find them.

[Automated review]

named in two files; `data-astryx-scrolling`, read but never written;
DropdownMenu's `data-astryx-submenu-host`; the Chat composer's
`data-astryx-dictation-interim`; and RichText's
`data-astryx-richtext-code-syntax`. No full inventory exists yet. Each

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.

Optional: three .doc.mjs entries already name the private data-astryx-press (ClickableCard.doc.mjs:41, SelectableCard.doc.mjs:43, Thumbnail.doc.mjs:82, in their --_press-overlay descriptions), which INV23's "appears in no … .doc.mjs" rules out. Listing them here would let the press-owner follow-up find them.

@cixzhang
cixzhang merged commit d18fdaa into main Oct 31, 2026
51 of 52 checks passed
@github-actions
github-actions Bot deleted the spec/private-attribute-owner branch November 1, 2026 06:05

This branch had an error being deployed

1 failed deployment
Preview — 795cf8a4 Deployed Oct 31, 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