Skip to content

fix(ivy): constant object literals shared across element and component instances #33705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

crisbeto
Copy link
Member

@crisbeto crisbeto commented Nov 9, 2019

Currently if a consumer does something like the following, the object literal will be shared across the two elements and any instances of the component template. The same applies to array literals:

<div [someDirective]="{}"></div>
<div [someDirective]="{}"></div>

These changes make it so that we generate a pure function even if an object is constant so that each instance gets its own object.

Note that the original design for this fix included moving the pure function factories into the consts array. In the process of doing so I realized that pure function are also used inside of directive host bindings which means that we don't have access to the consts.

These changes also:

  • Fix an issue that meant that the pureFunction0 instruction could only be run during creation mode.
  • Make the getConstant utility slightly more convenient to use. This isn't strictly required for these changes to work, but I had made it as a part of a larger refactor that I ended up reverting.

@crisbeto crisbeto marked this pull request as ready for review November 9, 2019 01:16
@crisbeto crisbeto requested review from a team as code owners November 9, 2019 01:16
@crisbeto crisbeto added comp: ivy action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Nov 9, 2019
@ngbot ngbot bot modified the milestone: needsTriage Nov 9, 2019
@mhevery mhevery removed the action: review The PR is still awaiting reviews from at least one requested reviewer label Nov 12, 2019
@mhevery
Copy link
Contributor

mhevery commented Nov 12, 2019

presubmit
ivy-presubmit

@mhevery mhevery added the action: merge The PR is ready for merge by the caretaker label Nov 12, 2019
@AndrewKushnir AndrewKushnir added the action: presubmit The PR is in need of a google3 presubmit label Nov 12, 2019
Copy link
Contributor

@kara kara left a comment

Choose a reason for hiding this comment

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

LGTM once comments are updated

@kara kara added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed cla: yes labels Nov 13, 2019
@crisbeto crisbeto removed the action: merge The PR is ready for merge by the caretaker label Nov 13, 2019
…t instances

Currently if a consumer does something like the following, the object literal will be shared across the two elements and any instances of the component template. The same applies to array literals:

```
<div [someDirective]="{}"></div>
<div [someDirective]="{}"></div>
```

These changes make it so that we generate a pure function even if an object is constant so that each instance gets its own object.

Note that the original design for this fix included moving the pure function factories into the `consts` array. In the process of doing so I realized that pure function are also used inside of directive host bindings which means that we don't have access to the `consts`.

These changes also:
* Fix an issue that meant that the `pureFunction0` instruction could only be run during creation mode.
* Make the `getConstant` utility slightly more convenient to use. This isn't strictly required for these changes to work, but I had made it as a part of a larger refactor that I ended up reverting.
@crisbeto crisbeto force-pushed the FW-1633/shared-object-literals branch from 2a5ad2e to 221bdf5 Compare November 13, 2019 13:26
@crisbeto
Copy link
Member Author

Rebased and updated the comments.

@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Nov 13, 2019
@kara kara removed the action: presubmit The PR is in need of a google3 presubmit label Nov 13, 2019
@kara kara closed this in fcdada5 Nov 13, 2019
kara pushed a commit that referenced this pull request Nov 13, 2019
…t instances (#33705)

Currently if a consumer does something like the following, the object literal will be shared across the two elements and any instances of the component template. The same applies to array literals:

```
<div [someDirective]="{}"></div>
<div [someDirective]="{}"></div>
```

These changes make it so that we generate a pure function even if an object is constant so that each instance gets its own object.

Note that the original design for this fix included moving the pure function factories into the `consts` array. In the process of doing so I realized that pure function are also used inside of directive host bindings which means that we don't have access to the `consts`.

These changes also:
* Fix an issue that meant that the `pureFunction0` instruction could only be run during creation mode.
* Make the `getConstant` utility slightly more convenient to use. This isn't strictly required for these changes to work, but I had made it as a part of a larger refactor that I ended up reverting.

PR Close #33705
@angular-automatic-lock-bot
Copy link

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 Dec 14, 2019
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 cla: yes target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants