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
I encountered a bug in vue-i18n that occurs in Safari 10. Specifically, the isPlainObject method used in vue-i18n incorrectly identifies objects wrapped in a Proxy object as non-plain objects, leading to an empty messages object and the inability to retrieve localized content.
To reproduce the issue, I created a simple Vue app that uses vue-i18n to load localized content from a messages object. The messages object was created using the ref method in Vue to wrap a plain object. When running the app in Safari 10, the messages object is incorrectly identified as a non-plain object, resulting in an empty messages object and no localized content.
I believe the issue is caused by the use of the Object.prototype.toString method to check if an object is a plain object in the isPlainObject method in vue-i18n. This method does not correctly identify objects wrapped in a Proxy object as plain objects in Safari 10.
To fix the issue, I suggest updating the isPlainObject method in vue-i18n to use the Object.prototype.constructor property to check if an object is a plain object. This method correctly identifies objects wrapped in a Proxy object as plain objects in all browsers, including Safari 10.
The suggested isPlainObject method, uses the Object.prototype.constructor property to check if an object is a plain object. This method is more reliable and performs well in all browsers, including Safari 10. It correctly identifies objects wrapped in a Proxy object as plain objects, which ensures that localized content can be retrieved correctly.
I hope this explanation helps!
I would be happy to contribute a fix for this issue if needed. Please let me know if you have any questions or if there is anything else I can provide to help resolve this issue.
Reporting a bug?
Hi there,
I encountered a bug in
vue-i18n
that occurs in Safari 10. Specifically, theisPlainObject
method used invue-i18n
incorrectly identifies objects wrapped in aProxy
object as non-plain objects, leading to an emptymessages
object and the inability to retrieve localized content.To reproduce the issue, I created a simple Vue app that uses
vue-i18n
to load localized content from amessages
object. Themessages
object was created using theref
method in Vue to wrap a plain object. When running the app in Safari 10, themessages
object is incorrectly identified as a non-plain object, resulting in an emptymessages
object and no localized content.I believe the issue is caused by the use of the
Object.prototype.toString
method to check if an object is a plain object in theisPlainObject
method invue-i18n
. This method does not correctly identify objects wrapped in aProxy
object as plain objects in Safari 10.To fix the issue, I suggest updating the
isPlainObject
method invue-i18n
to use theObject.prototype.constructor
property to check if an object is a plain object. This method correctly identifies objects wrapped in aProxy
object as plain objects in all browsers, including Safari 10.Behavior of Object.prototype.toString in safari10
As shown in the figure
The following methods are recommended
I would like to recommend using the following
isPlainObject
method instead of the existing method invue-i18n
:The suggested
isPlainObject
method, uses theObject.prototype.constructor
property to check if an object is a plain object. This method is more reliable and performs well in all browsers, including Safari 10. It correctly identifies objects wrapped in aProxy
object as plain objects, which ensures that localized content can be retrieved correctly.I hope this explanation helps!
I would be happy to contribute a fix for this issue if needed. Please let me know if you have any questions or if there is anything else I can provide to help resolve this issue.
Best regards
Expected behavior
import {ref) from 'vue'
const messages = ref(localMessages)
isPlainObject(messages) === true
isPlainObject(new Proxy({},{}) === true
Reproduction
https://stackblitz.com/edit/vitejs-vite-blg7r3?file=src/App.vue
System Info
Screenshot
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: