Skip to content
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: Enable styling compat mode to ensure proper style merging #2890

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions modules/react/layout/spec/mergeStyles.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ describe('mergeStyles', () => {

expect(screen.getByTestId('base')).toHaveStyle({padding: padding.styleAttribute});
});

it('should allow the cs prop to override base styles', () => {
// Skipping this for now while we enable compat mode to run all the time
it.skip('should allow the cs prop to override base styles', () => {
const overrideStyles = createStyles({
padding: padding.createStyles,
});
Expand Down
11 changes: 8 additions & 3 deletions modules/styling/lib/cs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -694,8 +694,13 @@ export function handleCsProp<
const {cs, style, className, ...restProps} = elemProps;
const instance = getInstance();

// We are going to track if any runtime styles are detected
let shouldRuntimeMergeStyles = false;
// We're seeing style merging issues when using createStyles or createStencil. It only happens when
// every style override of the element uses these utilities and @emotion/react or @emotion/styled is not used on the same element.
// These utilities rely on module execution order and we're having a few reports where modules are possibly executing out of order.
// In order to allow everyone to use createStyles and createStencil without worrying about style merge issues, we're going
// to enable compat mode all the time. We'll look into possible out-of-order execution issues in the future and plan to re-enable
// full static mode (for better performance) once we know why this is happening and have a proper workaround.
let shouldRuntimeMergeStyles = true;

// The order is intentional. The `className` should go first, then the `cs` prop. If we don't do
// runtime merging, this order doesn't actually matter because the browser doesn't care the order
Expand Down Expand Up @@ -891,7 +896,7 @@ function combineClassNames(input: (string | undefined)[]): string {
.filter((s, i, a) => onlyDefined(s) && onlyUnique(s, i, a))
.join(' ');
}

/**
* Creates a reuseable Stencil for styling elements. It takes vars, base styles, modifiers, and
* compound modifiers.
Expand Down
4 changes: 3 additions & 1 deletion modules/styling/spec/cs.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,9 @@ describe('handleCsProp', () => {
expect(screen.getByTestId('base')).toHaveStyle({padding: padding.styleAttribute});
});

it('should allow the cs prop to override base styles', () => {
// While we have compat mode enabled, we'll skip these tests. The class generated comes from emotion and
//we have no way of validating the correct class.
it.skip('should allow the cs prop to override base styles', () => {
const overrideStyles = createStyles({
padding: padding.createStyles,
});
Expand Down
Loading