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

Fix rendering into shadow root #11037

Merged
merged 2 commits into from
Oct 2, 2017
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
1 change: 1 addition & 0 deletions fixtures/dom/src/components/Header.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class Header extends React.Component {
<option value="/date-inputs">Date Inputs</option>
<option value="/error-handling">Error Handling</option>
<option value="/event-pooling">Event Pooling</option>
<option value="/custom-elements">Custom Elements</option>
</select>
</label>
<label htmlFor="react_version">
Expand Down
47 changes: 47 additions & 0 deletions fixtures/dom/src/components/fixtures/custom-elements/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import FixtureSet from '../../FixtureSet';
import TestCase from '../../TestCase';

const React = window.React;
const ReactDOM = window.ReactDOM;

class HelloWorld extends React.Component {
render() {
return <h1>Hello, world!</h1>;
}
}

// Babel breaks web components.
// https://github.com/w3c/webcomponents/issues/587
// eslint-disable-next-line no-new-func
const MyElement = new Function(
'React',
'ReactDOM',
'HelloWorld',
`
return class MyElement extends HTMLElement {
constructor() {
super();
const shadowRoot = this.attachShadow({ mode:'open' });
ReactDOM.render(React.createElement(HelloWorld), shadowRoot);
}
}`
)(React, ReactDOM, HelloWorld);

customElements.define('my-element', MyElement);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaearon this is causing the fixtures to fail in browsers that don't have customElements. We should either provide a polyfill or only run this fixture in browsers that support the custom element registry.


export default class ButtonTestCases extends React.Component {
render() {
return (
<FixtureSet
title="Custom Elements"
description="Support for Custom Element DOM standards.">
<TestCase title="Rendering into shadow root">
<TestCase.ExpectedResult>
You should see "Hello, World" printed below.{' '}
</TestCase.ExpectedResult>
<my-element />
</TestCase>
</FixtureSet>
);
}
}
3 changes: 3 additions & 0 deletions fixtures/dom/src/components/fixtures/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ButtonFixtures from './buttons';
import DateInputFixtures from './date-inputs';
import ErrorHandling from './error-handling';
import EventPooling from './event-pooling';
import CustomElementFixtures from './custom-elements';

const React = window.React;

Expand Down Expand Up @@ -40,6 +41,8 @@ function FixturesPage() {
return <ErrorHandling />;
case '/event-pooling':
return <EventPooling />;
case '/custom-elements':
return <CustomElementFixtures />;
default:
return <p>Please select a test fixture.</p>;
}
Expand Down
Loading