diff --git a/packages/@glimmer/runtime/lib/dom/helper.ts b/packages/@glimmer/runtime/lib/dom/helper.ts index 90b1878505..d7b24ed4a8 100644 --- a/packages/@glimmer/runtime/lib/dom/helper.ts +++ b/packages/@glimmer/runtime/lib/dom/helper.ts @@ -210,22 +210,15 @@ export function insertHTMLBefore( useless: HTMLElement, _parent: Simple.Element, _nextSibling: Option, - html: string + _html: string ): Bounds { - // tslint:disable-line - // TypeScript vendored an old version of the DOM spec where `insertAdjacentHTML` - // only exists on `HTMLElement` but not on `Element`. We actually work with the - // newer version of the DOM API here (and monkey-patch this method in `./compat` - // when we detect older browsers). This is a hack to work around this limitation. - let parent = _parent as HTMLElement; - let nextSibling = _nextSibling as Node; + let parent = _parent as Element; + let nextSibling = _nextSibling as Option; let prev = nextSibling ? nextSibling.previousSibling : parent.lastChild; let last: Simple.Node | null; - if (html === null || html === '') { - return new ConcreteBounds(parent, null, null); - } + let html = _html || ''; if (nextSibling === null) { parent.insertAdjacentHTML('beforeend', html); diff --git a/packages/@glimmer/runtime/lib/vm/element-builder.ts b/packages/@glimmer/runtime/lib/vm/element-builder.ts index 7a895efdc3..7fb6ae5c9a 100644 --- a/packages/@glimmer/runtime/lib/vm/element-builder.ts +++ b/packages/@glimmer/runtime/lib/vm/element-builder.ts @@ -482,7 +482,7 @@ export class SimpleBlockTracker implements Tracker { } finalize(stack: ElementBuilder) { - if (!this.first) { + if (this.first === null) { stack.appendComment(''); } } diff --git a/packages/@glimmer/runtime/test/updating-test.ts b/packages/@glimmer/runtime/test/updating-test.ts index 19860d4ded..855e5bb0ef 100644 --- a/packages/@glimmer/runtime/test/updating-test.ts +++ b/packages/@glimmer/runtime/test/updating-test.ts @@ -721,61 +721,66 @@ module('[glimmer-runtime] Updating', hooks => { }, { name: 'triple curlies', - template: '
{{{value}}}
', + template: '
before {{{value}}} after
', values: [ { input: 'hello', - expected: '
hello
', + expected: '
before hello after
', description: 'plain string', }, { input: 'hello', - expected: '
hello
', + expected: '
before hello after
', description: 'string containing HTML', }, { input: null, - expected: '
', + expected: '
before after
', description: 'null literal', }, { input: undefined, - expected: '
', + expected: '
before after
', description: 'undefined literal', }, + { + input: ' ', + expected: '
before after
', + description: 'blank string', + }, { input: makeSafeString('hello'), - expected: '
hello
', + expected: '
before hello after
', description: 'safe string containing HTML', }, { input: makeElement('p', 'hello'), - expected: '

hello

', + expected: '
before

hello

after
', description: 'DOM node containing and element with text', }, { input: makeFragment([makeElement('p', 'one'), makeElement('p', 'two')]), - expected: '

one

two

', + expected: '
before

one

two

after
', description: 'DOM fragment containing multiple nodes', }, { input: 'not modified', - expected: '
not modified
', + expected: '
before not modified after
', description: 'plain string (not modified, first render)', }, { input: 'not modified', - expected: '
not modified
', + expected: '
before not modified after
', description: 'plain string (not modified, second render)', }, { input: 0, - expected: '
0
', + expected: '
before 0 after
', description: 'number literal (0)', }, { input: true, - expected: '
true
', + expected: '
before true after
', description: 'boolean literal (true)', }, { @@ -784,9 +789,14 @@ module('[glimmer-runtime] Updating', hooks => { return 'I am an Object'; }, }, - expected: '
I am an Object
', + expected: '
before I am an Object after
', description: 'object with a toString function', }, + { + input: 'hello', + expected: '
before hello after
', + description: 'reset', + }, ], }, ].forEach(config => { @@ -870,11 +880,11 @@ module('[glimmer-runtime] Updating', hooks => { render(template, input); - equalTokens(root, '
', 'Initial render'); + equalTokens(root, '
', 'Initial render'); rerender(); - equalTokens(root, '
', 'no change'); + equalTokens(root, '
', 'no change'); input.value = 'Bold and spicy'; rerender(); @@ -884,7 +894,7 @@ module('[glimmer-runtime] Updating', hooks => { input.value = ''; rerender(); - equalTokens(root, '
', 'back to empty string'); + equalTokens(root, '
', 'back to empty string'); }); class ValueReference extends ConstReference {