fix: messages deepCopy mutates src arguments#1947
Conversation
@intlify/core
@intlify/devtools-types
@intlify/core-base
@intlify/message-compiler
@intlify/shared
petite-vue-i18n
vue-i18n
@intlify/vue-i18n-core
commit: |
|
I'm curious what the impact of this change is on performance since previously the objects assigned by reference were not looped over by key. |
|
Yeah, performance is certainly a concern, and I need to look at the cost of |
|
Somewhat related to performance and object checks (but not really related to this PR), I feel like #1379 should be reverted. The change was made to support Safari 10 which is not receiving security updates (Apple doesn't issue EOL dates), the original code seems to work fine for Vue core https://github.com/vuejs/core/blob/main/packages/shared/src/general.ts#L74-L75 and is likely more performant as well. |
Let's do it! |
9f3bb87 to
05b2353
Compare
I tried bench testing the change and it looks like it does impact performance but not excessively so, it's worth the trade-off. The way I tested it is not pretty so I pushed it to a separate branch, you can check out the changes and results in this PR BobbieGoede#5, I'm assuming we don't want to add a bench like this. |
|
Thanks! |
* fix: messages `deepCopy` mutates `src` arguments * fix: `deepCopy` should never merge arrays
* fix: messages `deepCopy` mutates `src` arguments * fix: `deepCopy` should never merge arrays
Important
This has not been thoroughly tested but should demonstrate the issue with
deepCopyCurrently during
deepCopyif a key is unset, it will be assigned to the value of thesrc[key], this is an issue for objects as they will be assigned by reference, meaning following calls todeepCopywill assign properties on these objects.So far a simple solution seems to be to set the property value to an empty object/array, this ensures both
src[key]anddes[key]are objects meaningdeepCopywill merge these as such instead of direct assignment.I've had this saved in a git stash for some time so it has been a while since debugging this issue, I'm opening this PR so I won't forget about it again 😅
nuxt-modules/i18n#3089
nuxt-modules/i18n#2803