-
Notifications
You must be signed in to change notification settings - Fork 27k
fix(core): Handle @let declaration with array in preparingForHydration
#57816
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
Conversation
…tion` Before this commit, `@let` decleration with an array where mistaken for a component in the lView and throwing an unexpected error. This commit fixes this.
preparingForHydrationpreparingForHydration
| ngh[CONTAINERS] ??= {}; | ||
| ngh[CONTAINERS][noOffsetIndex] = serializeLContainer(lView[i], context); | ||
| } else if (Array.isArray(lView[i])) { | ||
| } else if (Array.isArray(lView[i]) && (tNode.type & TNodeType.LetDeclaration) === 0) { |
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.
This fix looks good and we can move it up within this function where we skip a given slot if it doesn't represent a node that requires annotations, i.e. we can extend this condition with an extra check:
if (!isTNodeShape(tNode)) {
continue;
}
to
if (!isTNodeShape(tNode) || isLetDeclaration(tNode)) {
continue;
}
(there is also a comment above this check that would require an update)
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'm not sure the change you're suggesting is correct. The condition after this else if is handling let declarations specifically.
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.
@JeanMeche thanks for additional info. The fix looks good, but we should probably look into that a bit more to make sure that we don't generate an extra annotations for nodes that follow @let, e.g. for this situation we do not want to generate extra info in nghData for <div>:
@let name = 'Andrew';
<div>Hi {{ name }}!</div>
I believe the code in the else if block that you've mentioned would add extra annotation.
If you get a chance, could you please compare what we have in the nghData object for the mentioned template vs when @let is not present?
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.
There is an extra entry in the NODES when there is a @let declared. But it looks like they are required (not having them breaks hydration in our unit tests). Maybe @crisbeto can chime in on this.
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.
According to the current logic they are required, but we can update the logic within the locateNextRNode function to skip over LetDeclaration TNodes instead, so adding extra paths to the NODES set would not be required (+ also doing extra DOM "walks" to find those elements). Note: no need to block this PR, we can explore this more as a followup.
AndrewKushnir
left a comment
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 for this fix and let's take a look at #57816 (comment) as a followup.
|
Caretaker note: presubmit failures are unrelated to this change, this PR is ready for merge. |
|
This PR was merged into the repository by commit 4231e8f. The changes were merged into the following branches: main, 18.2.x |
|
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. |

Before this commit,
@letdeclerations with an array were mistaken for a component in the lView and throwing an unexpected error.This commit fixes this.