Skip to content

Commit ecef92b

Browse files
committed
wip: handle fallthrough attrs
1 parent c9ee8d1 commit ecef92b

File tree

2 files changed

+42
-18
lines changed

2 files changed

+42
-18
lines changed

packages/runtime-vapor/src/components/Transition.ts

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import {
2222
isFragment,
2323
} from '../block'
2424
import { type VaporComponentInstance, isVaporComponent } from '../component'
25-
import { isArray } from '@vue/shared'
25+
import { extend, isArray } from '@vue/shared'
2626
import { renderEffect } from '../renderEffect'
2727
import { setDynamicProps } from '../dom/prop'
2828

@@ -34,10 +34,11 @@ const decorate = (t: typeof VaporTransition) => {
3434
}
3535

3636
export const VaporTransition: FunctionalComponent<TransitionProps> =
37-
/*@__PURE__*/ decorate((props, { slots }) => {
37+
/*@__PURE__*/ decorate((props, { slots, attrs }) => {
3838
const children = (slots.default && slots.default()) as any as Block
3939
if (!children) return
4040

41+
const instance = currentInstance! as VaporComponentInstance
4142
const { mode } = props
4243
checkTransitionMode(mode)
4344

@@ -48,27 +49,45 @@ export const VaporTransition: FunctionalComponent<TransitionProps> =
4849
if (isMounted) {
4950
// only update props for Fragment block, for later reusing
5051
if (isFragment(children)) {
51-
if (children.$transition) {
52-
children.$transition.props = resolvedProps
53-
}
52+
children.$transition!.props = resolvedProps
5453
} else {
55-
// replace existing transition hooks
5654
const child = findTransitionBlock(children)
57-
if (child && child.$transition) {
58-
child.$transition.props = resolvedProps
59-
applyTransitionHooks(child, child.$transition)
55+
if (child) {
56+
// replace existing transition hooks
57+
child.$transition!.props = resolvedProps
58+
applyTransitionHooks(child, child.$transition!)
6059
}
6160
}
6261
} else {
6362
isMounted = true
6463
}
6564
})
6665

67-
applyTransitionHooks(children, {
68-
state: useTransitionState(),
69-
props: resolvedProps!,
70-
instance: currentInstance!,
71-
} as VaporTransitionHooks)
66+
// fallthrough attrs
67+
let fallthroughAttrs = true
68+
if (instance.hasFallthrough) {
69+
renderEffect(() => {
70+
// attrs are accessed in advance
71+
const resolvedAttrs = extend({}, attrs)
72+
const child = findTransitionBlock(children)
73+
if (child) {
74+
setDynamicProps(child, [resolvedAttrs])
75+
// ensure fallthrough attrs are not happened again in
76+
// applyTransitionHooks
77+
fallthroughAttrs = false
78+
}
79+
})
80+
}
81+
82+
applyTransitionHooks(
83+
children,
84+
{
85+
state: useTransitionState(),
86+
props: resolvedProps!,
87+
instance: instance,
88+
} as VaporTransitionHooks,
89+
fallthroughAttrs,
90+
)
7291

7392
return children
7493
})
@@ -164,7 +183,6 @@ export function applyTransitionHooks(
164183
setTransitionHooks(child, resolvedHooks)
165184
if (isFrag) setTransitionHooksToFragment(block, resolvedHooks)
166185

167-
// TODO handle attrs update
168186
// fallthrough attrs
169187
if (fallthroughAttrs && instance.hasFallthrough) {
170188
setDynamicProps(child, [instance.attrs])

packages/runtime-vapor/src/components/TransitionGroup.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ import {
2828
setTransitionHooks,
2929
setTransitionHooksToFragment,
3030
} from './Transition'
31-
import { type ObjectVaporComponent, isVaporComponent } from '../component'
31+
import {
32+
type ObjectVaporComponent,
33+
type VaporComponentInstance,
34+
isVaporComponent,
35+
} from '../component'
3236
import { isForBlock } from '../apiCreateFor'
3337
import { renderEffect, setDynamicProps } from '@vue/runtime-vapor'
3438

@@ -50,7 +54,7 @@ export const VaporTransitionGroup: ObjectVaporComponent = decorate({
5054
}),
5155

5256
setup(props: TransitionGroupProps, { slots }) {
53-
const instance = currentInstance
57+
const instance = currentInstance as VaporComponentInstance
5458
const state = useTransitionState()
5559
const cssTransitionProps = resolveTransitionProps(props)
5660

@@ -144,7 +148,9 @@ export const VaporTransitionGroup: ObjectVaporComponent = decorate({
144148
const container = document.createElement(tag)
145149
insert(slottedBlock, container)
146150
// fallthrough attrs
147-
renderEffect(() => setDynamicProps(container, [instance!.attrs]))
151+
if (instance!.hasFallthrough) {
152+
renderEffect(() => setDynamicProps(container, [instance!.attrs]))
153+
}
148154
return container
149155
} else {
150156
const frag = __DEV__

0 commit comments

Comments
 (0)