Skip to content

Commit c88e45b

Browse files
committed
fix(css): stop inlining duplicate props by default
fixes issues in places where tailwind-merge cannot work, like a no-underline component that gets [text-decoration:underline]
1 parent 4625f38 commit c88e45b

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/components/Layout.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ const htmlXmlns = computed(() => outlookFallback ? {
134134
:lang="lang"
135135
:dir="dir"
136136
style="font-size: medium;"
137+
data-juice-duplicates
137138
v-bind="{ ...attrs, class: undefined }"
138139
:class="articleMergedClass"
139140
>

src/tests/transformers/inlineCss.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,25 @@ describe('inlineCss', () => {
9797
})
9898
})
9999

100+
describe('inlineDuplicateProperties', () => {
101+
const html = '<style>.a { font-size: medium; } .b { font-size: max(16px, 1rem); }</style><p class="a b">x</p>'
102+
103+
it('collapses duplicate properties to a single declaration by default', () => {
104+
const result = run(html)
105+
expect(result.match(/font-size:/g)).toHaveLength(1)
106+
expect(result).toMatch(/font-size: max\(16px, ?1rem\)/)
107+
expect(result).not.toContain('font-size: medium')
108+
})
109+
110+
it('keeps duplicates when data-juice-duplicates is present on the element', () => {
111+
const marked = '<style>.a { font-size: medium; } .b { font-size: max(16px, 1rem); }</style><p class="a b" data-juice-duplicates>x</p>'
112+
const result = run(marked)
113+
expect(result.match(/font-size:/g)).toHaveLength(2)
114+
expect(result).toContain('font-size: medium')
115+
expect(result).toMatch(/font-size: max\(16px, ?1rem\)/)
116+
})
117+
})
118+
100119
describe('codeBlocks', () => {
101120
it('ignores EJS code blocks by default', () => {
102121
const html = '<style>.red { color: <%= colorVar %>; }</style><p class="red">Text</p>'

src/transformers/inlineCss.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ export function inlineCssDom(dom: ChildNode[], options: InlineCssOptions = {}):
162162
applyHeightAttributes: juicePassthrough.applyHeightAttributes ?? true,
163163
preservedSelectors: safelist ?? [],
164164
...customCSS ? { extraCss: customCSS } : {},
165-
inlineDuplicateProperties: juicePassthrough.inlineDuplicateProperties ?? true,
165+
inlineDuplicateProperties: juicePassthrough.inlineDuplicateProperties ?? false,
166166
...juicePassthrough,
167167
}
168168

0 commit comments

Comments
 (0)