fix(ui): Give each Mosaic component a minimal CSS reset - #9332
fix(ui): Give each Mosaic component a minimal CSS reset#9332alexcarpenter wants to merge 2 commits into
Conversation
The injected reset in MosaicProvider is keyed on `data-cl-slot`, which only the slot-recipe components emit. The StyleX components style through `themeProps` + `stylex.props` and never carried it, so they picked up user-agent defaults — most visibly `<Text>` and `<Heading>`, which rendered with the browser's paragraph and heading margins. The StyleX tier also builds through the Emotion-free `styles/index.ts` barrel, so it has no provider to inject anything and needs the reset as a StyleX atom rather than a stylesheet. `reset.base` is composed first in every `stylex.props(...)` call, mirroring how `typography.styles.ts` shares `sizes`/`colors`. `margin`/`padding` stay shorthands so component longhands outrank them by StyleX's own priority layers; the `inherit` declarations rely on the reset going first.
🦋 Changeset detectedLatest commit: beb47e9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 0 packagesWhen changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
📝 WalkthroughWalkthroughAdded a shared StyleX reset for spacing, sizing, color, typography, and line height. Applied Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
@clerk/astro
@clerk/backend
@clerk/chrome-extension
@clerk/clerk-js
@clerk/electron
@clerk/electron-passkeys
@clerk/eslint-plugin
@clerk/expo
@clerk/expo-google-signin
@clerk/expo-passkeys
@clerk/express
@clerk/fastify
@clerk/hono
@clerk/localizations
@clerk/nextjs
@clerk/nuxt
@clerk/react
@clerk/react-router
@clerk/shared
@clerk/tanstack-react-start
@clerk/testing
@clerk/ui
@clerk/upgrade
@clerk/vue
commit: |
API Changes Report
Summary
No API Changes DetectedAll packages have stable APIs with no detected changes. Report generated by Break Check Last ran on |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In @.changeset/mosaic-component-reset.md:
- Around line 1-2: Replace the empty front matter in mosaic-component-reset.md
with a valid patch changeset for the package owning packages/ui, and add a
concise note describing that the Mosaic reset removes native default margins
from public UI components.
In `@packages/ui/src/mosaic/components/reset.test.tsx`:
- Around line 35-57: Expand the reset coverage in the cases list and its
assertions to include the Button label span and the Menu reset targets:
positioner, popup, item, and separator. Use the existing component patterns and
ensure each added node is independently validated rather than relying on
root-only coverage.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository YAML (base), Organization UI (inherited)
Review profile: CHILL
Plan: Pro Plus
Run ID: b4bf9e19-9423-42a5-94a2-3a2412c8c516
📒 Files selected for processing (19)
.changeset/mosaic-component-reset.mdpackages/ui/src/mosaic/components/avatar/avatar.styles.tspackages/ui/src/mosaic/components/avatar/avatar.tsxpackages/ui/src/mosaic/components/badge/badge.styles.tspackages/ui/src/mosaic/components/badge/badge.tsxpackages/ui/src/mosaic/components/button/button.styles.tspackages/ui/src/mosaic/components/button/button.tsxpackages/ui/src/mosaic/components/card/card.styles.tspackages/ui/src/mosaic/components/card/card.tsxpackages/ui/src/mosaic/components/heading/heading.tsxpackages/ui/src/mosaic/components/icon/icon.tsxpackages/ui/src/mosaic/components/item/item.styles.tspackages/ui/src/mosaic/components/item/item.tsxpackages/ui/src/mosaic/components/menu/menu.styles.tspackages/ui/src/mosaic/components/menu/menu.tsxpackages/ui/src/mosaic/components/popover/popover.tsxpackages/ui/src/mosaic/components/reset.styles.tspackages/ui/src/mosaic/components/reset.test.tsxpackages/ui/src/mosaic/components/text/text.tsx
🔗 Linked repositories identified
CodeRabbit considers these linked repositories for cross-repo context during reviews:
clerk/clerk_go(manual)clerk/dashboard(manual)clerk/accounts(manual)clerk/backoffice(manual)clerk/clerk(manual)clerk/clerk-docs(manual)clerk/cloudflare-workers(manual)
💤 Files with no reviewable changes (6)
- packages/ui/src/mosaic/components/item/item.styles.ts
- packages/ui/src/mosaic/components/button/button.styles.ts
- packages/ui/src/mosaic/components/badge/badge.styles.ts
- packages/ui/src/mosaic/components/card/card.styles.ts
- packages/ui/src/mosaic/components/avatar/avatar.styles.ts
- packages/ui/src/mosaic/components/menu/menu.styles.ts
Description
MosaicProviderinjects a reset keyed ondata-cl-slot, but only the slot-recipe components (dialog,tabs,input) emit that attribute. The StyleX components style throughthemeProps+stylex.propsand never carried it, so they inherited user-agent defaults — most visibly<Text>and<Heading>, which rendered with the browser's paragraph and heading margins. MeanwhileboxSizingandfontFamily: inheritwere hand-copied into six separate.styles.tsfiles.An injected stylesheet can't fix this: the StyleX tier builds through the deliberately Emotion-free
styles/index.tsbarrel, which has no provider to inject anything. So the reset has to be a StyleX atom.components/reset.styles.tsexportsreset.base, composed as the first argument of everystylex.props(...)call — the same waytypography.styles.tsalready sharessizes/colors/truncationStyles:marginandpaddingare shorthands on purpose. StyleX sorts shorthands into an earlier priority layer than longhands, so a component's ownpaddingInlineoutranks the reset no matter how the arguments are ordered — visible in the builtstyles.css:The
inheritdeclarations tie with a component's own value, so those do depend on the reset going first.The declarations the reset now owns are deleted from
button,badge,avatar,card,itemandmenu. Each one still appears exactly once in the emitted CSS.Two things are deliberately left alone.
box.tsxkeeps its local plain-object reset andinput.tsxkeeps its owninheritdeclarations — both sit on the Emotion path and can't consume a StyleX atom, andMOSAIC_RESET_CSSremains the reset for that tier.Popover.Trigger/Close/Title/Descriptionare pure pass-throughs with no styles at all; giving a raw<button>padding: 0while leaving its native chrome would look worse than leaving it, and that needs acontrolatom this PR doesn't introduce.This is a visual change.
<Text>and<Heading>no longer carry the browser's default margins, so they now sit flush with their container. Layouts that leaned on that spacing need to set it explicitly.Checklist
pnpm testruns as expected.pnpm buildruns as expected.Type of change