@@ -14,6 +14,7 @@ import { Debouncer } from '../utils/debounce.js';
14
14
import { enqueueDebouncer , flush } from '../utils/flush.js' ;
15
15
import { microTask } from '../utils/async.js' ;
16
16
import { root } from '../utils/path.js' ;
17
+ import { wrap } from '../utils/wrap.js' ;
17
18
18
19
/**
19
20
* The `<dom-if>` element will stamp a light-dom `<template>` child when
@@ -120,9 +121,9 @@ export class DomIf extends PolymerElement {
120
121
*/
121
122
disconnectedCallback ( ) {
122
123
super . disconnectedCallback ( ) ;
123
- if ( ! this . parentNode ||
124
- ( this . parentNode . nodeType == Node . DOCUMENT_FRAGMENT_NODE &&
125
- ! this . parentNode . host ) ) {
124
+ const parent = Polymer . wrap ( this ) . parentNode ;
125
+ if ( ! parent || ( parent . nodeType == Node . DOCUMENT_FRAGMENT_NODE &&
126
+ ! Polymer . wrap ( parent ) . host ) ) {
126
127
this . __teardownInstance ( ) ;
127
128
}
128
129
}
@@ -174,15 +175,15 @@ export class DomIf extends PolymerElement {
174
175
}
175
176
176
177
__ensureInstance ( ) {
177
- let parentNode = this . parentNode ;
178
+ let parentNode = wrap ( this ) . parentNode ;
178
179
// Guard against element being detached while render was queued
179
180
if ( parentNode ) {
180
181
if ( ! this . __ctor ) {
181
- let template = /** @type {HTMLTemplateElement } */ ( this . querySelector ( 'template' ) ) ;
182
+ let template = /** @type {HTMLTemplateElement } */ ( wrap ( this ) . querySelector ( 'template' ) ) ;
182
183
if ( ! template ) {
183
184
// Wait until childList changes and template should be there by then
184
185
let observer = new MutationObserver ( ( ) => {
185
- if ( this . querySelector ( 'template' ) ) {
186
+ if ( wrap ( this ) . querySelector ( 'template' ) ) {
186
187
observer . disconnect ( ) ;
187
188
this . __render ( ) ;
188
189
} else {
@@ -219,16 +220,16 @@ export class DomIf extends PolymerElement {
219
220
}
220
221
if ( ! this . __instance ) {
221
222
this . __instance = new this . __ctor ( ) ;
222
- parentNode . insertBefore ( this . __instance . root , this ) ;
223
+ wrap ( parentNode ) . insertBefore ( this . __instance . root , this ) ;
223
224
} else {
224
225
this . __syncHostProperties ( ) ;
225
226
let c$ = this . __instance . children ;
226
227
if ( c$ && c$ . length ) {
227
228
// Detect case where dom-if was re-attached in new position
228
- let lastChild = this . previousSibling ;
229
+ let lastChild = wrap ( this ) . previousSibling ;
229
230
if ( lastChild !== c$ [ c$ . length - 1 ] ) {
230
231
for ( let i = 0 , n ; ( i < c$ . length ) && ( n = c$ [ i ] ) ; i ++ ) {
231
- parentNode . insertBefore ( n , this ) ;
232
+ wrap ( parentNode ) . insertBefore ( n , this ) ;
232
233
}
233
234
}
234
235
}
@@ -253,12 +254,12 @@ export class DomIf extends PolymerElement {
253
254
let c$ = this . __instance . children ;
254
255
if ( c$ && c$ . length ) {
255
256
// use first child parent, for case when dom-if may have been detached
256
- let parent = c$ [ 0 ] . parentNode ;
257
+ let parent = wrap ( c$ [ 0 ] ) . parentNode ;
257
258
// Instance children may be disconnected from parents when dom-if
258
259
// detaches if a tree was innerHTML'ed
259
260
if ( parent ) {
260
261
for ( let i = 0 , n ; ( i < c$ . length ) && ( n = c$ [ i ] ) ; i ++ ) {
261
- parent . removeChild ( n ) ;
262
+ wrap ( parent ) . removeChild ( n ) ;
262
263
}
263
264
}
264
265
}
0 commit comments