-
Notifications
You must be signed in to change notification settings - Fork 26.3k
fix(core): correctly fallback ng-content with projectable nodes. #57480
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
fix(core): correctly fallback ng-content with projectable nodes. #57480
Conversation
d7be1bc
to
fa8b2b3
Compare
I might miss something from a quick glance. What would happen if someone wants to explicitly avoid the ng-content default and project zero nodes? Should |
in that case they can pass |
It does sound like this would be a breaking change though? |
You are right 💯 . so now the question is should we do this as breaking change or do you prefer to change |
I might be missing something, but right now |
I will defer to @crisbeto on how to treat this, as he is the expert on projection and its APIs. @diesieben07 I think it wouldn't be a breaking change, if |
BREAKING CHANGE: Render default fallback with empty `projectableNodes`. When passing an empty array to `projectableNodes` in the `createComponent` API, the default fallback content of the `ng-content` will be rendered if present. To prevent rendering the default content, pass `document.createTextNode('')` as a `projectableNode`. For example: ```ts // The first ng-content will render the default fallback content if present createComponent(MyComponent. { projectableNodes: [[], [secondNode]] }); // To prevent projecting the default fallback content: createComponent(MyComponent. { projectableNodes: [[document.createTextNode('')], [secondNode]] }); ``` Fixes angular#57471
fa8b2b3
to
a232f94
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this logic makes sense, but will run a global presubmit just in case.
I just tried this out in current Angular and the behavior I described above ( In my opinion the behavior should not be altered and instead the type of |
I'm agreeing with @diesieben07. I've explained that in: #57480 (comment). Right now this is a breaking change. I think @crisbeto might be verifying if that is actually breaking a lot? In either case, I'd personally prefer |
In what situations might a user want to skip the projection and avoid falling back to the default value? Generally, when directly using a component in a template, falling back to the default is the more common approach. Therefore, I prefer to break from this pattern rather than introducing a null value. |
This PR was merged into the repository by commit 7b1e5be. The changes were merged into the following branches: main |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
projectableNodes
should allow to pass empty nodes to fallback to defaultng-content
for that placeholder without affecting rendering of remaining nodes.Fixes #57471
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?
Currently default ng-content fallback fails when
projectableNodes
are passed as empty in between of nodes.e.g for below component template
if the projectableNodes are passed like this [[customContentElement], [], [anotherContentElement]];
it will render
Issue Number: 57471
What is the new behavior?
It should render default fallback for empty nodes like below.
Does this PR introduce a breaking change?
Other information