From 28e1728b29adf323e82e2d78062125f9ba57dd02 Mon Sep 17 00:00:00 2001 From: Pedro Nauck Date: Sat, 11 Aug 2018 01:14:47 -0300 Subject: [PATCH] fix(docz-core): prevent crash on delete entry --- packages/docz-core/templates/index.tpl.js | 8 +++++- packages/docz-core/templates/root.tpl.js | 4 +-- packages/docz/src/components/DocPreview.tsx | 30 +++++++++++---------- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/packages/docz-core/templates/index.tpl.js b/packages/docz-core/templates/index.tpl.js index 7c4a71482..6ae7900a0 100644 --- a/packages/docz-core/templates/index.tpl.js +++ b/packages/docz-core/templates/index.tpl.js @@ -1,6 +1,8 @@ <% if (!isProd) {%>import 'webpack-serve-overlay'<%}%> import React from 'react' import ReactDOM from 'react-dom' + +import { imports } from './imports' import Root from './root' const _onPreRenders = [<% if (onPreRenders) {%><%- onPreRenders %><%}%>] @@ -12,7 +14,11 @@ const onPostRender = () => _onPostRenders.forEach(f => f && f()) const root = document.querySelector('#root') const render = (Component = Root) => { onPreRender() - ReactDOM.render(, root, onPostRender) + ReactDOM.render(, root, onPostRender) +} + +if (module.hot) { + module.hot.accept('./imports', () => render(Root)) } render(Root) diff --git a/packages/docz-core/templates/root.tpl.js b/packages/docz-core/templates/root.tpl.js index 8dc77181e..b5c402795 100644 --- a/packages/docz-core/templates/root.tpl.js +++ b/packages/docz-core/templates/root.tpl.js @@ -1,13 +1,11 @@ import React from 'react' import { hot } from 'react-hot-loader' import Theme from '<%- theme %>' - -import { imports } from './imports' import db from './db.json' <% if (wrapper) {%>import Wrapper from '<%- wrapper %>'<%}%> -const Root = () => ( +const Root = ({ imports }) => ( = ({ const entry = entries[path] return ( - ( - - )} - /> + entry && ( + ( + + )} + /> + ) ) })} {NotFound && }