Skip to content
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

Merged
merged 2 commits into from
Sep 16, 2022

Conversation

jye-sf
Copy link
Contributor

@jye-sf jye-sf commented Sep 16, 2022

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?

  • ✅ No, it does not introduce a breaking change.

Does this pull request introduce an observable change?

  • ⚠️ Yes, it does include an observable change.

GUS work item

@jye-sf jye-sf marked this pull request as ready for review September 16, 2022 20:35
[api_dynamic_component("x-foo", $cmp.trackedProp.foo, stc0)],
0
)
: null,
Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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)
Copy link
Contributor Author

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;
Copy link
Member

@jmsjtu jmsjtu Sep 16, 2022

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.

Copy link
Member

@jmsjtu jmsjtu left a 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!

@jye-sf jye-sf merged commit 55db5eb into if-else-mob Sep 16, 2022
@jye-sf jye-sf deleted the jye/elseif-fragments branch September 16, 2022 23:21
jye-sf added a commit that referenced this pull request Oct 5, 2022
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants