Skip to content

Commit

Permalink
fix(core): shortcuts ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Jan 24, 2023
1 parent 507303b commit d1e3e67
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/config.ts
Expand Up @@ -114,7 +114,7 @@ export function resolveConfig<Theme extends {} = {}>(
preflights: mergePresets('preflights'),
autocomplete,
variants: mergePresets('variants').map(normalizeVariant),
shortcuts: resolveShortcuts(mergePresets('shortcuts')),
shortcuts: resolveShortcuts(mergePresets('shortcuts')).reverse(),
extractors,
safelist: mergePresets('safelist'),
}
Expand Down
6 changes: 5 additions & 1 deletion packages/core/src/types.ts
Expand Up @@ -303,7 +303,9 @@ export type ThemeExtender<T> = (theme: T) => void

export interface ConfigBase<Theme extends {} = {}> {
/**
* Rules to generate CSS utilities
* Rules to generate CSS utilities.
*
* Later entries have higher priority.
*/
rules?: Rule<Theme>[]

Expand All @@ -316,6 +318,8 @@ export interface ConfigBase<Theme extends {} = {}> {
/**
* Similar to Windi CSS's shortcuts,
* allows you have create new utilities by combining existing ones.
*
* Later entries have higher priority.
*/
shortcuts?: UserShortcuts<Theme>

Expand Down
6 changes: 3 additions & 3 deletions test/__snapshots__/shortcuts.test.ts.snap
Expand Up @@ -51,9 +51,9 @@ exports[`shortcuts > merge transform-duplicated 1`] = `

exports[`shortcuts > nesting static 1`] = `
"/* layer: shortcuts */
.btn2{margin:0.75rem;margin-left:2.5rem;margin-right:2.5rem;padding-left:0.5rem;padding-right:0.5rem;padding-top:0.75rem;padding-bottom:0.75rem;}
.btn{margin-right:2.5rem;}
.btn1{margin-left:2.5rem;margin-right:2.5rem;}
.btn2{margin:0.75rem;margin-left:2.5rem;margin-right:2rem;padding-left:0.5rem;padding-right:0.5rem;padding-top:0.75rem;padding-bottom:0.75rem;}
.btn{margin-right:2rem;}
.btn1{margin-left:2.5rem;margin-right:2rem;}
@media (min-width: 640px){
.btn2{margin:0.5rem;}
}"
Expand Down
1 change: 1 addition & 0 deletions test/shortcuts.test.ts
Expand Up @@ -18,6 +18,7 @@ describe('shortcuts', () => {
btn2: 'sh1 btn1',
},
{
btn: 'mr-8',
primary: 'text-orange-800 bg-white',
accent: 'text-cyan-800 bg-black',
btn3: 'primary hover:(accent underline) focus:border',
Expand Down

3 comments on commit d1e3e67

@leomp12
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wasn't this a breaking change? 🙃

@antfu
Copy link
Member Author

@antfu antfu commented on d1e3e67 Jan 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Breaking change is relative. Any fix/change can be considered a breaking change if one relies on the behavior of the bug. That said, I considered this a bug, as it deviated from the order of rules. And as the priority of shortcuts was not defined properly.

I am sorry if this ever causes you trouble, but I think this is how things work. Use lock file, testing, changelogs, or other tools to help you capture the change when you upgrade the deps.

@leomp12
Copy link

@leomp12 leomp12 commented on d1e3e67 Jan 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No problem, it was actually easy to identify and I'm not using in production yet.
I just mentioned it in case it was a mistake...
Thank you for the answer!

Please sign in to comment.