Skip to content

Commit e80cd09

Browse files
committed
Revert "fix(setup): setup hook should be called before beforeCreate"
This reverts commit e1342df. reopen #12802 close #12821 close #12822
1 parent c61395d commit e80cd09

File tree

3 files changed

+10
-36
lines changed

3 files changed

+10
-36
lines changed

Diff for: src/core/instance/init.ts

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import config from '../config'
22
import { initProxy } from './proxy'
3-
import { initProps, initState } from './state'
3+
import { initState } from './state'
44
import { initRender } from './render'
55
import { initEvents } from './events'
66
import { mark, measure } from '../util/perf'
@@ -10,7 +10,6 @@ import { extend, mergeOptions, formatComponentName } from '../util/index'
1010
import type { Component } from 'types/component'
1111
import type { InternalComponentOptions } from 'types/options'
1212
import { EffectScope } from 'v3/reactivity/effectScope'
13-
import { initSetup } from '../../v3/apiSetup'
1413

1514
let uid = 0
1615

@@ -60,12 +59,8 @@ export function initMixin(Vue: typeof Component) {
6059
initLifecycle(vm)
6160
initEvents(vm)
6261
initRender(vm)
63-
64-
const opts = vm.$options
65-
initInjections(vm) // resolve injections before data/props
66-
initProps(vm, opts.props)
67-
initSetup(vm)
6862
callHook(vm, 'beforeCreate', undefined, false /* setContext */)
63+
initInjections(vm) // resolve injections before data/props
6964
initState(vm)
7065
initProvide(vm) // resolve provide after data/props
7166
callHook(vm, 'created')

Diff for: src/core/instance/state.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import config from '../config'
22
import Watcher from '../observer/watcher'
33
import Dep, { pushTarget, popTarget } from '../observer/dep'
44
import { isUpdatingChildComponent } from './lifecycle'
5+
import { initSetup } from 'v3/apiSetup'
56

67
import {
78
set,
@@ -50,6 +51,11 @@ export function proxy(target: Object, sourceKey: string, key: string) {
5051

5152
export function initState(vm: Component) {
5253
const opts = vm.$options
54+
if (opts.props) initProps(vm, opts.props)
55+
56+
// Composition API
57+
initSetup(vm)
58+
5359
if (opts.methods) initMethods(vm, opts.methods)
5460
if (opts.data) {
5561
initData(vm)
@@ -63,8 +69,7 @@ export function initState(vm: Component) {
6369
}
6470
}
6571

66-
export function initProps(vm: Component, propsOptions: Object | undefined) {
67-
if (!propsOptions) return
72+
function initProps(vm: Component, propsOptions: Object) {
6873
const propsData = vm.$options.propsData || {}
6974
const props = (vm._props = shallowReactive({}))
7075
// cache prop keys so that future props updates can iterate using Array

Diff for: test/unit/features/v3/apiSetup.spec.ts

+1-27
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ describe('api: setup context', () => {
263263
}).$mount()
264264
expect(spy).toHaveBeenCalled()
265265
})
266-
266+
267267
// #12561
268268
it('setup props should be reactive', () => {
269269
const msg = ref('hi')
@@ -333,30 +333,4 @@ describe('api: setup context', () => {
333333
await nextTick()
334334
expect(_listeners.foo()).toBe(2)
335335
})
336-
337-
// #12802
338-
it('should be called before all lifecycle hooks', () => {
339-
const calls: string[] = []
340-
341-
Vue.mixin({
342-
beforeCreate() {
343-
calls.push('global beforeCreate')
344-
}
345-
})
346-
347-
new Vue({
348-
beforeCreate() {
349-
calls.push('component beforeCreate')
350-
},
351-
setup() {
352-
calls.push('setup')
353-
}
354-
})
355-
356-
expect(calls).toEqual([
357-
'setup',
358-
'global beforeCreate',
359-
'component beforeCreate'
360-
])
361-
})
362336
})

0 commit comments

Comments
 (0)