-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
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: unable to cyclic ES modules #10892
Conversation
Hi @takerusilt! Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! This is looking really good. Very happy with somebody besides me messing with this code 👍
Could you add a test that fails without your changes? The current tests we have run from https://github.com/facebook/jest/blob/3cd04a50d82be392879202e5aefd16e1198ab12f/e2e/__tests__/nativeEsm.test.ts. Not sure if expanding our current test (native-esm.test.js
) or adding some specific new circular ones makes sense. Your example from the OP seems like a nice test to add
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
Thanks for pointing out where to add the test since I'm new to this repo :) |
Thanks! Can you run |
Done, including the changelog update :) |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Summary
In current implementation, when importing a mutually dependent ES module, stack overflow and promise deadlock occur.
For a circular dependency like follow:
moduleA.js
:import moduleB from './moduleB.js'; export default {};
moduleB.js
:import moduleA from './moduleA.js'; export default {};
Loading
moduleA.js
will triggerloadEsmModule
ofmoduleB.js
recursively frommodule.link
before the promise formoduleA.js
is set to_esmoduleRegistry
; which in turn will recursively triggerloadEsmModule
ofmoduleA.js
, having a cache miss. Thus this will continue until stack overflow.Another issue is that since the current cache registry is containing a promise that is resolved after the module is evaluated.
If there are circular dependencies, the promise in registry will never resolves because module evaluation is only done when all promises acquired through
module.link
are resolved.Promise of
moduleA.js
is waiting for promisemoduleB.js
to resolve while promise ofmoduleB.js
is also waiting for promise ofmoduleA.js
to resolve.Test plan
Test with
moduleA
andmoduleB
above.