Skip to content

Input writing refactors#59980

Closed
crisbeto wants to merge 9 commits intoangular:mainfrom
crisbeto:property-refactor
Closed

Input writing refactors#59980
crisbeto wants to merge 9 commits intoangular:mainfrom
crisbeto:property-refactor

Conversation

@crisbeto
Copy link
Copy Markdown
Member

@crisbeto crisbeto commented Feb 17, 2025

Includes some refactors around how we store input data internally. The result is that:

  • We duplicate less information between the TNode and the directive definition.
  • DirectiveDef.inputs has a consistent type no matter how an input is configured which makes it easier to reason about.
  • We need less information in order to write to a directive's input.
  • We can remove the InputTransformsFeature.
  • We can remove the DirectiveDef.inputTransforms field.
  • We no longer need to store input flags in TNode.inputs.
  • We store 2 fewer values in the TNode.initialInputs data structure.
  • We don't resolve the native element for property writes in production mode. In development mode it's only used for the ng-reflect- attributes.

Detailed list of changes:

refactor(core): simplify how inputs are stored in the directive definition

Currently the values in DirectiveDef.inputs are either strings or arrays, depending if there are flags. This makes it a bit hard to work with, because each time it's read, the consumer needs to account for both cases.

These changes rework it so the values are always an arrays.

refactor(core): remove inputTransforms from definition

Removes the inputTransform from the directive definition since this information is already available on the inputs.

refactor(compiler): remove input transforms feature

An earlier refactor made the InputTransformsFeature a no-op so these changes remove the code that was generating it.

refactor(core): remove flags from TNode.inputs

The input flags are already available on the definition so we don't need to store them on TNode.inputs.

refactor(core): simplify InitialInputs data structure

Reworks the InitialInputs data structure to only store a public name and initial value, resulting in less memory usage and making it easier to work with.

refactor(core): refactor(core): avoid unnecessary lookup when writing inputs

Currently we resolve the DOM node when writing inputs up-front, because it's necessary for the ng-reflect- attributes. Since the attributes are dev-mode-only, we can move the resolution into the function that writes them so we can avoid the resolution when it's not used.

refactor(core): add assertion to avoid writes to directive factories

Attempting to write to directive inputs before the directive is created can lead to subtle issues that won't necessarily trigger errors. These changes add an assertion to catch such issues earlier.

@crisbeto crisbeto added the target: patch This PR is targeted for the next patch release label Feb 17, 2025
@angular-robot angular-robot bot added area: compiler Issues related to `ngc`, Angular's template compiler area: core Issues related to the framework runtime labels Feb 17, 2025
@ngbot ngbot bot modified the milestone: Backlog Feb 17, 2025
@angular-robot angular-robot bot added the area: build & ci Related the build and CI infrastructure of the project label Feb 17, 2025
@crisbeto crisbeto force-pushed the property-refactor branch 2 times, most recently from 54a5488 to d657f8f Compare February 17, 2025 15:32
@crisbeto crisbeto added the action: review The PR is still awaiting reviews from at least one requested reviewer label Feb 17, 2025
@crisbeto crisbeto marked this pull request as ready for review February 17, 2025 16:39
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're not too far off from having this be a number[]. The problem is that it doesn't allow us to handle re-aliased host directive inputs.

@crisbeto
Copy link
Copy Markdown
Member Author

Passing TGP, aside from some unrelated broken targets.

Copy link
Copy Markdown
Member

@pkozlowski-opensource pkozlowski-opensource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very reasonable moves!

Special kudos for having small, focused commits for each refactor - makes it so much easier to review 🎉

…ition

Currently the values in `DirectiveDef.inputs` are either strings or arrays, depending if there are flags. This makes it a bit hard to work with, because each time it's read, the consumer needs to account for both cases.

These changes rework it so the values are always an arrays.
Removes the `inputTransform` from the directive definition since this information is already available on the `inputs`.
An earlier refactor made the `InputTransformsFeature` a no-op so these changes remove the code that was generating it.
The input flags are already available on the definition so we don't need to store them on `TNode.inputs`.
Reworks the `InitialInputs` data structure to only store a public name and initial value, resulting in less memory usage and making it easier to work with.
Currently we resolve the DOM node when writing inputs up-front, because it's necessary for the `ng-reflect-` attributes. Since the attributes are dev-mode-only, we can move the resolution into the function that writes them so we can avoid the resolution when it's not used.
Attempting to write to directive inputs before the directive is created can lead to subtle issues that won't necessarily trigger errors. These changes add an assertion to catch such issues earlier.
Updates the bundle goldens to account for the latest changes.
Simplifies the functions that serialize inputs/outputs for the `ComponentFactory` type.
@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Feb 18, 2025
thePunderWoman pushed a commit that referenced this pull request Feb 18, 2025
Removes the `inputTransform` from the directive definition since this information is already available on the `inputs`.

PR Close #59980
thePunderWoman pushed a commit that referenced this pull request Feb 18, 2025
An earlier refactor made the `InputTransformsFeature` a no-op so these changes remove the code that was generating it.

PR Close #59980
@thePunderWoman
Copy link
Copy Markdown
Contributor

This PR was merged into the repository by commit f41437e.

The changes were merged into the following branches: main, 19.1.x

thePunderWoman pushed a commit that referenced this pull request Feb 18, 2025
The input flags are already available on the definition so we don't need to store them on `TNode.inputs`.

PR Close #59980
thePunderWoman pushed a commit that referenced this pull request Feb 18, 2025
Reworks the `InitialInputs` data structure to only store a public name and initial value, resulting in less memory usage and making it easier to work with.

PR Close #59980
thePunderWoman pushed a commit that referenced this pull request Feb 18, 2025
Currently we resolve the DOM node when writing inputs up-front, because it's necessary for the `ng-reflect-` attributes. Since the attributes are dev-mode-only, we can move the resolution into the function that writes them so we can avoid the resolution when it's not used.

PR Close #59980
thePunderWoman pushed a commit that referenced this pull request Feb 18, 2025
…59980)

Attempting to write to directive inputs before the directive is created can lead to subtle issues that won't necessarily trigger errors. These changes add an assertion to catch such issues earlier.

PR Close #59980
thePunderWoman pushed a commit that referenced this pull request Feb 18, 2025
Updates the bundle goldens to account for the latest changes.

PR Close #59980
thePunderWoman pushed a commit that referenced this pull request Feb 18, 2025
Simplifies the functions that serialize inputs/outputs for the `ComponentFactory` type.

PR Close #59980
thePunderWoman pushed a commit that referenced this pull request Feb 18, 2025
…ition (#59980)

Currently the values in `DirectiveDef.inputs` are either strings or arrays, depending if there are flags. This makes it a bit hard to work with, because each time it's read, the consumer needs to account for both cases.

These changes rework it so the values are always an arrays.

PR Close #59980
thePunderWoman pushed a commit that referenced this pull request Feb 18, 2025
Removes the `inputTransform` from the directive definition since this information is already available on the `inputs`.

PR Close #59980
thePunderWoman pushed a commit that referenced this pull request Feb 18, 2025
An earlier refactor made the `InputTransformsFeature` a no-op so these changes remove the code that was generating it.

PR Close #59980
thePunderWoman pushed a commit that referenced this pull request Feb 18, 2025
The input flags are already available on the definition so we don't need to store them on `TNode.inputs`.

PR Close #59980
thePunderWoman pushed a commit that referenced this pull request Feb 18, 2025
Reworks the `InitialInputs` data structure to only store a public name and initial value, resulting in less memory usage and making it easier to work with.

PR Close #59980
thePunderWoman pushed a commit that referenced this pull request Feb 18, 2025
Currently we resolve the DOM node when writing inputs up-front, because it's necessary for the `ng-reflect-` attributes. Since the attributes are dev-mode-only, we can move the resolution into the function that writes them so we can avoid the resolution when it's not used.

PR Close #59980
thePunderWoman pushed a commit that referenced this pull request Feb 18, 2025
…59980)

Attempting to write to directive inputs before the directive is created can lead to subtle issues that won't necessarily trigger errors. These changes add an assertion to catch such issues earlier.

PR Close #59980
thePunderWoman pushed a commit that referenced this pull request Feb 18, 2025
Updates the bundle goldens to account for the latest changes.

PR Close #59980
thePunderWoman pushed a commit that referenced this pull request Feb 18, 2025
Simplifies the functions that serialize inputs/outputs for the `ComponentFactory` type.

PR Close #59980
@angular-automatic-lock-bot
Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Mar 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: build & ci Related the build and CI infrastructure of the project area: compiler Issues related to `ngc`, Angular's template compiler area: core Issues related to the framework runtime target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants