Skip to content

Commit

Permalink
[docs] Dodge issue with hoist-non-react-statics (mui#10896)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari authored Apr 3, 2018
1 parent 1b66305 commit 7e2f42f
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 36 deletions.
10 changes: 9 additions & 1 deletion docs/src/modules/components/AppWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ AppWrapper.propTypes = {
uiTheme: PropTypes.object.isRequired,
};

const AppWrapper2 = polyfill(AppWrapper);

// Solve an isolation issue with hoist-non-react-statics.
// TODO: remove once hoist-non-react-statics has been updated.
function AppWrapper3(props) {
return <AppWrapper2 {...props} />;
}

export default connect(state => ({
uiTheme: state.theme,
}))(polyfill(AppWrapper));
}))(AppWrapper3);
6 changes: 5 additions & 1 deletion docs/src/modules/utils/find.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ const jsRegex = /\.js$/;
const blackList = ['/.eslintrc', '/_document'];

// Returns the next.js pages available in a nested format.
// The output is in the next.js format.
// Each pathname is a route you can navigate to.
function findPages(
options = {},
directory = path.resolve(__dirname, '../../../../pages'),
Expand All @@ -88,7 +90,9 @@ function findPages(
const pathname = itemPath
.replace(new RegExp(`\\${path.sep}`, 'g'), '/')
.replace(/^.*\/pages/, '')
.replace('.js', '');
.replace('.js', '')
.replace(/^\/index$/, '/') // Replace `index` by `/`.
.replace(/\/index$/, '');

if (
options.front &&
Expand Down
35 changes: 11 additions & 24 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,38 +47,25 @@ module.exports = {
});
},
webpackDevMiddleware: config => config,
// next.js also provide a `defaultPathMap` so we could simplify the logic.
// However, we keep it in order to prevent any future regression on the `findPages()` side.
exportPathMap: () => {
// Replace `index` by `/`.
function sanitize(pathname) {
return pathname.replace(/^\/index$/, '/').replace(/\/index$/, '');
}

const map = {};

// Do not use a recursive logic as we don't want to support a depth > 2.
findPages().forEach(lvl0Page => {
if (!lvl0Page.children) {
map[sanitize(lvl0Page.pathname)] = {
page: sanitize(lvl0Page.pathname),
};
return;
}

lvl0Page.children.forEach(lvl1Page => {
if (!lvl1Page.children) {
map[sanitize(lvl1Page.pathname)] = {
page: sanitize(lvl1Page.pathname),
function generateMap(pages) {
pages.forEach(page => {
if (!page.children) {
map[page.pathname] = {
page: page.pathname,
};
return;
}

lvl1Page.children.forEach(lvl2Page => {
map[sanitize(lvl2Page.pathname)] = {
page: sanitize(lvl2Page.pathname),
};
});
generateMap(page.children);
});
});
}

generateMap(findPages());

return map;
},
Expand Down
28 changes: 18 additions & 10 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2500,10 +2500,6 @@ content-disposition@0.5.2:
version "0.5.2"
resolved "https://registry.yarnpkg.com/content-disposition/-/content-disposition-0.5.2.tgz#0cf68bb9ddf5f2be7961c3a85178cb85dba78cb4"

content-type-parser@^1.0.2:
version "1.0.2"
resolved "https://registry.yarnpkg.com/content-type-parser/-/content-type-parser-1.0.2.tgz#caabe80623e63638b2502fd4c7f12ff4ce2352e7"

content-type@~1.0.4:
version "1.0.4"
resolved "https://registry.yarnpkg.com/content-type/-/content-type-1.0.4.tgz#e138cc75e040c727b1966fe5e5f8c9aee256fe3b"
Expand Down Expand Up @@ -2969,6 +2965,14 @@ data-uri-to-buffer@1:
version "1.2.0"
resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-1.2.0.tgz#77163ea9c20d8641b4707e8f18abdf9a78f34835"

data-urls@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/data-urls/-/data-urls-1.0.0.tgz#24802de4e81c298ea8a9388bb0d8e461c774684f"
dependencies:
abab "^1.0.4"
whatwg-mimetype "^2.0.0"
whatwg-url "^6.4.0"

date-format@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/date-format/-/date-format-1.2.0.tgz#615e828e233dd1ab9bb9ae0950e0ceccfa6ecad8"
Expand Down Expand Up @@ -5743,17 +5747,16 @@ jscodeshift@^0.4.0:
write-file-atomic "^1.2.0"

jsdom@^11.3.0:
version "11.6.2"
resolved "https://registry.yarnpkg.com/jsdom/-/jsdom-11.6.2.tgz#25d1ef332d48adf77fc5221fe2619967923f16bb"
version "11.7.0"
resolved "https://registry.yarnpkg.com/jsdom/-/jsdom-11.7.0.tgz#8b45b657dae90d6d2d3a5f5d1126bb7102d0a172"
dependencies:
abab "^1.0.4"
acorn "^5.3.0"
acorn-globals "^4.1.0"
array-equal "^1.0.0"
browser-process-hrtime "^0.1.2"
content-type-parser "^1.0.2"
cssom ">= 0.3.2 < 0.4.0"
cssstyle ">= 0.2.37 < 0.3.0"
data-urls "^1.0.0"
domexception "^1.0.0"
escodegen "^1.9.0"
html-encoding-sniffer "^1.0.2"
Expand All @@ -5769,6 +5772,7 @@ jsdom@^11.3.0:
w3c-hr-time "^1.0.1"
webidl-conversions "^4.0.2"
whatwg-encoding "^1.0.3"
whatwg-mimetype "^2.1.0"
whatwg-url "^6.4.0"
ws "^4.0.0"
xml-name-validator "^3.0.0"
Expand Down Expand Up @@ -8300,8 +8304,8 @@ react-jss@^8.1.0:
theming "^1.3.0"

react-lifecycles-compat@^1.0.2:
version "1.1.0"
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-1.1.0.tgz#6641d0709bd5505329b5c90322147ef2d343485c"
version "1.1.2"
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-1.1.2.tgz#6b3a97bae12f421e57771d4715c7ebcd2833c07e"

react-number-format@^3.0.2:
version "3.3.0"
Expand Down Expand Up @@ -10651,6 +10655,10 @@ whatwg-fetch@>=0.10.0:
version "2.0.4"
resolved "https://registry.yarnpkg.com/whatwg-fetch/-/whatwg-fetch-2.0.4.tgz#dde6a5df315f9d39991aa17621853d720b85566f"

whatwg-mimetype@^2.0.0, whatwg-mimetype@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-2.1.0.tgz#f0f21d76cbba72362eb609dbed2a30cd17fcc7d4"

whatwg-url@^6.4.0:
version "6.4.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-6.4.0.tgz#08fdf2b9e872783a7a1f6216260a1d66cc722e08"
Expand Down

0 comments on commit 7e2f42f

Please sign in to comment.