Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Include support for customised built-in elements (#2266)
* Include support for customised built-in elements

* Inline the variable declaration
  • Loading branch information
defx authored and JoviDeCroock committed Jan 22, 2020
1 parent d439563 commit a311b04
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/diff/index.js
Expand Up @@ -294,9 +294,13 @@ function diffElementNodes(
if (newVNode.type === null) {
return document.createTextNode(newProps);
}

dom = isSvg
? document.createElementNS('http://www.w3.org/2000/svg', newVNode.type)
: document.createElement(newVNode.type);
: document.createElement(
newVNode.type,
newProps.is && { is: newProps.is }
);
// we created a new parent, so none of the previously attached children can be reused:
excessDomChildren = null;
}
Expand Down
42 changes: 42 additions & 0 deletions test/browser/customBuiltInElements.test.js
@@ -0,0 +1,42 @@
import { createElement, render, Component } from 'preact';
import { setupScratch, teardown } from '../_util/helpers';

/** @jsx createElement */

describe('customised built-in elements', () => {
let scratch;

beforeEach(() => {
scratch = setupScratch();
});

afterEach(() => {
teardown(scratch);
});

it('should create built in elements correctly', () => {
class Foo extends Component {
constructor(props) {
super(props);
return true;
}
render() {
return <div is="built-in" />;
}
}

const spy = sinon.spy();

class BuiltIn extends HTMLDivElement {
connectedCallback() {
spy();
}
}

customElements.define('built-in', BuiltIn, { extends: 'div' });

render(<Foo />, scratch);

expect(spy).to.have.been.calledOnce;
});
});

0 comments on commit a311b04

Please sign in to comment.