Order of setup vs beforeCreate not consistent with Vue 3 behavior

This issue has been created since 2022-09-26.



Reproduction link


Steps to reproduce

Run the linked codepen with console open.

What is expected?

setup function from the component to be called before beforeCreate hook from the mixin as it is in Vue 3

What is actually happening?

beforeCreate function from the mixin is being called before the setup function from the component

Vue 3 lifecycle diagram shows setup being called before beforeCreate. Vue 2 diagram does not make any mention of the setup function. I would expect that the order of setup vs beforeCreate 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 the setup 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 the beforeCreate hook.

Looking at the where the hooks are called, beforeCreate is indeed called before setup (https://github.com/vuejs/vue/blob/v2.7.10/src/core/instance/init.ts#L62 and two lines down initState calls initSetup)

ccrcw1314 wrote this answer on 2022-09-27

I guess it might be in Vue2.x, the mixin hooks is always called before component hooks. setup hooks is a component hooks.

vetruvet wrote this answer on 2022-09-29

@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)
Vue 2 fires them like this: beforeCreate(mixin)→beforeCreate(component)→setup

yyx990803 wrote this answer on 2022-10-15

Unfortunately making the order consistent with Vue 3 can cause unintended breakage. (See #12821 / #12822)

Root cause is that setup() requires props to be resolved first, however in Vue 2, props default initializer functions have access to this, and some users rely on properties injected from global beforeCreate hooks in these functions.

Vue 3 doesn't have this problem because Vue 3 props default initializer functions do not have access to this.

More Details About Repo
Owner Name vuejs
Repo Name vue
Full Name vuejs/vue
Language TypeScript
Created Date 2013-07-29
Updated Date 2022-12-10
Star Count 201155
Watcher Count 6070
Fork Count 33134
Issue Count 595


Issue Title Created Date Comment Count Updated Date
Add Section 10.7 - Permitted Use of 'Microsoft Store Edition' Suffix. 1 2022-10-27 2022-12-02
When I use "docker build" and: "E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?" 4 2022-11-04 2022-11-12
[Feature Request] Ability to map `choose` values to keys 4 2022-07-30 2022-10-28
How does the get user by id work? 3 2021-03-28 2022-05-08
I got error during installaion c1083 2 2018-05-21 2022-11-18
ModuleNotFoundError: No module named 'pycocotools.ytvos' 6 2021-04-13 2022-10-08
Tailwind Integration 0 2022-06-08 2022-10-19
Hey Everyone We are supported emoji or emoji parser? 0 2021-04-09 2022-09-04
[Twig] Support CraftCMS css and js blocks 0 2021-09-03 2022-10-26
Hello Bitcoin Video #4 Jam Session 1 2021-10-07 2022-03-06
Setting environment variables to falsy values (0, empty string, etc) reverts to default value 1 2021-12-08 2022-11-29
Lesson Contribution for #8 Making Packages R 0 2021-05-17 2022-10-31
xs = xs * test_cfg.out_size_factor * test_cfg.voxel_size[0] + test_cfg.pc_range[0] 1 2022-02-16 2022-11-16
Error: ENOENT: no such file or directory, rename gossip.json~ -> gossip.json 2 2020-12-11 2022-10-18
Advection in `ShallowWaterModel` 20 2022-06-23 2022-09-02
Updates with aggregation pipeline 0 2021-06-21 2022-11-23
Diagnostic count summary looks off in some cases 1 2021-11-15 2022-11-03
API Error 400: You have provided fees that do not match any of the collection fees. 1 2022-09-16 2022-11-29
Support EAP-TTLS PAP provisioning for Apple, Windows and Android devices 0 2022-06-17 2022-11-19
会话选择器支持选择所有私聊会话 / 所有群组会话 3 2022-07-17 2022-11-30
'ContractContainer' object has no attribute 'retrieve' 1 2022-02-19 2022-10-15
AmazonEC2FullAccess seems too broad 1 2021-06-02 2022-11-13
Lut 3D module has disappeared 9 2022-05-09 2022-10-24
Add a link to the final version of the project (codesanbox) in "The Project" section of te Homepage 1 2021-02-19 2022-11-21
ServiceWorker: Check for new version on load, and prompt to reload if it can be reached 2 2021-12-28 2022-11-19
google play无法下载app,一直显示等待中 0 2022-02-12 2022-12-03
[Bug] Deleted part of config when applying from Servers and Groups 2 2022-02-12 2022-11-15
MGS:PW - Graphic Bug (Android/Windows) 10 2022-05-02 2022-10-03
Flare Automatic DPI Override (For Windows) 0 2022-02-01 2022-12-01
Okteto doesn't read .dockerignore when building images 2 2022-06-01 2022-07-21
English language selection 0 2021-08-13 2022-12-01
Vulkan: Error spam when mixing Spot and Omni Lights and Shadows 0 2022-01-07 2022-09-16
netron.stop() never returns (Python package) 1 2022-05-18 2022-11-21
How to change admin password? 2 2021-07-10 2022-12-07
Is it possible to set table name for the relation table in m2m2type situation 1 2022-04-12 2022-11-22
help setting up behind alb 2 2021-06-29 2022-11-21
Illegal seek when using stdout as output file for az ssh config 2 2021-11-02 2022-10-25
examples/provisioning/wifi_prov_mgr build error (IDFGH-7822) 1 2022-07-14 2022-11-03
How to compile the viewer on Windows 0 2021-10-06 2022-11-23
How would one use CF env vars to set the apiKey? 0 2022-01-06 2022-11-28
Asset Import Issue w/ Webpack 2 2021-07-28 2022-12-05
Using `router.get` should add a default handler for `router.head` 4 2019-12-18 2022-10-25
How to make a URL to "http://localhost/../.."? 4 2021-03-06 2022-11-06
How to use sqlite database with Osmdroid? 6 2022-03-14 2022-12-07
[Bug] Version increments breaks downstream plugins 0 2022-11-04 2022-11-01
ERR_CONTENT_DECODING_FAILED on user authentication 1 2015-09-12 2022-11-13
Automatically insert page breaks into word documents 0 2022-04-29 2022-09-26
Updated index.html to not have any profanity 0 2018-03-31 2022-12-04
TestVmoduleOn fails on klog 2.10.0 with Golang 1.17rc2 1 2021-08-13 2022-11-28
The "Configure console apps" section doesn't actually say how to use the config 7 2021-11-19 2022-11-01