Repository navigation
Conversation
this.addWatchFile in load hook on a module's first request
|
This PR might also fix #18914 |
koriyoshi2041
left a comment
There was a problem hiding this comment.
Validated this at 6288bda22ab6. The HMR playground passes 130 tests with 1 skipped, including the new first-request <link> case. Applying only the regression fixture to current main@a976df388 fails at the expected boundary (red remains red after editing dep-load.js), so the test distinguishes the fix rather than just covering the steady state.
I also checked the earlier ensure-before-load/revert pair (#12774/#12929). That regression depended on eagerly calling ensureWatchedFile for the resolved request; this change only creates the module-graph entry early, while filesystem watching still occurs after a successful read. I did not find a remaining correctness issue in this diff.
| // Ensure the module node exists before `load` runs, so that module info | ||
| // and files registered via `this.addWatchFile` in the `load` hook can be | ||
| // associated with this module (#23860) | ||
| mod ??= await moduleGraph._ensureEntryFromUrl(url, undefined, resolved) |
There was a problem hiding this comment.
Maybe we should use canSkipImportAnalysis(id) for the second argument. But this bug (?) exist before this PR, so let's check it seprately.
|
I've added a failing test. I think we need to fix this |
koriyoshi2041
left a comment
There was a problem hiding this comment.
The rollback added at c7d7322 can remove a pre-existing shared module, not only the node created by this request. removeModuleOnLoadFailure is derived from the raw URL lookup before resolution, but _ensureEntryFromUrl may resolve that new URL to an existing idToModuleMap entry used by another URL. If load then fails, _removeModule deletes the shared id/file entry (and only mod.url from urlToModuleMap), leaving aliases pointing at a detached node. Please have _ensureEntryFromUrl report whether it created the node, or compare the resolved node against the pre-existing id mapping before making rollback destructive. A regression with two URLs resolving to one id, where the second URL load fails, should preserve the first URL module.
|
I've added a new failing test. |
koriyoshi2041
left a comment
There was a problem hiding this comment.
The changed head addresses the shared-node rollback case I raised. removeModuleOnLoadFailure is now false when the resolved id already exists, and _removeModule independently retains a node once another URL, an importer, or a completed transform is attached. The new overlapping-load regression exercises the timing-sensitive alias path directly, and the hosted Node 20/22/24/26 plus macOS/Windows matrix is green. I don't see a remaining issue at 60c71b65.
|
I've pushed a different fix as the code had some bugs:
|
close #23860
refs #14967, #18103