diff --git a/packages/@glimmer/runtime/lib/vm/rehydrate-builder.ts b/packages/@glimmer/runtime/lib/vm/rehydrate-builder.ts index 743a854a7c..61ac66df6c 100644 --- a/packages/@glimmer/runtime/lib/vm/rehydrate-builder.ts +++ b/packages/@glimmer/runtime/lib/vm/rehydrate-builder.ts @@ -4,7 +4,7 @@ import { Environment } from '../environment'; import Bounds, { bounds, Cursor } from '../bounds'; import { Simple, Option, Opaque } from "@glimmer/interfaces"; import { DynamicContentWrapper } from './content/dynamic'; -import { expect, assert, Stack } from "@glimmer/util"; +import { expect, assert, Stack, isSerializationFirstNode, SERIALIZATION_FIRST_NODE_STRING} from "@glimmer/util"; import { SVG_NAMESPACE } from '../dom/helper'; export class RehydratingCursor extends Cursor { @@ -31,11 +31,11 @@ export class RehydrateBuilder extends NewElementBuilder implements ElementBuilde let node = this.currentCursor!.element.firstChild; while (node !== null) { - if (isComment(node) && node.nodeValue === '%+b:0%') { break; } + if (isComment(node) && isSerializationFirstNode(node)) { break; } node = node.nextSibling; } - assert(node, 'Must have opening comment for rehydration.'); + assert(node, `Must have opening comment for rehydration.`); this.candidate = node; } diff --git a/packages/@glimmer/util/index.ts b/packages/@glimmer/util/index.ts index 1b4fe3023f..3bfa8d4704 100644 --- a/packages/@glimmer/util/index.ts +++ b/packages/@glimmer/util/index.ts @@ -8,6 +8,8 @@ export { default as assert } from './lib/assert'; export { assign, fillNulls } from './lib/object-utils'; export { ensureGuid, initializeGuid, HasGuid } from './lib/guid'; +export { isSerializationFirstNode, SERIALIZATION_FIRST_NODE_STRING } from './lib/is-serialization-first-node'; + export { Stack, Dict, Set, DictSet, dict } from './lib/collections'; export { EMPTY_SLICE, LinkedList, LinkedListNode, ListNode, CloneableListNode, ListSlice, Slice } from './lib/list-utils'; export { EMPTY_ARRAY } from './lib/array-utils'; diff --git a/packages/@glimmer/util/lib/is-serialization-first-node.ts b/packages/@glimmer/util/lib/is-serialization-first-node.ts new file mode 100644 index 0000000000..053784faad --- /dev/null +++ b/packages/@glimmer/util/lib/is-serialization-first-node.ts @@ -0,0 +1,7 @@ +import { Simple } from '@glimmer/interfaces'; + +export const SERIALIZATION_FIRST_NODE_STRING = '%+b:0%'; + +export function isSerializationFirstNode(node: Simple.Node): boolean { + return node.nodeValue === SERIALIZATION_FIRST_NODE_STRING; +};