GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||
GeezerVison is showing github.com — module: do not check circular dependencies for exported proxies by BridgeAR · Pull Request #33338 · nodejs/node Conversation
Member
In case the exported module is a proxy that has the Fixes: #33334 Signed-off-by: Ruben Bridgewater [email protected] Checklist
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions
richardlau
reviewed
Uh oh!
There was an error while loading. Please reload this page.
rickyes
reviewed
Uh oh!
There was an error while loading. Please reload this page. Uh oh!
There was an error while loading. Please reload this page.
|
There was an error while loading. Please reload this page.
|
I don't really like the direction this is going. Even with these changes it still triggers some traps ( module.exports = new Proxy({}, { get(){ assert.fail(); // Throws here } }); But, in general, altering user's objects is really bad practice. I understand the intention is to help users resolve problems regarding circular dependencies, but it brings the cobra effect. Consider the following example: // Script A module.exports = someCondition ? new MyClass() : {}; // Script B const A = require('./A'); if (Object.getPrototypeOf(A) !== Object.prototype) { // Here we know that `someCondition` is true } else { // Here we know that `someCondition` is false } It does not work as expected in v14.x. May I suggest removing this entire feature, or at least adding an opt-in flag for that? Most of the users know what they are doing and altering random objects makes a lot of unexpected bugs hard to debug. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
It does not trigger the
Module |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
That is incorrect. It does trigger get trap. Please try it yourself before posting a comment: // A.js const assert = require('assert'); module.exports = new Proxy({}, { get(){ assert.fail(); } }); require('./B'); // B.js require('./A'); It triggers the
That is incorrect. Please try it yourself before posting a comment: // A.js const someCondition = false; class MyClass{} module.exports = someCondition ? new MyClass() : {}; require('./B'); // B.js const A = require('./A'); if (Object.getPrototypeOf(A) !== Object.prototype) { console.log('Oh, something went really bad :/'); } else { console.log('OK'); } |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM although I’m having mixed feelings, because it seems like we’re working around people’s broken Proxy implementations here.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Yeah, I agree here – there’s no point in doing anything here for Proxy exports 👍
So is exporting an incomplete Proxy from a module, I would say 🤷♀️
I understand where you’re coming from, but the example code you posted is contrived, and there’s no reason to expect that it is a common occurrence, whereas this feature has enabled catching real-world bugs multiple times even before it was released. It’s making a trade-off, sure, but I would definitely disagree with the notion that it makes the overall situation worse. What’s more, it tends to improve the situation for people who are less familiar with Node.js, and those who do run into these edge cases with it can be assumed to be familiar enough with JS and Node.js to know how to work with them. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
dba07f5 to
83e5b2a
Compare
|
I updated the code to fully work with proxies. It will now just use the target object. It won't "fix" the prototype example but it does seem contrived as @addaleax pointed out and I don't think we have to fix that. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I updated the code to fully work with proxies.
I would disagree with this – the current state of the PR seems worse than the previous version.
It will now just use the target object.
If the module.exports of a module is a Proxy, there is no point in applying this feature, because there is no way to tell how the Proxy interacts with the target object. Plus, modifying an object that is only reachable as a Proxy target breaks expectations about how Proxy objects` work in general.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I was already pondering if the argument about not telling how the |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
31b25e4 to
ed49784
Compare
|
Updated. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
In case the exported module is a proxy that has the `getPrototypeOf` or `setPrototypeOf` trap, skip the circular dependencies check. It would otherwise be triggered by the check itself. Fixes: nodejs#33334 Signed-off-by: Ruben Bridgewater <[email protected]>
ed49784 to
4e7e478
Compare
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
In case the exported module is a proxy that has the `getPrototypeOf` or `setPrototypeOf` trap, skip the circular dependencies check. It would otherwise be triggered by the check itself. Fixes: nodejs#33334 Signed-off-by: Ruben Bridgewater <[email protected]> PR-URL: nodejs#33338 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Zeyu Yang <[email protected]>
|
Landed in 24bf1ad |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
In case the exported module is a proxy that has the `getPrototypeOf` or `setPrototypeOf` trap, skip the circular dependencies check. It would otherwise be triggered by the check itself. Fixes: #33334 Signed-off-by: Ruben Bridgewater <[email protected]> PR-URL: #33338 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Michaël Zasso <[email protected]> Reviewed-By: Zeyu Yang <[email protected]>
|
@BridgeAR should this go back to 12, and if yes, could you please open a manual backport for it? There are a host of conflicts. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Assertion error starting from v14.0.0
There was an error while loading. Please reload this page.