Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix Compatibility Issue with Object Property Check Update use-draw.ts #708

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

mdqst
Copy link
Contributor

@mdqst mdqst commented Nov 16, 2024

Description:

Fixed an issue in the paths object where Object.hasOwn(paths, defaultLocale) was used to check for the presence of the defaultLocale key. While Object.hasOwn() works in some environments, it is not a standard method in JavaScript and may cause compatibility issues across different platforms or environments.

Issue

The code incorrectly used Object.hasOwn(paths, defaultLocale), which is not part of the standard JavaScript API. The correct and safer method to check for the presence of a key in an object is Object.prototype.hasOwnProperty.call(paths, defaultLocale).

Fix

Replaced Object.hasOwn(paths, defaultLocale) with Object.prototype.hasOwnProperty.call(paths, defaultLocale) to ensure compatibility and to follow best practices for property checks in JavaScript.

Importance

This change ensures better cross-environment compatibility, as Object.hasOwn() is not universally supported. Using the standard hasOwnProperty.call() method is a safer and more reliable way to check for the presence of a property in an object. This fix improves code robustness and reduces the risk of runtime errors in different JavaScript environments.

Checklist

  • Do all Lints pass?
    • Have you ran pnpm spellcheck?
    • Have you ran pnpm fmt?
    • Have you ran pnpm lint?

This PR addresses a compatibility issue in the paths object by replacing the non-standard Object.hasOwn() method with the safer and more widely supported Object.prototype.hasOwnProperty.call(). This change ensures better cross-browser and cross-environment compatibility for property existence checks.
Copy link

vercel bot commented Nov 16, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
developer-docs-nextra ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 10, 2024 9:34pm

if (!Object.hasOwn(paths, defaultLocale)) {
if (!Object.prototype.hasOwnProperty.call(paths, defaultLocale)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm interesting, how many browsers wouldn't support hasOwn

This answer on stack overflow points that this is preferred https://stackoverflow.com/questions/69561596/object-hasown-vs-object-prototype-hasownproperty

Seems like most modern browsers support it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants