-
-
Notifications
You must be signed in to change notification settings - Fork 34.9k
module: add clearCache for CJS and ESM #61767
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
Open
anonrig
wants to merge
11
commits into
nodejs:main
Choose a base branch
from
anonrig:yagiz/node-module-clear-cache
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,532
−3
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b7788b4
module: add clearCache for CJS and ESM
anonrig 357917f
fixup! module: add clearCache for CJS and ESM
anonrig f7c826e
fixup! module: add clearCache for CJS and ESM
anonrig 723300c
fixup! module: add clearCache for CJS and ESM
anonrig 2496f25
fixup! module: add clearCache for CJS and ESM
anonrig e2a581d
fixup! module: add clearCache for CJS and ESM
anonrig d21982c
fixup! module: add clearCache for CJS and ESM
anonrig 35d207e
fixup! module: add clearCache for CJS and ESM
anonrig 105ff7e
fixup! module: add clearCache for CJS and ESM
anonrig 7e9a7c5
fixup! module: add clearCache for CJS and ESM
anonrig 1410c00
fixup! module: add clearCache for CJS and ESM
anonrig File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
This may need to spell out a bit more concretely how HMR is supposed to use this API without leaking more. From #61767 (comment) there are a couple of things that need to be taken care of:
2 has a subtle difference in CommonJS v.s. ESM dependents. If the changed module has CommonJS dependents, the solution may need to track and clear the cache of all the dependent modules and re-evaluate from the root to see the update. For ESM dependents it's easier because evaluation is separate from linking, so the solution can simply clear the cache for the changed module and the root, and re-evaluate from the root to pick up the new branch while reusing all the existing branches (so unchanged modules won't get evaluated again). This won't violate the spec as explained by Nicolo because it's technically disposing the old graph and then linking and evaluating a new graph again that just reuse some existing module records, not mutating the existing link of an old, evaluated graph.
Although, it would be much simpler if whatever that uses it enforces that the module that gets HMR can only ever be the root itself and no bottom-up dependency HMR is supported. But I am not sure if that's a limitation that all existing HMR users can enforce.
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.
Would it be simpler if instead of a “clear cache” API, we just provided a “replace module” API? Where the new module must have the same exports as the old one, so that the linking wouldn’t need to be redone?
Uh oh!
There was an error while loading. Please reload this page.
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.
I think regardless of whether the new module has the same exports or not, linking must be redone. Links exist between different module records (not Node.js ModuleJobs or ModuleWraps, but
v8::Module), and we can't swap out what's inside av8::Module- but can only compile a new one and relink.