Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: isPlainObject incorrectly identifies objects wrapped in a Proxy object in Safari 10 #1379

Merged
merged 1 commit into from
May 30, 2023

Conversation

reed-soul
Copy link
Contributor

Hi there!

I noticed that in Safari 10, the isPlainObject method used in vue-i18n can lead to an issue where objects wrapped in a Proxy object, such as those returned by the ref method in Vue, are incorrectly identified as non-plain objects. This can result in an empty messages object and the inability to retrieve localized content.

To address this issue, I propose changing the isPlainObject method used in vue-i18n to use 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.

Here's the updated code for the isPlainObject method:

function isPlainObject(obj) {
  if (typeof obj !== 'object' || obj === null) return false
  const proto = Object.getPrototypeOf(obj)
  return proto === null || proto.constructor === Object
}

This change should resolve the issue in Safari 10 and ensure that objects wrapped in a Proxy object are correctly identified as plain objects.

Please let me know if you have any questions or concerns. Thanks for considering this PR!

Best regards

closes(#1378)

Copy link
Member

@kazupon kazupon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for my late reply!
Good contribution!
Thanks!

@kazupon kazupon merged commit 0a6b897 into intlify:master May 30, 2023
@kazupon kazupon added the Type: Bug Bug or Bug fixes label May 30, 2023
BobbieGoede added a commit to BobbieGoede/vue-i18n-next that referenced this pull request Sep 15, 2024
kazupon pushed a commit that referenced this pull request Sep 15, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Type: Bug Bug or Bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants