feat(upgrade): add option to initialize inputs synchronously#69919
Open
rush1818 wants to merge 1 commit into
Open
feat(upgrade): add option to initialize inputs synchronously#69919rush1818 wants to merge 1 commit into
rush1818 wants to merge 1 commit into
Conversation
Add `initializeInputsSynchronously` option to `downgradeComponent` to allow initializing Angular component inputs synchronously during creation. Previously, downgraded components evaluated input bindings asynchronously during the first AngularJS digest cycle. This caused issues for components using `input.required()` signal inputs, which threw `NG0950` errors if read during instantiation or initial rendering because the values were not yet available. With this option enabled, the adapter uses `ComponentRef.setInput()` to apply bindings synchronously immediately after creation, ensuring required inputs are available before change detection runs. Also fixes a bug in `@angular/core` where `writeToDirectiveInput` would crash when trying to read an undefined transform decorator on an input (common in JIT or manual mock inputs used in tests).
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.
Add
initializeInputsSynchronouslyoption todowngradeComponentto allow initializing Angular component inputs synchronously during creation.Previously, downgraded components evaluated input bindings asynchronously during the first AngularJS digest cycle. This caused issues for components using
input.required()signal inputs, which threwNG0950errors if read during instantiation or initial rendering because the values were not yet available.With this option enabled, the adapter uses
ComponentRef.setInput()to apply bindings synchronously immediately after creation, ensuring required inputs are available before change detection runs.Also fixes a bug in
@angular/corewherewriteToDirectiveInputwould crash when trying to read an undefined transform decorator on an input (common in JIT or manual mock inputs used in tests).PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
Downgraded Angular components evaluate their input bindings (
$watch/$observecallbacks) asynchronously during the first AngularJS$digestcycle after component creation.Because of this asynchronous initialization timing, if a downgraded component uses modern required signal inputs (
input.required()), reading these signals during component instantiation or initial rendering/change detection throws error.Issue Number: N/A
What is the new behavior?
initializeInputsSynchronously?: boolean(defaults tofalse) todowngradeComponent().initializeInputsSynchronouslyis enabled (true), the downgraded component adapter evaluates the AngularJS input attributes/expressions and applies them synchronously usingComponentRef.setInput()immediately after component instantiation. This ensures that all inputs (including required signal inputs) are fully initialized before the initial change detection or rendering runs.Does this PR introduce a breaking change?
Other information