diff --git a/core/docz/src/utils/createState.tsx b/core/docz/src/utils/createState.tsx index 860712559..becb968a5 100644 --- a/core/docz/src/utils/createState.tsx +++ b/core/docz/src/utils/createState.tsx @@ -41,9 +41,6 @@ export function create(initial: T): State { public componentWillUnmount(): void { listeners.clear() } - public shouldComponentUpdate(nextProps: any, nextState: any): boolean { - return !equal(this.state, nextState) - } public render(): React.ReactNode { return ( {this.props.children} diff --git a/core/gatsby-theme-docz/package.json b/core/gatsby-theme-docz/package.json index 77080837d..2c5913207 100644 --- a/core/gatsby-theme-docz/package.json +++ b/core/gatsby-theme-docz/package.json @@ -28,6 +28,7 @@ "gatsby-plugin-compile-es6-packages": "^1.0.6", "gatsby-plugin-manifest": "^2.0.17", "gatsby-plugin-react-helmet": "^3.0.6", + "lodash": "^4.17.11", "prop-types": "^15.7.2", "react": "^16.8.2", "react-dom": "^16.8.2", diff --git a/core/gatsby-theme-docz/src/node/createPagesStatefully.js b/core/gatsby-theme-docz/src/node/createPagesStatefully.js index c5e54f82c..cd7def2c8 100644 --- a/core/gatsby-theme-docz/src/node/createPagesStatefully.js +++ b/core/gatsby-theme-docz/src/node/createPagesStatefully.js @@ -2,10 +2,11 @@ const path = require('path') const chokidar = require('chokidar') const { Entries } = require('docz-core') const { parseConfig } = require('../utils/parseConfig') +const { get } = require('lodash/fp') const getEntry = async (filepath, entries) => { const map = await entries.get() - return map[filepath] + return get(filepath, map) } const mountRoute = (base = '/', route) => { @@ -25,8 +26,8 @@ module.exports = async ({ store, actions }, opts) => { }) const handleCreatePage = async filepath => { - const component = path.join(paths.root, filepath) const entry = await getEntry(filepath, entries) + const component = path.join(paths.root, filepath) if (entry) { createPage({ @@ -50,10 +51,16 @@ module.exports = async ({ store, actions }, opts) => { } } + const allEntries = await entries.get() + await Promise.all( + Object.values(allEntries).map(async value => { + handleCreatePage(value.filepath) + }) + ) + return new Promise((resolve, reject) => { watcher .on('add', handleCreatePage) - .on('change', handleCreatePage) .on('unlink', handleDeletePage) .on('ready', () => resolve()) .on('error', err => reject(err))