fix(compiler): support foreign components inside control flow blocks#69674
fix(compiler): support foreign components inside control flow blocks#69674leonsenft wants to merge 3 commits into
Conversation
3a0f32b to
6e3a9ca
Compare
| } | ||
| } | ||
|
|
||
| view.create.prepend(generateVariablesInScopeForView(view, scope, false)); |
There was a problem hiding this comment.
This is potentially problematic for variables which aren't available in the creation pass, e.g. @if (c) { <input #i /> <FancyButton [x]="i" /> }
There was a problem hiding this comment.
This is a great catch, and one that isn't trivial to solve. The issue is that these references truly aren't available until the update phase, so we can't simply expose them to the create phase like we did for the component context.
As a workaround, you could use viewQuery() signal to pass reactive references, although this similarly breaks if you use viewQuery.required().
We could implement diagnostics to prohibit passing references in this manner. Alternatively, we could reevaluate the timing of foreign component creation and move it to the update phase. That would be a pretty significant refactor though, so are you okay if we submit this as-is for now and address that in a follow up PR?
…n component When a control flow block (`@if`, `@switch`, `@for`) contains a single root element that is a foreign component, do not treat its name as a tag name for the template container (`conditionalCreate`, `repeaterCreate`).
Prepend generated view scope variables to `view.create` in addition to `view.update` so that expressions evaluated during creation (such as foreign component property bindings) can resolve context variables from parent views when nested inside control flow blocks (`@if`, `@switch`, `@for`). This is necessary to support binding properties to foreign components inside control flow blocks. reflect this broader behavior.)
6e3a9ca to
962abec
Compare
962abec to
66d91f2
Compare
Prepend generated view scope variables to
view.createin addition toview.updateso that expressions evaluated during creation (such as foreign component property bindings) can resolve context variables from parent views when nested inside control flow blocks (@if,@switch,@for). This is necessary to support binding properties to foreign components inside control flow blocks.