-
Notifications
You must be signed in to change notification settings - Fork 393
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: use Fragment VNodes for if-elseif-else children #3047
Conversation
[api_dynamic_component("x-foo", $cmp.trackedProp.foo, stc0)], | ||
0 | ||
) | ||
: null, |
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.
@jodarove This now returns null if there's nothing in the else branch
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 should be ok, it looks like there's a check when mounting the vnodes to see if the value is null.
We also return an array of null values in the if:true/false
cases from the tmpl function.
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.
Yup. I modeled this after codegen's behavior for if:true/false.
|
||
const childrenExpression = codeGen.genFragment( | ||
t.literal(ifBlockKey), | ||
transformChildren(conditionalParentBlock) |
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.
genFragment
has a third parameter that lets us specify whether this fragment is stable
or not. A subsequent perf optimization we can do is to detect whether the children here are dynamic or static and set the stable
flag appropriately.
Leaving that for a separate PR after #3030 gets merged. Getting that merged sooner will unblock some of the integration work.
@@ -5,17 +5,25 @@ const $fragment3 = parseFragment`<h1${3}>things</h1>`; | |||
const $fragment4 = parseFragment`<h1${3}>hello</h1>`; | |||
const $fragment5 = parseFragment`<h1${3}>world!</h1>`; | |||
function tmpl($api, $cmp, $slotset, $ctx) { | |||
const { t: api_text, st: api_static_fragment, f: api_flatten } = $api; | |||
return api_flatten([ | |||
const { t: api_text, st: api_static_fragment, fr: api_fragment } = $api; |
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.
The original goal of this test was just to ensure that the returned values were wrapped with api_flatten
. Since we're using fragments now I think we can rename it to with-siblings
or something else.
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.
lgtm! Looking through #3034 it should be good to good, excellent job!
* feat: lwc:if, lwc:elseif, and lwc:else directives (#2985) * feat: refactor parser context to support new behavior for slot name tracking (#2990) * feat(template-compiler): add codegen portion for else-if directives (#2995) * fix: use Fragment VNodes for if-elseif-else children (#3047) Co-authored-by: Pierre-Marie Dartus <p.dartus@salesforce.com> Co-authored-by: James Tu <j.tu@salesforce.com>
Details
Builds on top of #3034 to resolve issue with diffing algo. if-elseif-else children are now properly marked as fragments so that the diffing algo can update the nodes properly.
Has dependencies on both #3034 and #3030 and should only be merged into a branch that contains both those changes.
Does this pull request introduce a breaking change?
Does this pull request introduce an observable change?
GUS work item