Skip to content

Commit d70a41f

Browse files
authored
fix: prevent style tags from piling up (#71)
1 parent 4b585aa commit d70a41f

File tree

3 files changed

+114
-66
lines changed

3 files changed

+114
-66
lines changed

package-lock.json

Lines changed: 101 additions & 64 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"hash-sum": "^2.0.0",
2323
"prismjs": "^1.21.0",
2424
"recast": "^0.19.1",
25-
"vue-inbrowser-compiler": "^4.33.4",
25+
"vue-inbrowser-compiler": "^4.42.0",
2626
"vue-prism-editor": "^1.2.2",
2727
"vue-template-compiler": "^2.6.12"
2828
},

src/Preview.vue

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ export default {
8686
created() {
8787
this.renderComponent(this.code.trim());
8888
},
89+
destroyed() {
90+
this.removeScopedStyle();
91+
},
8992
watch: {
9093
code(value) {
9194
this.renderComponent(value.trim());
@@ -118,6 +121,11 @@ export default {
118121
this.$emit("error", e);
119122
this.error = e.message;
120123
},
124+
removeStyle() {
125+
if (this.removeScopedStyle) {
126+
this.removeScopedStyle();
127+
}
128+
},
121129
renderComponent(code) {
122130
let options = {};
123131
let style;
@@ -182,11 +190,14 @@ export default {
182190
options.components = { ...options.components, ...this.components };
183191
}
184192
}
193+
194+
this.removeStyle();
195+
185196
if (style) {
186197
// To add the scope id attribute to each item in the html
187198
// this way when we add the scoped style sheet it will be aplied
188199
options._scopeId = `data-${this.scope}`;
189-
addScopedStyle(style, this.scope);
200+
this.removeScopedStyle = addScopedStyle(style, this.scope);
190201
}
191202
192203
if (options.template || options.render) {

0 commit comments

Comments
 (0)