Skip to content

chore(ChatMessage): give the avatar offset variable a private literal name - #9602

Merged
cixzhang merged 3 commits into
mainfrom
chat-avatar-offset-private-var
Nov 2, 2026
Merged

cixzhang merged 3 commits into
mainfrom
chat-avatar-offset-private-var

Conversation

@cixzhang

@cixzhang cixzhang commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

Why

Internal CSS variables are private. ChatMessage's avatar offset is an internal variable, but StyleX hashed its name, so the published stylesheet declares it as a plain --x… name that looks like a public custom property and appears in the public API report. A private variable uses a --_* name so consumers can tell it is not for them to set or read.

What

  • chatMessage.vars.stylex.ts: the internal variable is now the literal private name --_chat-avatar-offset (StyleX's literal-name form, so nothing is hashed). Its explanatory comment stays, updated to the new name.
  • ChatMessage.tsx: its two references use the new name.
  • Chat.doc.mjs: the variable is listed in theming.vars as private: true, like the other private Chat variables, and derivedVarRegistry.test.ts lists it as a variable with no derived mapping (content state, not a theming lever).
  • Patch [chore] Changeset.

Risk

Low. The variable is internal and not exported from the package entry point. Built CSS is the same rule for rule: only the variable name and the generated class names change.

Testing

  • Built @astryxdesign/core before and after. astryx.css now declares --_chat-avatar-offset (default 0px, var(--spacing-5) when the message holds a name row, read by the avatar's margin-top) and no hashed variable.
  • Rule-for-rule check: with the old hashed name replaced by the new name and generated class names normalized, the before and after rule sets are equal. The only order change is between the default rule and the :has([data-chat-name]) rule, and the :has() rule has higher specificity, so the computed avatar offset is the same with and without a name row.
  • vitest run packages/core/src/Chat packages/core/src/theme: 2063 passed. tsc, ESLint, and Prettier clean.

CI impact

None. The next API report regeneration drops the hashed variable row.

@vercel

vercel Bot commented Nov 2, 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 2, 2026 7:30pm UTC

Request Review

@astracat-bot

astracat-bot Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

AI review status for this pull request.

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

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 2, 2026
@github-actions github-actions Bot added the needs:design-review Affects visuals — Design should review label Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

PR Analysis Report

🔎 Preview · 1479ec3

Storybook · Sandbox · built from this PR's head

Current run: Heavy CI deferred: runs when marked ready and before merge. Lint, typecheck and any path-filtered checks ran on this push.


Generated by PR Enrichment workflow | View current CI run

@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 rename is right, and the built stylesheet is otherwise unchanged, but derivedVarRegistry.test.ts now fails because --_chat-avatar-offset is not listed in Chat.doc.mjs. To fix it, add a private: true entry for the variable to theming.vars[] in packages/core/src/Chat/Chat.doc.mjs, and add the name with its reason to VARS_WITHOUT_DERIVED_MAPPING in packages/core/src/theme/derivedVarRegistry.test.ts, as --_tree-focus-z does. Optionally, split the long sentence in the reworded chatMessage.vars.stylex.ts comment (see the inline note).

[Automated review]

*/
export const chatMessageVars = stylex.defineVars({
avatarOffset: '0px',
'--_chat-avatar-offset': '0px',

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.

derivedVarRegistry.test.ts ("Chat: all source vars are in doc file") now sees this literal name, and it fails on this head. Document the variable as private in Chat.doc.mjs theming.vars[]:

{name: '--_chat-avatar-offset', description: 'Top offset of a message avatar: the name row spacing when a bubble in the message shows a name, else 0px. Each message sets it from its own content. Not a theming lever.', default: '0px', private: true},

Then add '--_chat-avatar-offset', with its reason, to VARS_WITHOUT_DERIVED_MAPPING in packages/core/src/theme/derivedVarRegistry.test.ts, as --_tree-focus-z does. With both changes the test passes.

Comment on lines +8 to +14
* `--_chat-avatar-offset` is the avatar's top spacing: the name row's spacing
* when a bubble in this message renders a name, else none. Each article sets
* it from its own `:has([data-chat-name])`, a parent-relative rule: a
* sibling-relative `:has(~ …)` in the global stylesheet makes WebKit re-check
* every earlier sibling on each insertion into any container, so filling one
* grows quadratically. A message nested in another sets its own value, so it
* never inherits the outer message'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.

Non-blocking: the sentence starting "Each article sets it" runs to 35 words and covers several topics. The repository's comment style caps a description sentence at 25 words, with one topic each. A shorter version:

 * `--_chat-avatar-offset` is the avatar's top spacing. It is the name row's
 * spacing when a bubble in this message shows a name, else 0. Each article
 * sets it from its own `:has([data-chat-name])`. A sibling-relative `:has(~ …)`
 * in the global stylesheet makes WebKit re-check every earlier sibling on each
 * insertion. Filling a container then takes quadratic time. A nested message
 * sets its own value and does not inherit the outer one.

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

Approval recommended. The private name --_chat-avatar-offset leaves the built stylesheet unchanged apart from the variable name, and the new private: true entry in Chat.doc.mjs, with its VARS_WITHOUT_DERIVED_MAPPING reason, fixes the theming-docs test failure from the earlier review. Optionally, the long sentence in the chatMessage.vars.stylex.ts comment can still be split, as the earlier inline note suggests.

[Automated review]

@cixzhang
cixzhang merged commit d40b5b7 into main Nov 2, 2026
94 of 97 checks passed
@github-actions
github-actions Bot deleted the chat-avatar-offset-private-var branch November 3, 2026 06:05

This branch was successfully deployed

1 active deployment
Preview — 1479ec3d Deployed Nov 2, 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. needs:design-review Affects visuals — Design should review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant