Skip to content

Commit 7eccd6c

Browse files
author
William Bernting
committed
Fixed exposing shadowRoot in mounted() hook
1 parent 89dffde commit 7eccd6c

File tree

5 files changed

+40
-14
lines changed

5 files changed

+40
-14
lines changed

dist/vue-wc-wrapper.es5.global.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ function wrap(Vue, Component) {
563563
var _connectedCallback = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
564564
var _this5 = this;
565565

566-
var wrapper, syncInitialAttributes;
566+
var wrapper, syncInitialAttributes, tempContainer;
567567
return regeneratorRuntime.wrap(function _callee$(_context) {
568568
while (1) {
569569
switch (_context.prev = _context.next) {
@@ -601,9 +601,13 @@ function wrap(Vue, Component) {
601601
} // initialize children
602602

603603

604-
this.updateSlotChildren();
605-
wrapper.$mount();
606-
this.shadowRoot.appendChild(wrapper.$el);
604+
this.updateSlotChildren(); // doing this will let us access the shadow root via `this.$root.$el.getRootNode()`
605+
// inside of the mounted hook, which is important for copying global styles to the shadow dom.
606+
607+
tempContainer = document.createElement('div');
608+
this.shadowRoot.appendChild(tempContainer); // tempContainer will be completely rewritten
609+
610+
wrapper.$mount(tempContainer);
607611
} else {
608612
callHooks(this.vueComponent, 'activated');
609613
}

dist/vue-wc-wrapper.es5.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ function wrap(Vue, Component) {
560560
var _connectedCallback = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
561561
var _this5 = this;
562562

563-
var wrapper, syncInitialAttributes;
563+
var wrapper, syncInitialAttributes, tempContainer;
564564
return regeneratorRuntime.wrap(function _callee$(_context) {
565565
while (1) {
566566
switch (_context.prev = _context.next) {
@@ -598,9 +598,13 @@ function wrap(Vue, Component) {
598598
} // initialize children
599599

600600

601-
this.updateSlotChildren();
602-
wrapper.$mount();
603-
this.shadowRoot.appendChild(wrapper.$el);
601+
this.updateSlotChildren(); // doing this will let us access the shadow root via `this.$root.$el.getRootNode()`
602+
// inside of the mounted hook, which is important for copying global styles to the shadow dom.
603+
604+
tempContainer = document.createElement('div');
605+
this.shadowRoot.appendChild(tempContainer); // tempContainer will be completely rewritten
606+
607+
wrapper.$mount(tempContainer);
604608
} else {
605609
callHooks(this.vueComponent, 'activated');
606610
}

dist/vue-wc-wrapper.global.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -349,8 +349,14 @@ function wrap(Vue, Component) {
349349
}
350350
// initialize children
351351
this.updateSlotChildren();
352-
wrapper.$mount();
353-
this.shadowRoot.appendChild(wrapper.$el);
352+
353+
// doing this will let us access the shadow root via `this.$root.$el.getRootNode()`
354+
// inside of the mounted hook, which is important for copying global styles to the shadow dom.
355+
const tempContainer = document.createElement('div');
356+
this.shadowRoot.appendChild(tempContainer);
357+
358+
// tempContainer will be completely rewritten
359+
wrapper.$mount(tempContainer);
354360
} else {
355361
callHooks(this.vueComponent, 'activated');
356362
}

dist/vue-wc-wrapper.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,14 @@ function wrap(Vue, Component) {
346346
}
347347
// initialize children
348348
this.updateSlotChildren();
349-
wrapper.$mount();
350-
this.shadowRoot.appendChild(wrapper.$el);
349+
350+
// doing this will let us access the shadow root via `this.$root.$el.getRootNode()`
351+
// inside of the mounted hook, which is important for copying global styles to the shadow dom.
352+
const tempContainer = document.createElement('div');
353+
this.shadowRoot.appendChild(tempContainer);
354+
355+
// tempContainer will be completely rewritten
356+
wrapper.$mount(tempContainer);
351357
} else {
352358
callHooks(this.vueComponent, 'activated');
353359
}

src/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,14 @@ export default function wrap(Vue, Component) {
260260
}
261261
// initialize children
262262
this.updateSlotChildren()
263-
wrapper.$mount()
264-
this.shadowRoot.appendChild(wrapper.$el)
263+
264+
// doing this will let us access the shadow root via `this.$root.$el.getRootNode()`
265+
// inside of the mounted hook, which is important for copying global styles to the shadow dom.
266+
const tempContainer = document.createElement('div')
267+
this.shadowRoot.appendChild(tempContainer)
268+
269+
// tempContainer will be completely rewritten
270+
wrapper.$mount(tempContainer)
265271
} else {
266272
callHooks(this.vueComponent, 'activated')
267273
}

0 commit comments

Comments
 (0)