Skip to content

Commit 24bab94

Browse files
committed
wip: staticStyle and staticClass
1 parent 62bfdae commit 24bab94

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

packages/runtime-core/src/compat/__tests__/renderFn.spec.ts

+29
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,35 @@ describe('compat: render function', () => {
6060
})
6161
})
6262

63+
test('staticClass + class', () => {
64+
expect(
65+
h('div', {
66+
class: { foo: true },
67+
staticClass: 'bar'
68+
})
69+
).toMatchObject({
70+
props: {
71+
class: 'bar foo'
72+
}
73+
})
74+
})
75+
76+
test('staticStyle + style', () => {
77+
expect(
78+
h('div', {
79+
style: { color: 'red' },
80+
staticStyle: { fontSize: '14px' }
81+
})
82+
).toMatchObject({
83+
props: {
84+
style: {
85+
color: 'red',
86+
fontSize: '14px'
87+
}
88+
}
89+
})
90+
})
91+
6392
test('on / nativeOn', () => {
6493
const fn = () => {}
6594
expect(

packages/runtime-core/src/compat/renderFn.ts

+21-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import {
22
extend,
33
isArray,
44
isObject,
5+
normalizeClass,
6+
normalizeStyle,
57
ShapeFlags,
68
toHandlerKey
79
} from '@vue/shared'
@@ -141,7 +143,13 @@ export function compatH(
141143
}
142144
}
143145

144-
function convertLegacyProps(legacyProps?: LegacyVNodeProps): Data & VNodeProps {
146+
function convertLegacyProps(
147+
legacyProps?: LegacyVNodeProps
148+
): Data & VNodeProps | null {
149+
if (!legacyProps) {
150+
return null
151+
}
152+
145153
const converted: Data & VNodeProps = {}
146154

147155
for (const key in legacyProps) {
@@ -159,11 +167,22 @@ function convertLegacyProps(legacyProps?: LegacyVNodeProps): Data & VNodeProps {
159167
: incoming
160168
}
161169
}
162-
} else {
170+
} else if (
171+
key !== 'refInFor' &&
172+
key !== 'staticStyle' &&
173+
key !== 'staticClass'
174+
) {
163175
converted[key] = legacyProps[key as keyof LegacyVNodeProps]
164176
}
165177
}
166178

179+
if (legacyProps.staticClass) {
180+
converted.class = normalizeClass([legacyProps.staticClass, converted.class])
181+
}
182+
if (legacyProps.staticStyle) {
183+
converted.style = normalizeStyle([legacyProps.staticStyle, converted.style])
184+
}
185+
167186
return converted
168187
}
169188

0 commit comments

Comments
 (0)