E2E_TIMEOUT,
)
- test.todo(
+ test(
'transition on appear with v-show',
async () => {
const btnSelector = '.show-appear > button'
const containerSelector = '.show-appear > div'
const childSelector = `${containerSelector} > div`
+
+ let calls = await page().evaluate(() => {
+ return (window as any).getCalls('showAppear')
+ })
+ expect(calls).toStrictEqual(['beforeEnter', 'onEnter'])
+
+ // appear
+ expect(await classList(childSelector)).contains('test-appear-active')
+
+ await transitionFinish()
+ expect(await html(containerSelector)).toBe(
+ '<div class="test">content</div>',
+ )
+ calls = await page().evaluate(() => {
+ return (window as any).getCalls('showAppear')
+ })
+ expect(calls).toStrictEqual(['beforeEnter', 'onEnter', 'afterEnter'])
+
+ // leave
+ expect(
+ (await transitionStart(btnSelector, childSelector)).classNames,
+ ).toStrictEqual(['test', 'test-leave-from', 'test-leave-active'])
+ await nextFrame()
+ expect(await classList(childSelector)).toStrictEqual([
+ 'test',
+ 'test-leave-active',
+ 'test-leave-to',
+ ])
+ await transitionFinish()
+ expect(await isVisible(childSelector)).toBe(false)
+
+ // enter
+ expect(
+ (await transitionStart(btnSelector, childSelector)).classNames,
+ ).toStrictEqual(['test', 'test-enter-from', 'test-enter-active'])
+ await nextFrame()
+ expect(await classList(childSelector)).toStrictEqual([
+ 'test',
+ 'test-enter-active',
+ 'test-enter-to',
+ ])
+ await transitionFinish()
+ expect(await html(containerSelector)).toBe(
+ '<div class="test" style="">content</div>',
+ )
},
E2E_TIMEOUT,
)
- test.todo(
+ test(
'transition events should not call onEnter with v-show false',
- async () => {},
+ async () => {
+ const btnSelector = '.show-appear-not-enter > button'
+ const containerSelector = '.show-appear-not-enter > div'
+ const childSelector = `${containerSelector} > div`
+
+ expect(await isVisible(childSelector)).toBe(false)
+ let calls = await page().evaluate(() => {
+ return (window as any).getCalls('notEnter')
+ })
+ expect(calls).toStrictEqual([])
+
+ // enter
+ expect(
+ (await transitionStart(btnSelector, childSelector)).classNames,
+ ).toStrictEqual(['test', 'test-enter-from', 'test-enter-active'])
+ calls = await page().evaluate(() => {
+ return (window as any).getCalls('notEnter')
+ })
+ expect(calls).toStrictEqual(['beforeEnter', 'onEnter'])
+ await nextFrame()
+ expect(await classList(childSelector)).toStrictEqual([
+ 'test',
+ 'test-enter-active',
+ 'test-enter-to',
+ ])
+ calls = await page().evaluate(() => {
+ return (window as any).getCalls('notEnter')
+ })
+ expect(calls).not.contain('afterEnter')
+ await transitionFinish()
+ expect(await html(containerSelector)).toBe(
+ '<div class="test" style="">content</div>',
+ )
+ calls = await page().evaluate(() => {
+ return (window as any).getCalls('notEnter')
+ })
+ expect(calls).toStrictEqual(['beforeEnter', 'onEnter', 'afterEnter'])
+ },
E2E_TIMEOUT,
)
-
- test.todo('transition on appear with v-show', async () => {}, E2E_TIMEOUT)
})
describe('explicit durations', () => {
show: [],
showLeaveCancel: [],
showAppear: [],
+ notEnter: [],
}
window.getCalls = key => calls[key]
window.resetCalls = key => (calls[key] = [])
</div>
<button @click="toggle = !toggle">button</button>
</div>
+ <div class="show-appear-not-enter">
+ <div>
+ <transition
+ name="test"
+ appear
+ @beforeEnter="() => calls.notEnter.push('beforeEnter')"
+ @enter="() => calls.notEnter.push('onEnter')"
+ @afterEnter="() => calls.notEnter.push('afterEnter')"
+ >
+ <div v-show="!toggle" class="test">content</div>
+ </transition>
+ </div>
+ <button @click="toggle = !toggle">button</button>
+ </div>
<!-- work with vshow end -->
<!-- explicit durations -->
describe('compiler: transition', () => {
test('basic', () => {
+ const { code } = compileWithElementTransform(
+ `<Transition><h1 v-show="show">foo</h1></Transition>`,
+ )
+ expect(code).toMatchSnapshot()
+ })
+
+ test('v-show + appear', () => {
const { code } = compileWithElementTransform(
`<Transition appear><h1 v-show="show">foo</h1></Transition>`,
)
const t0 = _template("<h1>foo</h1>")
export function render(_ctx) {
- const n1 = _createComponent(_VaporTransition, {
- appear: () => (""),
- persisted: () => ("")
- }, {
+ const n1 = _createComponent(_VaporTransition, { persisted: () => ("") }, {
"default": () => {
const n0 = t0()
_applyVShow(n0, () => (_ctx.show))
}"
`;
+exports[`compiler: transition > v-show + appear 1`] = `
+"import { VaporTransition as _VaporTransition, applyVShow as _applyVShow, createComponent as _createComponent, template as _template } from 'vue';
+const t0 = _template("<h1>foo</h1>")
+
+export function render(_ctx) {
+ const lazyApplyVShowFn = []
+ const n1 = _createComponent(_VaporTransition, {
+ appear: () => (""),
+ persisted: () => ("")
+ }, {
+ "default": () => {
+ const n0 = t0()
+ lazyApplyVShowFn.push(() => _applyVShow(n0, () => (_ctx.show)))
+ return n0
+ }
+ }, true)
+ lazyApplyVShowFn.forEach(fn => fn())
+ return n1
+}"
+`;
+
exports[`compiler: transition > work with dynamic keyed children 1`] = `
"import { VaporTransition as _VaporTransition, createKeyedFragment as _createKeyedFragment, createComponent as _createComponent, template as _template } from 'vue';
const t0 = _template("<h1>foo</h1>")
const { dynamic, effect, operation, returns, key } = block
const resetBlock = context.enterBlock(block)
+ if (block.hasLazyApplyVShow) {
+ push(NEWLINE, `const lazyApplyVShowFn = []`)
+ }
+
if (root) {
genResolveAssets('component', 'resolveComponent')
genResolveAssets('directive', 'resolveDirective')
push(...genOperations(operation, context))
push(...genEffects(effect, context))
+ if (block.hasLazyApplyVShow) {
+ push(NEWLINE, `lazyApplyVShowFn.forEach(fn => fn())`)
+ }
+
if (dynamic.needsKey) {
for (const child of dynamic.children) {
const keyValue = key
oper: DirectiveIRNode,
context: CodegenContext,
): CodeFragment[] {
+ const { lazy, element } = oper
return [
NEWLINE,
- ...genCall(context.helper('applyVShow'), `n${oper.element}`, [
+ lazy ? `lazyApplyVShowFn.push(() => ` : undefined,
+ ...genCall(context.helper('applyVShow'), `n${element}`, [
`() => (`,
...genExpression(oper.dir.exp!, context),
`)`,
]),
+ lazy ? `)` : undefined,
]
}
operation: OperationNode[]
expressions: SimpleExpressionNode[]
returns: number[]
+ hasLazyApplyVShow: boolean
}
export interface RootIRNode {
builtin?: boolean
asset?: boolean
modelType?: 'text' | 'dynamic' | 'radio' | 'checkbox' | 'select'
+ lazy?: boolean
}
export interface CreateComponentIRNode extends BaseIRNode {
returns: [],
expressions: [],
tempId: 0,
+ hasLazyApplyVShow: false,
})
export function wrapTemplate(node: ElementNode, dirs: string[]): TemplateNode {
DOMErrorCodes,
ElementTypes,
ErrorCodes,
+ NodeTypes,
createCompilerError,
createDOMCompilerError,
} from '@vue/compiler-dom'
import type { DirectiveTransform } from '../transform'
import { IRNodeTypes } from '../ir'
+import { findProp, isTransitionTag } from '../utils'
export const transformVShow: DirectiveTransform = (dir, node, context) => {
const { exp, loc } = dir
return
}
+ // lazy apply vshow if the node is inside a transition with appear
+ let lazyApplyVShow = false
+ const parentNode = context.parent && context.parent.node
+ if (parentNode && parentNode.type === NodeTypes.ELEMENT) {
+ lazyApplyVShow = !!(
+ isTransitionTag(parentNode.tag) &&
+ findProp(parentNode, 'appear', false, true)
+ )
+
+ if (lazyApplyVShow) {
+ context.parent!.parent!.block.hasLazyApplyVShow = true
+ }
+ }
+
context.registerOperation({
type: IRNodeTypes.DIRECTIVE,
element: context.reference(),
dir,
name: 'show',
builtin: true,
+ lazy: lazyApplyVShow,
})
}
el.style.display = el[vShowOriginalDisplay]!
$transition.enter(target)
} else {
- $transition.leave(target, () => {
+ // during initial render, the element is not yet inserted into the
+ // DOM, and it is hidden, no need to trigger transition
+ if (target.isConnected) {
+ $transition.leave(target, () => {
+ el.style.display = 'none'
+ })
+ } else {
el.style.display = 'none'
- })
+ }
}
} else {
el.style.display = value ? el[vShowOriginalDisplay]! : 'none'