Repository navigation
fix(defer): give each @defer block its own deps fn - #659
Merged
Merged
Conversation
With cross-file analysis (resolveImportedValues), oxc built one shared resolver per component and passed it to every ɵɵdefer, so the first block to trigger also fetched the chunks of the other blocks. Blocks that used only eager or same-file deps got no deps fn at all. Port ngtsc's full-compilation PerBlock mode: each block lists the `imports` entries its main content matches (nested blocks own their content, their @placeholder/@loading/@error count for the outer one), as a dynamic import() when the dep is lazy and a plain reference when it is eager. The fn is pooled as `<Cmp>_Defer_<slot>_DepsFn`, where only the first `_Template` of the view's fn name is dropped, and the pool takes the name as is, without using up a `_cN` index. setClassMetadataAsync lists the lazy deps block by block. Same-file standalone classes are matched by their selector too. An entry used only inside @defer blocks leaves `dependencies`, even when it can't be lazy-loaded: the blocks' fns provide it. When no entry is left, the component gets no `dependencies` key. Unknown selectors (node_modules, pipes) stay out of the lists, as before; `dependencies` still provides them. An explicit `deferredImports`, HMR, JIT and the no-analysis path keep the shared resolver. Ported from @angular/compiler-cli 22.2.3 ComponentDecoratorHandler (resolveDeferBlocks, resolveAllDeferredDependencies, compileDeferBlocks, handleDependencyCycles) and @angular/compiler 22.2.2 compileDeferResolverFunction, resolveDeferDepsFns and ConstantPool.getSharedFunctionReference. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. What shall we delve into next? Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Part of #623 (the
@deferloader row). ThedeferredImportsform is #654.When cross-file analysis is on (
resolveImportedValues), oxc built one shared resolver per component and passed it to everyɵɵdefer. So the first block to trigger also loaded the chunks of the other blocks. Blocks that used only eager or same-file deps got no deps fn at all.This PR ports ngtsc's full-compilation PerBlock mode:
<Cmp>_Defer_<slot>_DepsFn. It lists theimportsentries that the block's main content matches: a dynamicimport()for a lazy dep, a plain reference for an eager one.@placeholder,@loadingand@errorcount for the outer block._Templateof the view's fn name, likefnName?.replace('_Template', '').getSharedFunctionReference(..., false)), so it does not use up a_cNindex.@deferblocks leavesdependencies, even when it can't be lazy-loaded, because the block's fn provides it. When no entry is left, the component gets nodependencieskey.setClassMetadataAsynclists the lazy deps block by block.Ported from @angular/compiler-cli 22.2.3
ComponentDecoratorHandler(resolveDeferBlocks,resolveAllDeferredDependencies,compileDeferBlocks,handleDependencyCycles) and @angular/compiler 22.2.2 (compileDeferResolverFunction,resolveDeferDepsFns,ConstantPool.getSharedFunctionReference).Before / after
ngtsc cases checked
I compared deps fns and
dependencieswith ngtsc on 37 cases. These match: in_if, same_two, nested, fwdref, dir_attr, dir_tpl, placeholder_only, for_loop, pure_fn, i18n, placeholder_defer, loading_err, reverse_order, switch_case, hydrate, ng_container_tpl, two_cmp_share_import, two_cmp_lazy, order_, name_tpl, collide, default_imp, sibling_spec, multi_sel, Card_Template, My_TemplateCmp in @if, a, sib_eager, sib_iface. Adependencieskey is now missing exactly where ngtsc has none.Known gaps that remain (same as before this PR): pipes, barrel re-exports, a self reference, and node_modules deps are not in the deps fn, and
dependenciesstill uses thegetComponentDepsFactoryform. When several components in one file have the same deps fn, each one still emits its own copy.Checks
🤖 Generated with Claude Code