Skip to content

fix: isObject and isArray not working in V8 isolates#75

Open
luke07758 wants to merge 1 commit intomuratgozel:masterfrom
luke07758:master
Open

fix: isObject and isArray not working in V8 isolates#75
luke07758 wants to merge 1 commit intomuratgozel:masterfrom
luke07758:master

Conversation

@luke07758
Copy link
Copy Markdown

The v.constructor === Object and v.constructor === Array conditions do not work as expected when using V8 isolates. Using the setSender and setTo functions (from "mimetext/browser") resulted in errors on Next.js server components with edge runtime. Upon debugging, the aforementioned conditions were evaluating to false despite passing objects and strings exactly as described in the docs.

I believe the issue is due to the object/string being passed in from a different context which leads to it having a different reference, causing that condition to be false.

I replaced the object condition with Object.prototype.toString.call(v) === '[object Object]' as this works across contexts and will not have false positives on Array, Date, etc. (I assumed only plain objects should be accepted here)

As for the Array comparison, Array.isArray(v) works perfectly fine, and I removed the isArray function as checking !!v is redundant when using the built-in function for this.

With these changes, there are no errors when running in V8 isolates.

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.

1 participant