You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Does this case correspond to the content of the following note?
Note that default values for mutable reference types (like arrays or objects) should be wrapped in functions when using withDefaults to avoid accidental modification and external side effects. This ensures each component instance gets its own copy of the default value. This is not necessary when using default values with destructure.
Does this case correspond to the content of the following note?
Note that default values for mutable reference types (like arrays or objects) should be wrapped in functions when using withDefaults to avoid accidental modification and external side effects. This ensures each component instance gets its own copy of the default value. This is not necessary when using default values with destructure.
Yes, The meaning is roughly this: if a function is not used, the default value will be considered to have side effects and will not be tree-shaken. see rollupjs repl. you can try changing the default to a non-function and observe the outputted JS.
Vue version
3.5.13
Link to minimal reproduction
https://stackblitz.com/edit/vitejs-vite-sr5itbdf
Steps to reproduce
npm install
npm run build
NotTreeShaken
component exists indist/assets/index-xxx.js
What is expected?
NotTreeShaken
component is not imported, so it should be tree-shakenWhat is actually happening?
NotTreeShaken
component exists indist/assets/index-xxx.js
System Info
System: OS: Linux 5.0 undefined CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz Memory: 0 Bytes / 0 Bytes Shell: 1.0 - /bin/jsh Binaries: Node: 18.20.3 - /usr/local/bin/node Yarn: 1.22.19 - /usr/local/bin/yarn npm: 10.2.3 - /usr/local/bin/npm pnpm: 8.15.6 - /usr/local/bin/pnpm npmPackages: vue: ^3.5.13 => 3.5.13
Any additional comments?
In the case of
Props Destructure
, it is tree-shaken.In the case of withDefaults, props are compiled as follows:
In the case of Props Destructure, it is compiled as follows:
The text was updated successfully, but these errors were encountered: