Adding custom element polyfill (#177)

This commit is contained in:
Jake Archibald
2018-09-27 14:49:45 +01:00
committed by GitHub
parent c9fe5ffbcf
commit 5e66e0acc4
4 changed files with 16 additions and 0 deletions

24
src/init-app.tsx Normal file
View File

@@ -0,0 +1,24 @@
import { h, render } from 'preact';
import './lib/fix-pmc';
import './style';
import App from './components/App';
// Find the outermost Element in our server-rendered HTML structure.
let root = document.querySelector('#app') || undefined;
// "attach" the client-side rendering to it, updating the DOM in-place instead of replacing:
root = render(<App />, document.body, root);
// In production, this entire condition is removed.
if (process.env.NODE_ENV === 'development') {
// Enable support for React DevTools and some helpful console warnings:
require('preact/debug');
// When an update to any module is received, re-import the app and trigger a full re-render:
module.hot.accept('./components/App', () => {
// tslint:disable-next-line variable-name
import('./components/App').then(({ default: App }) => {
root = render(<App />, document.body, root);
});
});
}