Skip to content

Commit

Permalink
fix(unhead): style side effect not clearing
Browse files Browse the repository at this point in the history
Fixes #357
  • Loading branch information
harlan-zw committed Jun 20, 2024
1 parent c0ca0c1 commit baf8bc9
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/dom/src/renderDOMHead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export async function renderDOMHead<T extends Unhead<any>>(head: T, options: Ren
// style attributes have their own side effects to allow for merging
for (const c of (value || '').split(';').filter(Boolean)) {
const [k, ...v] = c.split(':').map(s => s.trim())
track(id, `${ck}:${c}:${k}`, () => {
track(id, `${ck}:${k}`, () => {
($el as any as ElementCSSInlineStyle).style.removeProperty(k)
})
;($el as any as ElementCSSInlineStyle).style.setProperty(k, v.join(':'))
Expand Down
49 changes: 49 additions & 0 deletions test/unhead/dom/styles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,55 @@ describe('styles', () => {
</body></html>"
`)
})
it('overrides', async () => {
useDOMHead()

useHead({
bodyAttrs: {
style: '--c-bg: #03D57E;--c-text: #000;',
},
})

const el = useHead({
bodyAttrs: {
style: '--c-bg: #000;--c-text: white;',
},
})

activeDom?.window.document.documentElement.style.setProperty('--header-height', '50px')

expect(await useDelayedSerializedDom()).toMatchInlineSnapshot(`
"<!DOCTYPE html><html style="--header-height: 50px;"><head>
</head>
<body style="--c-bg: #000; --c-text: white;">
<div>
<h1>hello world</h1>
</div>
</body></html>"
`)

el.dispose()

expect(await useDelayedSerializedDom()).toMatchInlineSnapshot(`
"<!DOCTYPE html><html style="--header-height: 50px;"><head>
</head>
<body style="--c-bg: #03D57E; --c-text: #000;">
<div>
<h1>hello world</h1>
</div>
</body></html>"
`)
})
Expand Down

0 comments on commit baf8bc9

Please sign in to comment.