Skip to content
This repository has been archived by the owner on Jan 24, 2025. It is now read-only.

Commit

Permalink
fix(docz-core): prevent crash on delete entry
Browse files Browse the repository at this point in the history
  • Loading branch information
pedronauck committed Aug 11, 2018
1 parent e0a95b3 commit 28e1728
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
8 changes: 7 additions & 1 deletion packages/docz-core/templates/index.tpl.js
Original file line number Diff line number Diff line change
@@ -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 %><%}%>]
Expand All @@ -12,7 +14,11 @@ const onPostRender = () => _onPostRenders.forEach(f => f && f())
const root = document.querySelector('#root')
const render = (Component = Root) => {
onPreRender()
ReactDOM.render(<Component />, root, onPostRender)
ReactDOM.render(<Component imports={imports} />, root, onPostRender)
}

if (module.hot) {
module.hot.accept('./imports', () => render(Root))
}

render(Root)
4 changes: 1 addition & 3 deletions packages/docz-core/templates/root.tpl.js
Original file line number Diff line number Diff line change
@@ -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 }) => (
<Theme
db={db}
imports={imports}
Expand Down
30 changes: 16 additions & 14 deletions packages/docz/src/components/DocPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,20 +98,22 @@ export const DocPreview: SFC<DocPreviewProps> = ({
const entry = entries[path]

return (
<Route
exact
key={entry.id}
path={entry.route}
render={props => (
<AsyncRoute
{...props}
path={path}
entries={entries}
imports={imports}
components={components}
/>
)}
/>
entry && (
<Route
exact
key={entry.id}
path={entry.route}
render={props => (
<AsyncRoute
{...props}
path={path}
entries={entries}
imports={imports}
components={components}
/>
)}
/>
)
)
})}
{NotFound && <Route component={NotFound} />}
Expand Down

0 comments on commit 28e1728

Please sign in to comment.