forked from angular/angular
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(compiler): trigger hmr load on initialization (angular#58465)
Adjusts the HMR initialization to avoid the edge case where a developer makes change to a non-rendered component that exists in a lazy loaded chunk that has not been loaded yet. The changes include: * Moving the `import` statement out into a separate function. * Adding a null check for `d.default` before calling `replaceMEtadata`. * Triggering the `import` callback eagerly on initialization. Example of the new generated code: ```js (() => { function Cmp_HmrLoad(t) { import( /* @vite-ignore */ "/@ng/component?c=test.ts%40Cmp&t=" + encodeURIComponent(t) ).then((m) => m.default && i0.ɵɵreplaceMetadata(Cmp, m.default, [/* Dependencies go here */])); } (typeof ngDevMode === "undefined" || ngDevMode) && Cmp_HmrLoad(Date.now()); (typeof ngDevMode === "undefined" || ngDevMode) && import.meta.hot && import.meta.hot.on("angular:component-update", (d) => { if (d.id === "test.ts%40Cmp") { Cmp_HmrLoad(d.timestamp); } }); })(); ``` PR Close angular#58465
- Loading branch information
1 parent
fbd7b7c
commit 7d0ba0c
Showing
2 changed files
with
71 additions
and
36 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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