Skip to content

Commit 7b6c5a1

Browse files
committed
Conservative backport of #852 to release-0-25
1 parent fa25ea3 commit 7b6c5a1

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

packages/@glimmer/runtime/lib/dom/helper.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export class DOMChanges extends DOMOperations {
193193
}
194194
}
195195

196-
export function insertHTMLBefore(this: void, _useless: Simple.Element, _parent: Simple.Element, _nextSibling: Option<Simple.Node>, html: string): Bounds { // tslint:disable-line
196+
export function insertHTMLBefore(this: void, _useless: Simple.Element, _parent: Simple.Element, _nextSibling: Option<Simple.Node>, _html: string): Bounds { // tslint:disable-line
197197
// TypeScript vendored an old version of the DOM spec where `insertAdjacentHTML`
198198
// only exists on `HTMLElement` but not on `Element`. We actually work with the
199199
// newer version of the DOM API here (and monkey-patch this method in `./compat`
@@ -205,9 +205,7 @@ export function insertHTMLBefore(this: void, _useless: Simple.Element, _parent:
205205
let prev = nextSibling ? nextSibling.previousSibling : parent.lastChild;
206206
let last: Simple.Node | null;
207207

208-
if (html === null || html === '') {
209-
return new ConcreteBounds(parent, null, null);
210-
}
208+
let html = _html || '<!---->';
211209

212210
if (nextSibling === null) {
213211
parent.insertAdjacentHTML('beforeend', html);

packages/@glimmer/runtime/test/updating-test.ts

+24-16
Original file line numberDiff line numberDiff line change
@@ -619,59 +619,67 @@ module("[glimmer-runtime] Updating", hooks => {
619619
}]
620620
}, {
621621
name: 'triple curlies',
622-
template: '<div>{{{value}}}</div>',
622+
template: '<div>before {{{value}}} after</div>',
623623
values: [{
624624
input: 'hello',
625-
expected: '<div>hello</div>',
625+
expected: '<div>before hello after</div>',
626626
description: 'plain string'
627627
}, {
628628
input: '<b>hello</b>',
629-
expected: '<div><b>hello</b></div>',
629+
expected: '<div>before <b>hello</b> after</div>',
630630
description: 'string containing HTML'
631631
}, {
632632
input: null,
633-
expected: '<div></div>',
633+
expected: '<div>before <!---> after</div>',
634634
description: 'null literal'
635635
}, {
636636
input: undefined,
637-
expected: '<div></div>',
637+
expected: '<div>before <!---> after</div>',
638638
description: 'undefined literal'
639639
}, {
640+
input: ' ',
641+
expected: '<div>before after</div>',
642+
description: 'blank string',
643+
},{
640644
input: makeSafeString('<b>hello</b>'),
641-
expected: '<div><b>hello</b></div>',
645+
expected: '<div>before <b>hello</b> after</div>',
642646
description: 'safe string containing HTML'
643647
}, {
644648
input: makeElement('p', 'hello'),
645-
expected: '<div><p>hello</p></div>',
649+
expected: '<div>before <p>hello</p> after</div>',
646650
description: 'DOM node containing and element with text'
647651
}, {
648652
input: makeFragment([makeElement('p', 'one'), makeElement('p', 'two')]),
649-
expected: '<div><p>one</p><p>two</p></div>',
653+
expected: '<div>before <p>one</p><p>two</p> after</div>',
650654
description: 'DOM fragment containing multiple nodes'
651655
}, {
652656
input: 'not modified',
653-
expected: '<div>not modified</div>',
657+
expected: '<div>before not modified after</div>',
654658
description: 'plain string (not modified, first render)'
655659
}, {
656660
input: 'not modified',
657-
expected: '<div>not modified</div>',
661+
expected: '<div>before not modified after</div>',
658662
description: 'plain string (not modified, second render)'
659663
}, {
660664
input: 0,
661-
expected: '<div>0</div>',
665+
expected: '<div>before 0 after</div>',
662666
description: 'number literal (0)'
663667
}, {
664668
input: true,
665-
expected: '<div>true</div>',
669+
expected: '<div>before true after</div>',
666670
description: 'boolean literal (true)'
667671
}, {
668672
input: {
669673
toString() {
670674
return 'I am an Object';
671675
}
672676
},
673-
expected: '<div>I am an Object</div>',
677+
expected: '<div>before I am an Object after</div>',
674678
description: 'object with a toString function'
679+
}, {
680+
input: 'hello',
681+
expected: '<div>before hello after</div>',
682+
description: 'reset',
675683
}]
676684
}].forEach(config => {
677685
test(`updating ${config.name} produces expected result`, () => {
@@ -737,11 +745,11 @@ module("[glimmer-runtime] Updating", hooks => {
737745

738746
render(template, input);
739747

740-
equalTokens(root, '<div></div>', "Initial render");
748+
equalTokens(root, '<div><!----></div>', "Initial render");
741749

742750
rerender();
743751

744-
equalTokens(root, '<div></div>', "no change");
752+
equalTokens(root, '<div><!----></div>', "no change");
745753

746754
input.value = '<b>Bold and spicy</b>';
747755
rerender();
@@ -751,7 +759,7 @@ module("[glimmer-runtime] Updating", hooks => {
751759
input.value = '';
752760
rerender();
753761

754-
equalTokens(root, '<div></div>', "back to empty string");
762+
equalTokens(root, '<div><!----></div>', "back to empty string");
755763
});
756764

757765
class ValueReference<T> extends ConstReference<T> {

0 commit comments

Comments
 (0)