Skip to content

fix(core): correctly project single-root content inside control flow - #54879

Closed
pkozlowski-opensource wants to merge 1 commit into
angular:mainfrom
pkozlowski-opensource:control_flow_container_projection
Closed

pkozlowski-opensource wants to merge 1 commit into
angular:mainfrom
pkozlowski-opensource:control_flow_container_projection

Conversation

@pkozlowski-opensource

Copy link
Copy Markdown
Member

This commit changes the way we use containers to insert conditional content. Previously if and switch conditional would always use the first content as the insertion container. This strategy interfered with content projection that projects entire containers - as the consequence content for all cases would end up in slot matched by the first container. This could be very surprising as described in #54840

After the change each conditional content is projected into its own container. This means that content projection can match more than one container and result in correct display.

Fixes #54840

@pkozlowski-opensource

Copy link
Copy Markdown
Member Author

@crisbeto this PR has runtime bits + tests of the changed strategy of inserting conditional content into containers. I've added tests for @if and @switch - @for should be fine as far as I can tell.

Important notes:

  • DO NOT MERGE this PR on its own - it requires compiler changes as well;
  • with those changes we could simplify the ɵɵconditional instruction by dropping its first containerIndex argument

@pkozlowski-opensource pkozlowski-opensource added area: core Issues related to the framework runtime core: control flow Issues related to the built-in control flow (@if, @for, @switch) labels Mar 15, 2024
@ngbot ngbot Bot added this to the Backlog milestone Mar 15, 2024

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice! I would probably do it in a standalone PR though.

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.

Yep, make sense to do it in a separate PR!

This commit changes the way we use containers to insert conditional content.
Previously if and switch conditional would always use the first content as the
insertion container. This strategy interfered with content projection that
projects entire containers - as the consequence content for _all_ cases would
end up in slot matched by the first container. This could be very surprising
as desicribed in angular#54840

After the change each conditional content is projected into its own container.
This means that content projection can match more than one container and
result in correct display.

Fixes angular#54840
@crisbeto

Copy link
Copy Markdown
Member

Compiler changes plus the changes from this PR are in #54921.

@pkozlowski-opensource

Copy link
Copy Markdown
Member Author

Landed as part of #54921

@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 Apr 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area: core Issues related to the framework runtime core: control flow Issues related to the built-in control flow (@if, @for, @switch)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Conditionals and content projection

2 participants