Migrate MenuDivider, VirtualList and the toast viewport to vanilla-extract - #2732
Migrate MenuDivider, VirtualList and the toast viewport to vanilla-extract#2732stipsan wants to merge 8 commits into
Conversation
…xtract Co-authored-by: Cody Olsen <stipsan@users.noreply.github.com>
…xtract Co-authored-by: Cody Olsen <stipsan@users.noreply.github.com>
…nilla-extract Co-authored-by: Cody Olsen <stipsan@users.noreply.github.com>
Co-authored-by: Cody Olsen <stipsan@users.noreply.github.com>
🦋 Changeset detectedLatest commit: c643c51 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
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.
1 Skipped Deployment
|
There was a problem hiding this comment.
Pull request overview
Migrates three static style blocks (MenuDivider, VirtualList wrapper/item wrapper, and the Toast viewport container) from styled-components to vanilla-extract, continuing the repo’s incremental extraction of static CSS into @sanity/ui/styles.css.
Changes:
- Replaces
styled.*wrappers inVirtualListwith vanilla-extract classes and preserves polymorphicas, ref wiring, and className merging. - Replaces the toast viewport
styled(Grid)wrapper with atoastLayervanilla-extract class applied directly toGrid as="ul". - Replaces
styled.hrMenuDivider with a plain polymorphic component applying a vanilla-extractmenuDividerclass, and adds a changeset documenting the requirement to import@sanity/ui/styles.css.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| packages/ui/src/core/utils/virtualList/virtualList.tsx | Removes styled-components wrappers and applies vanilla-extract classes to the polymorphic root and items. |
| packages/ui/src/core/utils/virtualList/virtualList.css.ts | Adds extracted static positioning styles for the VirtualList root and item wrapper. |
| packages/ui/src/core/components/toast/toastLayer.tsx | Removes styled(Grid) wrapper and applies a vanilla-extract class to the Grid toast viewport rendered as <ul>. |
| packages/ui/src/core/components/toast/toastLayer.css.ts | Adds extracted static layout/positioning styles for the toast viewport container. |
| packages/ui/src/core/components/menu/menuDivider.tsx | Replaces styled.hr with a polymorphic component that applies a vanilla-extract class and preserves className merging. |
| packages/ui/src/core/components/menu/menuDivider.ts | Removes the previous styled-components implementation of MenuDivider. |
| packages/ui/src/core/components/menu/menuDivider.css.ts | Adds extracted static divider styles (hairline, background var, margin reset). |
| .changeset/vanilla-extract-second-slice.md | Adds a minor changeset documenting the additional components now depending on @sanity/ui/styles.css. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
…rings Co-authored-by: Cody Olsen <stipsan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 10 changed files in this pull request and generated no new comments.
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
Suppressed comments (1)
pnpm-lock.yaml:11877
- pnpm-lock now resolves
@sanity/vision's@sanity/uidependency to the published@sanity/ui@4.0.4instead of the workspacelink:packages/ui. Since the repo also depends on the workspace@sanity/ui(e.g.apps/studio), this can lead to two separate@sanity/uiinstances in a single app (which is especially risky if contexts/providers are involved) and can make local UI changes not exercised through@sanity/vision. Consider adjusting pnpm workspace resolution (or pinning/overriding) so@sanity/visionuses the workspace@sanity/uiduring development/CI, or explain why pulling@sanity/ui@4.0.4here is expected.
…event) Co-authored-by: Cody Olsen <stipsan@users.noreply.github.com>
…t-low-risk-refactors-c941 # Conflicts: # pnpm-lock.yaml Co-authored-by: Cody Olsen <stipsan@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 10 changed files in this pull request and generated no new comments.
Files not reviewed (1)
- pnpm-lock.yaml: Generated file
Suppressed comments (1)
pnpm-lock.yaml:667
- This lockfile update looks broader than what’s needed for adding
clsxtopackages/ui(e.g. it also upgrades@module-federation/viteat pnpm-lock.yaml:2487 and@testing-library/user-eventat pnpm-lock.yaml:4416, plus several@sanity/*versions like pnpm-lock.yaml:3905). If these upgrades aren’t intentional, consider regeneratingpnpm-lock.yamlto keep the diff scoped to theclsxaddition; otherwise, please call out the dependency bumps explicitly in the PR description so they’re reviewed as part of scope.
…t-low-risk-refactors-c941 # Conflicts: # pnpm-lock.yaml Co-authored-by: Cody Olsen <stipsan@users.noreply.github.com>
Continues the styled-components → vanilla-extract migration started in #2523 ("more components follow in future 4.x minors", per the 4.0.0 release notes) with three low-risk refactors. Each one moves fully static CSS — no theme or prop interpolation — into a colocated
.css.tsmodule extracted into@sanity/ui/styles.css, and removes thestyled-componentsimport from its file entirely.The three refactors
MenuDivider(packages/ui/src/core/components/menu/menuDivider.tsx): the staticstyled.hrbecomes a plain<hr>with a vanilla-extract class. The polymorphicassupport and publicMenuDividerProps<E>type are preserved using the same component-plus-cast pattern asKBDandSrOnly, and a consumer-providedclassNameis still merged.VirtualList(packages/ui/src/core/utils/virtualList/virtualList.tsx): the two staticstyled.divs (position: relativeroot, absolutely positioned item wrapper) become vanilla-extract classes. Theaspolymorphism, rest-prop spreading (soas={Stack}keeps receiving Stack props), inlinetop/heightstyles, andclassNamemerging are preserved.packages/ui/src/core/components/toast/toastLayer.tsx):StyledLayer = styled(Grid)becomes<Grid as="ul" className={toastLayer}>.as="ul"is equivalent to the previousforwardedAs="ul", and the inlinezIndexfromuseLayer()is unchanged.Why these three are low-risk
Candidates were screened for cascade-order safety: the static stylesheet loads before styled-components' runtime-injected styles, so a vanilla-extract class must never need to override a styled-components rule of equal specificity. All three picks have zero property collisions with the runtime styles that remain on their elements (
boxStyle/grid styles emit none of the properties the toast viewport sets; the other two style plain DOM elements). Rejected for exactly that reason: breadcrumbs'ExpandButton(margin: -4pxmust beat Button's runtimemargin: 0) and hotkeys'Key(same-specificitydisplayoverride ofKBD).Changeset
One
minorchangeset, following the 4.0.0 wording: no API changes, but these components now render unstyled unless the app imports@sanity/ui/styles.cssonce (required since 4.0.0).Verification
pnpm lint(includes tsgolint type checking),pnpm test(106 unit tests, including menu and toast tests) andpnpm knipall pass.pnpm --filter @sanity/ui buildextracts all three rule sets intodist/styles.csswith declarations identical to the removed styled-components CSS.pnpm test:browserpasses: 245 tests across 61 story files, rendering every story (Menu, MenuButton, MenuItem, Toast, VirtualList included) in headless Chromium with play interactions.height: 1px; background-color: rgb(42, 45, 63); the toast viewport<ul>resolves toposition: fixed; right: 0; bottom: 0; display: grid; list-style: none; pointer-events: none; max-width: 420px, and two distinct-id toasts stack with the expected 12px grid gap; the VirtualList root/items resolve torelative/absolutepositioning.Menu with the 1px hairline divider between Inspect and the submenu item
Two toasts stacked in the bottom-right toast viewport
VirtualList scrolled to items 22-36 with even spacing
menu_divider_toast_viewport_virtual_list_walkthrough.mp4
To show artifacts inline, enable in settings.