Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prevent main fragment being created twice #1064

Merged
merged 2 commits into from
Jan 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/generators/dom/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ export default function dom(
parsed.html.build();
const { block } = parsed.html;

// prevent fragment being created twice (#1063)
if (options.customElement) block.builders.create.addLine(`this.c = @noop;`);

generator.stylesheet.warnOnUnusedSelectors(options.onwarn);

const builder = new CodeBuilder();
Expand Down
4 changes: 4 additions & 0 deletions test/custom-elements/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ describe('custom-elements', function() {

const nightmare = new Nightmare({ show: false });

nightmare.on('console', (type, ...args) => {
console[type](...args);
});

let svelte;
let server;
let bundle;
Expand Down
13 changes: 13 additions & 0 deletions test/custom-elements/samples/nested/Counter.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<button on:click='set({ count: count + 1 })'>count: {{count}}</button>

<script>
export default {
tag: 'my-counter',

data() {
return {
count: 0
};
}
};
</script>
12 changes: 12 additions & 0 deletions test/custom-elements/samples/nested/main.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Counter bind:count/>
<p>clicked {{count}} times</p>

<script>
import Counter from './Counter.html';

export default {
tag: 'my-app',

components: { Counter }
};
</script>
17 changes: 17 additions & 0 deletions test/custom-elements/samples/nested/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import * as assert from 'assert';
import './main.html';

export default function (target) {
target.innerHTML = '<my-app/>';
const el = target.querySelector('my-app');
const counter = el.shadowRoot.querySelector('my-counter');
const button = counter.shadowRoot.querySelector('button');

assert.equal(counter.count, 0);
assert.equal(counter.shadowRoot.innerHTML, `<button>count: 0</button>`);

button.dispatchEvent(new MouseEvent('click'));

assert.equal(counter.count, 1);
assert.equal(counter.shadowRoot.innerHTML, `<button>count: 1</button>`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ function create_main_fragment(state, component) {
c: function create() {
div = createElement("div");
div.textContent = "fades in";
this.c = noop;
},

m: function mount(target, anchor) {
Expand Down
1 change: 1 addition & 0 deletions test/js/samples/css-shadow-dom-keyframes/expected.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ function create_main_fragment(state, component) {
c: function create() {
div = createElement("div");
div.textContent = "fades in";
this.c = noop;
},

m: function mount(target, anchor) {
Expand Down