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
instanceof
doesn't work in middleware v12.2
#38184
Comments
Thanks you @meikidd. Calling // will return false in the middleware
[] instanceof Array
{} instanceof Object
/^hello$/ instanceof RegExp We're working on a fix, but it's a tricky problem, due to the nature of Node.js VM module. |
@feugy FYI, there is a dirty hack for this: Array = [].constructor;
Object = {}.constructor;
RegExp = /^/.constructor; Just prepend this before the code that needs to be executed (instead of replacing the global objects with |
That is... fishy indeed 😅 |
@feugy If the issue only occurs in dev mode, IMHO the hacky workaround should work. Also, per Node.js'
Although it is only used in local developing environment, it is still technically not safe, and also causes behavior mismatches between development and production (just like this issue). But there is an escape hatch. There are ongoing ECMAScript proposals proposal-compartments (currently at stage 1) and proposal-shadowrealm (currently at stage 3 already!) to help developer creating a safe, secure sandbox for executing code! |
Thanks for the pointers on the incoming ECMA proposals. As you said it, edge-runtime is currently for dev only, and is not meant to provide strong isolation. We'll surely revise is in the future, but it is out of scope for now. We did some investigation with @javivelasco about the hack, and unfortunately it's not gonna work.
TLDR; it's fixing
|
Hello, this has been addressed and shipped at Next.js v12.2.3: console.log(request instanceof Object) // true
console.log(response instanceof Object) // true
console.log({} instanceof Object) // true You can see more examples Edge Runtime test suite 🙂 |
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Verify canary release
Provide environment information
What browser are you using? (if relevant)
No response
How are you deploying your application? (if relevant)
No response
Describe the Bug
The
instanceof
operator doesn't work in the new released middleware.Expected Behavior
Expect above example to print "true".
Link to reproduction
https://github.com/meikidd/nextjs-middleware-instanceof
To Reproduce
The text was updated successfully, but these errors were encountered: