Skip to content

Commit 8c366fe

Browse files
Fix hydration error
Likely related to vercel/next.js#10355
1 parent 4357e89 commit 8c366fe

File tree

8 files changed

+22
-21
lines changed

8 files changed

+22
-21
lines changed

.eslintrc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ module.exports = {
4444
// we have to be disciplined about the usage and ensure the Number type for its
4545
// arguments
4646
'no-restricted-globals': ['error'].concat(confusingBrowserGlobals),
47-
'no-underscore-dangle': ['error', { allow: ['_rewriteUrlForNextExport'] }],
47+
'no-underscore-dangle': 'error',
4848
'prefer-arrow-callback': ['error', { allowNamedFunctions: true }],
4949
'prefer-destructuring': 'off', // Destructuring harm grep potential.
5050

docs/pages/_app.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import PropTypes from 'prop-types';
1111
import acceptLanguage from 'accept-language';
1212
import { create } from 'jss';
1313
import rtl from 'jss-rtl';
14-
import { Router as Router2, useRouter } from 'next/router';
14+
import { useRouter } from 'next/router';
15+
import { rewriteUrlForNextExport } from 'next/dist/next-server/lib/router/rewrite-url-for-export';
1516
import { StylesProvider, jssPreset } from '@material-ui/styles';
1617
import pages from 'docs/src/pages';
1718
import initRedux from 'docs/src/modules/redux/initRedux';
@@ -58,7 +59,7 @@ function LanguageNegotiation() {
5859

5960
React.useEffect(() => {
6061
const { userLanguage: userLanguageUrl, canonical } = pathnameToLanguage(
61-
Router2._rewriteUrlForNextExport(router.asPath),
62+
rewriteUrlForNextExport(router.asPath),
6263
);
6364
const preferedLanguage =
6465
getCookie('userLanguage') !== 'noDefault' && userLanguage === 'en'
@@ -289,7 +290,7 @@ function AppWrapper(props) {
289290
if (pathname !== '/') {
290291
// The leading / is only added to support static hosting (resolve /index.html).
291292
// We remove it to normalize the pathname.
292-
// See `_rewriteUrlForNextExport` on Next.js side.
293+
// See `rewriteUrlForNextExport` on Next.js side.
293294
pathname = pathname.replace(/\/$/, '');
294295
}
295296
const activePage = findActivePage(pages, pathname);

docs/pages/_document.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
22
import { ServerStyleSheets } from '@material-ui/styles';
33
import Document, { Head, Main, NextScript } from 'next/document';
4-
import { Router as Router2 } from 'next/router';
4+
import { rewriteUrlForNextExport } from 'next/dist/next-server/lib/router/rewrite-url-for-export';
55
import { LANGUAGES_SSR } from 'docs/src/modules/constants';
66
import { pathnameToLanguage } from 'docs/src/modules/utils/helpers';
77
import { themeColor } from 'docs/src/modules/components/ThemeContext';
@@ -48,20 +48,20 @@ export default class MyDocument extends Document {
4848
{/* SEO */}
4949
<link
5050
rel="canonical"
51-
href={`https://material-ui.com${Router2._rewriteUrlForNextExport(
51+
href={`https://material-ui.com${rewriteUrlForNextExport(
5252
`${userLanguage === 'en' ? '' : `/${userLanguage}`}${canonical}`,
5353
)}`}
5454
/>
5555
<link
5656
rel="alternate"
57-
href={`https://material-ui.com${Router2._rewriteUrlForNextExport(canonical)}`}
57+
href={`https://material-ui.com${rewriteUrlForNextExport(canonical)}`}
5858
hrefLang="x-default"
5959
/>
6060
{LANGUAGES_SSR.map(userLanguage2 => (
6161
<link
6262
key={userLanguage2}
6363
rel="alternate"
64-
href={`https://material-ui.com${Router2._rewriteUrlForNextExport(
64+
href={`https://material-ui.com${rewriteUrlForNextExport(
6565
`${userLanguage2 === 'en' ? '' : `/${userLanguage2}`}${canonical}`,
6666
)}`}
6767
hrefLang={userLanguage2}

docs/src/modules/components/AppFrame.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from 'react';
22
import PropTypes from 'prop-types';
33
import { useSelector } from 'react-redux';
4-
import Router, { Router as Router2, useRouter } from 'next/router';
4+
import Router, { useRouter } from 'next/router';
5+
import { rewriteUrlForNextExport } from 'next/dist/next-server/lib/router/rewrite-url-for-export';
56
import { withStyles, useTheme } from '@material-ui/core/styles';
67
import NProgress from 'nprogress';
78
import CssBaseline from '@material-ui/core/CssBaseline';
@@ -182,7 +183,7 @@ function AppFrame(props) {
182183
};
183184

184185
const router = useRouter();
185-
const { canonical } = pathnameToLanguage(Router2._rewriteUrlForNextExport(router.asPath));
186+
const { canonical } = pathnameToLanguage(rewriteUrlForNextExport(router.asPath));
186187
const { activePage } = React.useContext(PageContext);
187188

188189
let disablePermanent = false;

docs/src/modules/components/Head.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import NextHead from 'next/head';
3-
import { Router, useRouter } from 'next/router';
3+
import { useRouter } from 'next/router';
4+
import { rewriteUrlForNextExport } from 'next/dist/next-server/lib/router/rewrite-url-for-export';
45
import PropTypes from 'prop-types';
56
import { useSelector } from 'react-redux';
67

@@ -27,7 +28,7 @@ export default function Head(props) {
2728
<meta property="og:title" content={title} />
2829
<meta
2930
property="og:url"
30-
content={`https://material-ui.com${Router._rewriteUrlForNextExport(router.asPath)}`}
31+
content={`https://material-ui.com${rewriteUrlForNextExport(router.asPath)}`}
3132
/>
3233
<meta property="og:description" content={description} />
3334
<meta property="og:image" content="https://material-ui.com/static/logo.png" />

docs/src/modules/components/MarkdownLinks.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export async function handleEvent(event, as) {
2222
if (pathname !== '/') {
2323
// The leading / is only added to support static hosting (resolve /index.html).
2424
// We remove it to normalize the pathname.
25-
// See `_rewriteUrlForNextExport` on Next.js side.
25+
// See `rewriteUrlForNextExport` on Next.js side.
2626
pathname = pathname.replace(/\/$/, '');
2727
}
2828
pathname = pathnameToLanguage(pathname).canonical;

docs/src/modules/components/useMarkdownDocs.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import kebabCase from 'lodash/kebabCase';
3-
import { Router as Router2 } from 'next/router';
3+
import { rewriteUrlForNextExport } from 'next/dist/next-server/lib/router/rewrite-url-for-export';
44
import { useSelector } from 'react-redux';
55
import Demo from 'docs/src/modules/components/Demo';
66
import { getHeaders, getContents, demoRegexp } from 'docs/src/modules/utils/parseMarkdown';
@@ -80,9 +80,7 @@ export default function useMarkdownDocs(options) {
8080
${headers.components
8181
.map(
8282
component =>
83-
`- [&lt;${component} /&gt;](${Router2._rewriteUrlForNextExport(
84-
`/api/${kebabCase(component)}`,
85-
)})`,
83+
`- [&lt;${component} /&gt;](${rewriteUrlForNextExport(`/api/${kebabCase(component)}`)})`,
8684
)
8785
.join('\n')}
8886
`);

docs/src/modules/utils/generateMarkdown.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { parse as parseDoctrine } from 'doctrine';
22
import * as recast from 'recast';
33
import { parse as docgenParse } from 'react-docgen';
4-
import { Router as Router2 } from 'next/router';
4+
import { rewriteUrlForNextExport } from 'next/dist/next-server/lib/router/rewrite-url-for-export';
55
import { pageToTitle } from './helpers';
66
import { SOURCE_CODE_ROOT_URL, LANGUAGES_IN_PROGRESS } from 'docs/src/modules/constants';
77

@@ -331,7 +331,7 @@ function generateProps(reactAPI) {
331331
text = `${text}
332332
Any other props supplied will be provided to the root element (${
333333
reactAPI.inheritance
334-
? `[${reactAPI.inheritance.component}](${Router2._rewriteUrlForNextExport(
334+
? `[${reactAPI.inheritance.component}](${rewriteUrlForNextExport(
335335
reactAPI.inheritance.pathname,
336336
)})`
337337
: 'native element'
@@ -412,7 +412,7 @@ function generateInheritance(reactAPI) {
412412

413413
return `## Inheritance
414414
415-
The props of the [${inheritance.component}](${Router2._rewriteUrlForNextExport(
415+
The props of the [${inheritance.component}](${rewriteUrlForNextExport(
416416
inheritance.pathname,
417417
)}) component${suffix} are also available.
418418
You can take advantage of this behavior to [target nested components](/guides/api/#spread).
@@ -436,7 +436,7 @@ function generateDemos(reactAPI) {
436436
return `## Demos
437437
438438
${pagesMarkdown
439-
.map(page => `- [${pageToTitle(page)}](${Router2._rewriteUrlForNextExport(page.pathname)})`)
439+
.map(page => `- [${pageToTitle(page)}](${rewriteUrlForNextExport(page.pathname)})`)
440440
.join('\n')}
441441
442442
`;

0 commit comments

Comments
 (0)