fix(ivy): save queries at the correct indices (#28327)

Previous to this change, we were storing view queries at the
wrong index. This is because we were passing a raw index to the
store() instruction instead of an adjusted index (i.e. an
index that does not include the HEADER_OFFSET). We had an
additional issue where TView.blueprint was not backfilled
when TView.data was backfilled, so new component instances
created from the blueprint would end up having a shorter LView.
Both of these problems together led to the Material demo app
failing with Ivy. This commit fixes those discrepancies.

PR Close #28327
This commit is contained in:
Kara Erickson
2019-01-23 21:11:13 -08:00
committed by Jason Aden
parent d4ecffe475
commit c1fb9c265c
6 changed files with 107 additions and 67 deletions

View File

@ -2930,6 +2930,7 @@ export function store<T>(index: number, value: T): void {
const adjustedIndex = index + HEADER_OFFSET;
if (adjustedIndex >= tView.data.length) {
tView.data[adjustedIndex] = null;
tView.blueprint[adjustedIndex] = null;
}
lView[adjustedIndex] = value;
}
@ -3069,4 +3070,4 @@ function getTViewCleanup(view: LView): any[] {
function loadComponentRenderer(tNode: TNode, lView: LView): Renderer3 {
const componentLView = lView[tNode.index] as LView;
return componentLView[RENDERER];
}
}

View File

@ -23,7 +23,7 @@ import {unusedValueExportToPlacateAjd as unused1} from './interfaces/definition'
import {unusedValueExportToPlacateAjd as unused2} from './interfaces/injector';
import {TContainerNode, TElementContainerNode, TElementNode, TNode, TNodeType, unusedValueExportToPlacateAjd as unused3} from './interfaces/node';
import {LQueries, unusedValueExportToPlacateAjd as unused4} from './interfaces/query';
import {LView, TVIEW} from './interfaces/view';
import {HEADER_OFFSET, LView, TVIEW} from './interfaces/view';
import {getCurrentViewQueryIndex, getIsParent, getLView, getOrCreateCurrentQueries, setCurrentViewQueryIndex} from './state';
import {isContentQueryHost} from './util';
import {createElementRef, createTemplateRef} from './view_engine_compatibility';
@ -407,7 +407,7 @@ export function viewQuery<T>(
}
const index = getCurrentViewQueryIndex();
const viewQuery: QueryList<T> = query<T>(predicate, descend, read);
store(index, viewQuery);
store(index - HEADER_OFFSET, viewQuery);
setCurrentViewQueryIndex(index + 1);
return viewQuery;
}
@ -418,5 +418,5 @@ export function viewQuery<T>(
export function loadViewQuery<T>(): T {
const index = getCurrentViewQueryIndex();
setCurrentViewQueryIndex(index + 1);
return load<T>(index);
}
return load<T>(index - HEADER_OFFSET);
}