Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[docs] Improve loading experience #20005

Merged
merged 5 commits into from
Mar 20, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions docs/src/modules/components/AppFrame.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { LANGUAGES_LABEL } from 'docs/src/modules/constants';
import { pathnameToLanguage } from 'docs/src/modules/utils/helpers';
import { useChangeTheme } from 'docs/src/modules/components/ThemeContext';
import PageContext from 'docs/src/modules/components/PageContext';
import Skeleton from '@material-ui/lab/Skeleton';

const LOCALES = { zh: 'zh-CN', pt: 'pt-BR', es: 'es-ES' };
const CROWDIN_ROOT_URL = 'https://translate.material-ui.com/project/material-ui-docs/';
Expand All @@ -52,7 +53,7 @@ Router.onRouteChangeError = () => {

const AppSearch = React.lazy(() => import('docs/src/modules/components/AppSearch'));
function DeferredAppSearch() {
const fallback = null;
const fallback = <Skeleton height={40} variant="rect" width={200} />;

const [mounted, setMounted] = React.useState(false);
React.useEffect(() => {
Expand All @@ -67,10 +68,12 @@ function DeferredAppSearch() {
as="style"
/>
{/* Suspense isn't supported for SSR yet */}
{mounted && (
{mounted ? (
<React.Suspense fallback={fallback}>
<AppSearch />
</React.Suspense>
) : (
fallback
)}
</React.Fragment>
);
Expand Down Expand Up @@ -237,7 +240,7 @@ function AppFrame(props) {
<ExpandMoreIcon fontSize="small" />
</Button>
</Tooltip>
<NoSsr>
<NoSsr defer>
<Menu
id="language-menu"
anchorEl={languageMenu}
Expand Down
20 changes: 16 additions & 4 deletions docs/src/modules/components/Demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import Menu from '@material-ui/core/Menu';
import MenuItem from '@material-ui/core/MenuItem';
import MoreVertIcon from '@material-ui/icons/MoreVert';
import Tooltip from '@material-ui/core/Tooltip';
import Skeleton from '@material-ui/lab/Skeleton';
import MarkdownElement from 'docs/src/modules/components/MarkdownElement';
import DemoSandboxed from 'docs/src/modules/components/DemoSandboxed';
import DemoLanguages from 'docs/src/modules/components/DemoLanguages';
Expand Down Expand Up @@ -98,12 +99,10 @@ const styles = theme => ({
top: 0,
right: theme.spacing(1),
height: theme.spacing(6),
marginTop: theme.spacing(1),
},
justifyContent: 'space-between',
},
headerButtons: {
margin: '2px 0',
},
code: {
display: 'none',
padding: 0,
Expand Down Expand Up @@ -152,6 +151,19 @@ function getDemoData(codeVariant, demo, githubLocation) {
};
}

function DemoToolbarFallback() {
return (
<React.Fragment>
{/* demo languages placeholder
* since they're hidden by default we use an empty div to position the next
* placeholder properly */}
<div />
{/* header buttons placeholder */}
<Skeleton height={40} variant="rect" width={200} />
</React.Fragment>
);
}

function Demo(props) {
const { classes, demo, demoOptions, githubLocation } = props;
const dispatch = useDispatch();
Expand Down Expand Up @@ -345,7 +357,7 @@ function Demo(props) {
<div className={classes.anchorLink} id={`${demoName}.tsx`} />
{demoOptions.hideHeader ? null : (
<div className={classes.header}>
<NoSsr>
<NoSsr defer fallback={<DemoToolbarFallback />}>
<DemoLanguages
demo={demo}
codeOpen={codeOpen}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/DemoSandboxed.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function DemoFrame(props) {

// NoSsr fixes a strange concurrency issue with iframe and quick React mount/unmount
return (
<NoSsr>
<NoSsr defer>
<Frame
ref={handleRef}
className={classes.frame}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/HomeQuickWord.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function HomeQuickWord(props) {
return (
<div className={classes.root}>
<Typography variant="caption">{t('homeQuickWord')}</Typography>
<NoSsr>
<NoSsr defer>
<Link
variant="body2"
display="block"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/HomeQuotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ function HomeQuotes() {

return (
<div className={classes.root}>
<NoSsr>
<NoSsr defer>
<Container maxWidth="md" className={classes.container} disableGutters>
<Divider />
<div className={classes.users}>
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/HomeSponsors.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function HomeSponsors(props) {

return (
<div className={classes.root}>
<NoSsr>
<NoSsr defer>
<Container maxWidth="md">
<Divider />
<MarkdownElement className={classes.markdownElement} text={backers[userLanguage]} />
Expand Down
4 changes: 2 additions & 2 deletions docs/src/modules/components/HomeThemes.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function HomeThemes(props) {

return (
<div className={classes.root}>
<NoSsr>
<NoSsr defer>
<Container maxWidth="md">
<Typography variant="h4" component="h2" align="center" gutterBottom>
{t('themes')}
Expand All @@ -67,7 +67,7 @@ function HomeThemes(props) {
data-ga-event-label="home-image"
className={classes.link}
>
<NoSsr>
<NoSsr defer>
<img
className={classes.img}
alt={t('themesButton')}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/HomeUsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ function HomeUsers(props) {

return (
<div className={classes.root}>
<NoSsr>
<NoSsr defer>
<Container maxWidth="md" className={classes.container} disableGutters>
<Divider />
<div className={classes.users}>
Expand Down