Repository navigation
Conversation
Resolve `@angular/core`'s `forwardRef` in `imports` before the implicit `@defer` deferral, like ngtsc's `forwardRefResolver`, so a component used only inside `@defer` is loaded with a dynamic `import()`. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Fixes #632.
Problem
A standalone component listed as
imports: [forwardRef(() => CmpA)]and used only inside@deferstayed eager: the implicit-deferral gate from #313 required everyimportsentry to be a bare identifier, and the identifier list it matched against skippedforwardRef(...)entries. The staticimport { CmpA }stayed andɵɵdefer(1, 0)got no dependency function. ngtsc resolves the entry throughforwardRefResolver(tryUnwrapForwardRefinpackages/compiler-cli/src/ngtsc/annotations/common/src/util.ts) beforeresolveAllDeferredDependenciesmatches selectors.Fix
decorator.rs: record the classes written asforwardRef(() => X)in theimportsarray (ComponentMetadata::forward_ref_imports), using the existingtry_unwrap_forward_ref, so only@angular/core'sforwardRefcounts.importsitself is unchanged (partial/Direct emit still reads it).transform.rs:import_entry_classmaps each rawimportsentry to its class (Xor a resolvedforwardRef(() => X), arrow orreturnbody). The gate, the candidate list and the removal from the eagerɵɵgetComponentDepsFactoryarray all use it.Output now matches ngc:
ɵɵdefer(1, 0, () => [import("./lazy").then(m => m.LazyCmp)]),ɵɵgetComponentDepsFactory(Parent, []), and no static import.Selectorless deps (
selectorless_spec.ts: "should defer selectorless symbols") are out of scope: OXC rejects selectorless components outright (pipeline/ingest.rs), so there is nothing to defer yet.Checks
tests/defer_implicit_imports_test.rs:forward_ref_import_used_only_inside_defer_is_lazy_loaded(port ofdefer_spec.ts"should lazy-load dependency referenced with a fowrardRef", arrow and block-body forms) andforward_ref_not_from_angular_core_stays_eager.cargo test -p oxc_angular_compiler --all-features: 3518 passed, 0 failed.cargo fmt;cargo clippy -p oxc_angular_compiler --all-featuresadds no warnings on the changed lines.🤖 Generated with Claude Code