Skip to content

Commit 8498ba6

Browse files
Doctor-wusxzz
authored andcommitted
feat(runtime-vapor): update attrs when props update
1 parent 2db5e19 commit 8498ba6

File tree

3 files changed

+65
-6
lines changed

3 files changed

+65
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import {
2+
createComponent,
3+
defineComponent,
4+
getCurrentInstance,
5+
nextTick,
6+
ref,
7+
setText,
8+
template,
9+
toRefs,
10+
watch,
11+
watchEffect,
12+
} from '../src'
13+
import { setCurrentInstance } from '../src/component'
14+
import { makeRender } from './_utils'
15+
16+
const define = makeRender<any>()
17+
18+
describe('attribute fallthrough', () => {
19+
it('should allow attrs to fallthrough', async () => {
20+
const t0 = template('<div>')
21+
const { component: Child } = define({
22+
props: ['foo'],
23+
render() {
24+
const instance = getCurrentInstance()!
25+
const n0 = t0()
26+
watchEffect(() => setText(n0, instance.props.foo))
27+
return n0
28+
},
29+
})
30+
31+
const foo = ref(1)
32+
const id = ref('a')
33+
const { instance, host } = define({
34+
setup() {
35+
return { foo, id }
36+
},
37+
render(_ctx: Record<string, any>) {
38+
return createComponent(Child, {
39+
foo: () => _ctx.foo,
40+
id: () => _ctx.id,
41+
})
42+
},
43+
}).render()
44+
const reset = setCurrentInstance(instance)
45+
expect(host.innerHTML).toBe('<div id="a">1</div>')
46+
47+
foo.value++
48+
await nextTick()
49+
expect(host.innerHTML).toBe('<div id="a">2</div>')
50+
51+
id.value = 'b'
52+
await nextTick()
53+
expect(host.innerHTML).toBe('<div id="b">2</div>')
54+
reset()
55+
})
56+
})

packages/runtime-vapor/__tests__/componentProps.spec.ts

-3
Original file line numberDiff line numberDiff line change
@@ -246,17 +246,14 @@ describe('component: props', () => {
246246
},
247247
}).render()
248248
const reset = setCurrentInstance(instance)
249-
// expect(host.innerHTML).toBe('<div id="a">1</div>') // TODO: Fallthrough Attributes
250249
expect(host.innerHTML).toBe('<div>1</div>')
251250

252251
foo.value++
253252
await nextTick()
254-
// expect(host.innerHTML).toBe('<div id="a">2</div>') // TODO: Fallthrough Attributes
255253
expect(host.innerHTML).toBe('<div>2</div>')
256254

257255
id.value = 'b'
258256
await nextTick()
259-
// expect(host.innerHTML).toBe('<div id="b">2</div>') // TODO: Fallthrough Attributes
260257
reset()
261258
})
262259

packages/runtime-vapor/src/apiRender.ts

+9-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { isArray, isFunction, isObject } from '@vue/shared'
22
import { type ComponentInternalInstance, setCurrentInstance } from './component'
33
import { insert, querySelector, remove } from './dom/element'
4-
import { flushPostFlushCbs, queuePostRenderEffect } from './scheduler'
5-
import { proxyRefs } from '@vue/reactivity'
4+
import {
5+
createVaporPreScheduler,
6+
flushPostFlushCbs,
7+
queuePostRenderEffect,
8+
} from './scheduler'
9+
import { baseWatch, proxyRefs } from '@vue/reactivity'
610
import { invokeLifecycle } from './componentLifecycle'
711
import { VaporLifecycleHooks } from './apiLifecycle'
812
import { fallThroughAttrs } from './componentAttrs'
@@ -50,7 +54,9 @@ export function setupComponent(instance: ComponentInternalInstance): void {
5054
}
5155
instance.block = block
5256
if (instance.inheritAttrs !== false) {
53-
fallThroughAttrs(instance)
57+
baseWatch(() => fallThroughAttrs(instance), undefined, {
58+
scheduler: createVaporPreScheduler(instance),
59+
})
5460
}
5561
return block
5662
})

0 commit comments

Comments
 (0)