fix(ivy): don't increment expandoStartIndex after directives are matched (#28424)

i18n instructions create text nodes dynamically and save them between bindings and the expando block in `LView`. e.g., they try to create the following order in `LView`.

```
| -- elements -- | -- bindings -- | -- dynamic i18n text -- | -- expando (dirs, injectors) -- |
```

Each time a new text node is created, it is pushed to the end of the array and the `expandoStartIndex` marker is incremented, so the section begins slightly later. This happens in `allocExpando`.

This is fine if no directives have been created yet. The end of the array will be in the "dynamic text node" section.

| -- elements -- | -- bindings -- | -- dynamic i18n text -- |

However, this approach doesn't work if dynamic text nodes are created after directives are matched (for example when the directive uses host bindings). In that case, there are already directives and injectors saved in the "expando" section. So pushing to the end of `LView` actually pushes after the expando section. What we get is this:

```
| -- elements -- | -- bindings -- | -- dynamic i18n text -- | -- expando -- | -- dynamic i18n text-- |
```

In this case, the `expandoStartIndex` shouldn't be incremented because we are not inserting anything before the expando section (it's now after the expando section). But because it is incremented in the code right now, it's now pointing to an index in the middle of the expando section.

This PR fixes that so that we only increment the `expandoStartIndex` if nothing was pushed into the expando section.

FW-978 #resolve

PR Close #28424
This commit is contained in:
Olivier Combe
2019-01-29 15:28:31 +01:00
committed by Matias Niemelä
parent 3f73dfa151
commit baf103c98f
4 changed files with 134 additions and 53 deletions

View File

@ -245,14 +245,6 @@ export interface TI18n {
*/
vars: number;
/**
* Index in EXPANDO where the i18n stores its DOM nodes.
*
* When the bindings are processed by the `i18nEnd` instruction it is necessary to know where the
* newly created DOM nodes will be inserted.
*/
expandoStartIndex: number;
/**
* A set of OpCodes which will create the Text Nodes and ICU anchors for the translation blocks.
*
@ -332,14 +324,6 @@ export interface TIcu {
*/
childIcus: number[][];
/**
* Index in EXPANDO where the i18n stores its DOM nodes.
*
* When the bindings are processed by the `i18nEnd` instruction it is necessary to know where the
* newly created DOM nodes will be inserted.
*/
expandoStartIndex: number;
/**
* A list of case values which the current ICU will try to match.
*