-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Order of setup vs beforeCreate not consistent with Vue 3 behavior #12802
Comments
I guess it might be in Vue2.x, the mixin hooks is always called before component hooks. setup hooks is a component hooks. |
@ccrcw1314 while that is true - mixin hooks fire before component hooks, I believe that applies for hooks of the same type. I updated both codepen links in the issue report to have beforeCreate hooks in both the components and the mixin to demonstrate. Vue 3 fires them like this: setup→beforeCreate(mixin)→beforeCreate(component) |
Unfortunately making the order consistent with Vue 3 can cause unintended breakage. (See #12821 / #12822) Root cause is that Vue 3 doesn't have this problem because Vue 3 props default initializer functions do not have access to |
Version
2.7.10
Reproduction link
codepen.io
Steps to reproduce
Run the linked codepen with console open.
What is expected?
setup
function from the component to be called beforebeforeCreate
hook from the mixin as it is in Vue 3What is actually happening?
beforeCreate
function from the mixin is being called before thesetup
function from the componentVue 3 lifecycle diagram shows
setup
being called beforebeforeCreate
. Vue 2 diagram does not make any mention of thesetup
function. I would expect that the order ofsetup
vsbeforeCreate
would be consistent between 2.7 and 3.x.Minimal reproduction repo to observe vue 3 behavior: https://codepen.io/vetruvet/pen/LYmePyN
Why a mixin and why
beforeCreate
? This behavior is coming from a third-party library I don't control. The code I need to run in thesetup
function needs to access variables that are only available in the setup function and at the same time needs to run before that 3rd-party code in thebeforeCreate
hook.Looking at the where the hooks are called,
beforeCreate
is indeed called beforesetup
(https://github.com/vuejs/vue/blob/v2.7.10/src/core/instance/init.ts#L62 and two lines downinitState
callsinitSetup
)The text was updated successfully, but these errors were encountered: