-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix the cx()
function's class collection at runtime as it generated class instances rather than strings.
#1697
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@compiled/react': patch | ||
--- | ||
|
||
Fix the `cx()` function's class collection at runtime as it generated class instances rather than strings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
packages/react/src/create-strict-api/__tests__/pass-through-xcss.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/** @jsxImportSource @compiled/react */ | ||
import { render } from '@testing-library/react'; | ||
|
||
import { cssMap, type XCSSProp, cx } from './__fixtures__/strict-api'; | ||
|
||
const styles = cssMap({ | ||
rootNative: { | ||
color: 'var(--ds-text)', | ||
background: 'var(--ds-surface)', | ||
}, | ||
rootComponent: { | ||
color: 'var(--ds-text-error)', | ||
background: 'var(--ds-surface-overlay)', | ||
}, | ||
bold: { | ||
color: 'var(--ds-text-bold)', | ||
}, | ||
sunken: { | ||
background: 'var(--ds-surface-sunken)', | ||
}, | ||
}); | ||
|
||
function ComponentPassThrough({ | ||
xcss, | ||
}: { | ||
xcss?: ReturnType<typeof XCSSProp<'background' | 'color', '&:hover'>>; | ||
}) { | ||
return <NativePassThrough xcss={cx(styles.rootComponent, xcss)} />; | ||
} | ||
|
||
function NativePassThrough({ | ||
xcss, | ||
}: { | ||
xcss?: ReturnType<typeof XCSSProp<'background' | 'color', '&:hover'>>; | ||
}) { | ||
return <button data-testid="button" className={xcss} css={styles.rootNative} />; | ||
} | ||
|
||
describe('pass-through props.xcss directly to DOM', () => { | ||
it('works with no props.xcss', () => { | ||
const { getByTestId } = render(<NativePassThrough />); | ||
|
||
expect(getByTestId('button')).toHaveCompiledCss({ | ||
color: 'var(--ds-text)', | ||
background: 'var(--ds-surface)', | ||
}); | ||
}); | ||
|
||
it('works with pass-through props.xcss', () => { | ||
const { getByTestId } = render(<NativePassThrough xcss={styles.bold} />); | ||
|
||
expect(getByTestId('button')).toHaveCompiledCss({ | ||
color: 'var(--ds-text-bold)', | ||
background: 'var(--ds-surface)', // rootNative styles | ||
}); | ||
}); | ||
|
||
it('works with pass-through multiple props.xcss via cx', () => { | ||
const { getByTestId } = render(<NativePassThrough xcss={cx(styles.bold, styles.sunken)} />); | ||
|
||
expect(getByTestId('button')).toHaveCompiledCss({ | ||
color: 'var(--ds-text-bold)', | ||
background: 'var(--ds-surface-sunken)', | ||
}); | ||
}); | ||
}); | ||
|
||
describe('pass-through props.xcss via another component', () => { | ||
it('works with no props.xcss', () => { | ||
const { getByTestId } = render(<ComponentPassThrough />); | ||
|
||
expect(getByTestId('button')).toHaveCompiledCss({ | ||
color: 'var(--ds-text-error)', | ||
background: 'var(--ds-surface-overlay)', | ||
}); | ||
}); | ||
|
||
it('works with pass-through props.xcss', () => { | ||
const { getByTestId } = render(<ComponentPassThrough xcss={styles.bold} />); | ||
|
||
expect(getByTestId('button')).toHaveCompiledCss({ | ||
color: 'var(--ds-text-bold)', | ||
background: 'var(--ds-surface-overlay)', // rootComponent styles | ||
}); | ||
}); | ||
|
||
it('works with pass-through multiple props.xcss via cx', () => { | ||
const { getByTestId } = render(<ComponentPassThrough xcss={cx(styles.bold, styles.sunken)} />); | ||
|
||
expect(getByTestId('button')).toHaveCompiledCss({ | ||
color: 'var(--ds-text-bold)', | ||
background: 'var(--ds-surface-sunken)', | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm worried this doesn't fail tests, not sure how to test this to be honest. I don't think anything is testing this properly (else it would've been failing before).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a setup like that in
packages/react/src/create-strict-api/__tests__/css-func.test.tsx
could work for testing it right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought this would've failed in this test before to be frank:
compiled/packages/react/src/create-strict-api/__tests__/index.test.tsx
Line 526 in 39d9a02
<div className={xcss}>
it wasn't a problem, it's when it's wrapped in<Component xcss={xcss}>
it becomes a problem…?Added tests in f0f1899 and can confirm, without this
ax
diff it breaks: