Skip to content
This repository has been archived by the owner on May 25, 2021. It is now read-only.

Commit

Permalink
Fixes #487
Browse files Browse the repository at this point in the history
Option elements are excluded from being added to the compoment tree.

However, we must also exclude them from being numbered when assigning
augury-id's.

Otherwise, if we have option elements with other elements after it, we
will get undefined elements in the parent component's child array in the
component tree, since it assigns to the child array using the augury-id
as an index to the array.

Example:
If we have 4 <option> elements with a <div> after it, then the four
<option> elements have augury-id 0 to 3 and the <div> would get id 4.

When adding to the child array of the parent, the four <option>
elements are not added. The <div> after is added, but is added to index
4 in the child array. This creates undefined elements in positions 0-3 in
the array.

The front-end is then given the componet tree and a JS error is thrown
when the user highlights the null node.
  • Loading branch information
Andrew Lo committed Jul 26, 2016
1 parent a380f0f commit 3272d84
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/backend/adapters/angular2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ export class Angular2Adapter extends BaseAdapter {
if (compEl.children.length > 0) {
compEl
.children
.filter((child: any) => !this._isComponentExcluded(child))
.forEach((child: any, childIdx: number) => {

let index: string = idx;
if (child.providerTokens.length > 0) {
index = [idx, this._tree[idx]].join('.');
Expand Down Expand Up @@ -174,7 +174,6 @@ export class Angular2Adapter extends BaseAdapter {
_emitNativeElement = (compEl: any, isRoot: boolean,
idx: string): void => {
const nativeElement = this._getNativeElement(compEl);
const nodeName = this._getComponentName(compEl);

// When encounter a template comment, insert another comment with
// augury-id above it.
Expand All @@ -190,9 +189,7 @@ export class Angular2Adapter extends BaseAdapter {

if (isRoot) {
return this.addRoot(compEl);
} else if (nodeName !== 'option') {
// skipping the option to improve performance
// It adds no value displaying node elements
} else if (!this._isComponentExcluded(compEl)) {
this.addChild(compEl);
}
};
Expand Down Expand Up @@ -299,6 +296,12 @@ export class Angular2Adapter extends BaseAdapter {
return true;
}

_isComponentExcluded(debugEl: any): boolean {
// skipping the option to improve performance
// It adds no value displaying node elements
return this._getComponentName(debugEl) === 'option';
}

_getComponentState(debugEl: any): Object {
let state;
if (debugEl.componentInstance) {
Expand Down

0 comments on commit 3272d84

Please sign in to comment.