Accept Marker type in StyleXStyles for passing between component prop boundaries - #1820
Accept Marker type in StyleXStyles for passing between component prop boundaries#1820titchimoto wants to merge 3 commits into
StyleXStyles for passing between component prop boundaries#1820Conversation
…pe to allow markers in constrained StyleXStyles prop styles
|
Hi @titchimoto! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
@titchimoto is attempting to deploy a commit to the Meta Open Source Team on Vercel. A member of the Team first needs to authorize it. |
nmn
left a comment
There was a problem hiding this comment.
Default markers and custom markers should really be combined into a single type.
| @@ -318,6 +319,14 @@ export type StyleX$DefineMarker = () => MapNamespace<{ | |||
| readonly marker: symbol; | |||
| }>; | |||
|
|
|||
| export type StyleX$DefaultMarker = () => MapNamespace<{ | |||
| readonly marker: 'default-marker'; | |||
| }>; | |||
|
|
|||
| export type StyleXMarkerToken = | |||
| | ReturnType<StyleX$DefineMarker> | |||
| | ReturnType<StyleX$DefaultMarker>; | |||
|
|
|||
There was a problem hiding this comment.
| export type StyleXMarker = MapNamespace<{ | |
| readonly marker: symbol; | |
| }>; | |
| export type StyleX$DefineMarker = () => StyleXMarker; | |
| export type StyleX$DefaultMarker = () => StyleXMarker; | |
| | GenStylePropType<Readonly<CSS>> | ||
| | Readonly<[GenStylePropType<Readonly<CSS>>, InlineStyles]>, | ||
| | Readonly<[GenStylePropType<Readonly<CSS>>, InlineStyles]> | ||
| | StyleXMarkerToken, |
There was a problem hiding this comment.
| | StyleXMarkerToken, | |
| | StyleXMarker, |
There was a problem hiding this comment.
Pull request overview
This PR updates StyleX’s public typing so marker tokens (stylex.defaultMarker() / stylex.defineMarker()) are accepted anywhere StyleXStyles<T> is used, enabling marker-based ancestor/descendant styling patterns to pass cleanly through constrained component style props (e.g., design-system xstyle?: StyleXStyles<...>).
Changes:
- Extend
StyleXStyles<T>to accept a newStyleXMarkerTokenunion type. - Define and export
StyleXMarkerToken(andStyleX$DefaultMarker) in both Flow and TypeScript type surfaces. - Add TypeScript type-tests validating marker tokens work with constrained
StyleXStyles<T>without weakening CSS constraints.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| packages/typescript-tests/src/typetests.ts | Adds TS type-tests proving marker tokens satisfy StyleXMarkerToken and are accepted by constrained StyleXStyles<T> while preserving constraints. |
| packages/@stylexjs/stylex/src/types/StyleXTypes.js | Updates Flow StyleXStyles to include StyleXMarkerToken and introduces StyleX$DefaultMarker + StyleXMarkerToken type exports. |
| packages/@stylexjs/stylex/src/types/StyleXTypes.d.ts | Updates TS StyleXStyles to include StyleXMarkerToken and introduces StyleX$DefaultMarker + StyleXMarkerToken type exports. |
| packages/@stylexjs/stylex/src/stylex.js | Re-exports StyleXMarkerToken and types defaultMarker on the legacy interface via StyleX$DefaultMarker. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
f3b0864 to
3673e82
Compare
@nmn sounds good! updated here to collapse both these marker types down into a single type. I did keep the Flow |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
What changed / motivation ?
In our Design System, we follow StyleX's docs recommend pattern for constraining component style props using
StyleXStyles<T>:This pattern works for style overrides but consumers also need to use the marker API to implement ancestor-state patterns, for example, revealing a child element when a parent is hovered, entirely in CSS:
Because
StyleXStyles<T>has no way to express "a marker token is also valid here", in our DS, we've created an internalXStyletype which is essentially a union ofStylexStyles<T> | StyleXMarkerToken(which we've just created internally from theReturnType's as in this PR), which does work & without that our DS consumers are forced to either add additional wrapping elements, or are generally unable to use our components for their use-case.But it would be nice to not have to manage this at the DS level & could live in the library instead to pass between component prop boundaries easier.
Pre-flight checklist
Contribution Guidelines