Skip to content

Commit

Permalink
[docs] Fix ad exception in Joy UI (#35685)
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari authored Jan 3, 2023
1 parent 8e067ee commit a267ed6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 19 deletions.
3 changes: 2 additions & 1 deletion docs/src/BrandingCssVarsProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ const theme = extendTheme({
...getThemedComponents(),
});

export default function BrandingCssVarsProvider({ children }: { children: React.ReactNode }) {
export default function BrandingCssVarsProvider(props: { children: React.ReactNode }) {
const { children } = props;
return (
<CssVarsProvider theme={theme} defaultMode="system" disableTransitionOnChange>
<NextNProgressBar />
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/DemoSandbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ function DemoSandbox(props) {

return (
<DemoErrorBoundary name={name} onResetDemoClick={onResetDemoClick} t={t}>
{canonicalAs.startsWith('/joy-ui') ? (
{canonicalAs.startsWith('/joy-ui/') ? (
children
) : (
<StylesProvider jss={jss}>
Expand Down
17 changes: 10 additions & 7 deletions docs/src/modules/components/MarkdownDocs.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ import PropTypes from 'prop-types';
import path from 'path';
import { useRouter } from 'next/router';
import { useTheme } from '@mui/system';
import { exactProp } from '@mui/utils';
import { CssVarsProvider, useColorScheme } from '@mui/joy/styles';
import Demo from 'docs/src/modules/components/Demo';
import MarkdownElement from 'docs/src/modules/components/MarkdownElement';
import { exactProp } from '@mui/utils';
import { pathnameToLanguage } from 'docs/src/modules/utils/helpers';
import AppLayoutDocs from 'docs/src/modules/components/AppLayoutDocs';
import { useTranslate, useUserLanguage } from 'docs/src/modules/utils/i18n';
import { CssVarsProvider, useColorScheme } from '@mui/joy/styles';
import BrandingProvider from 'docs/src/BrandingProvider';
import Ad from 'docs/src/modules/components/Ad';
import AdGuest from 'docs/src/modules/components/AdGuest';
Expand All @@ -34,7 +35,7 @@ JoyModeObserver.propTypes = {
export default function MarkdownDocs(props) {
const theme = useTheme();
const router = useRouter();
const asPathWithoutLang = router.asPath.replace(/^\/[a-zA-Z]{2}\//, '/');
const { canonicalAs } = pathnameToLanguage(router.asPath);
const {
disableAd = false,
disableToc = false,
Expand All @@ -50,7 +51,7 @@ export default function MarkdownDocs(props) {
const localizedDoc = docs[userLanguage] || docs.en;
const { description, location, rendered, title, toc } = localizedDoc;

const isJoy = asPathWithoutLang.startsWith('/joy-ui');
const isJoy = canonicalAs.startsWith('/joy-ui/');
const Provider = isJoy ? CssVarsProvider : React.Fragment;
const Wrapper = isJoy ? BrandingProvider : React.Fragment;

Expand All @@ -65,9 +66,11 @@ export default function MarkdownDocs(props) {
>
<Provider>
{disableAd ? null : (
<AdGuest>
<Ad />
</AdGuest>
<Wrapper>
<AdGuest>
<Ad />
</AdGuest>
</Wrapper>
)}
{isJoy && <JoyModeObserver mode={theme.palette.mode} />}
{rendered.map((renderedMarkdownOrDemo, index) => {
Expand Down
8 changes: 1 addition & 7 deletions docs/src/modules/components/ThemeContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import { ThemeProvider as MuiThemeProvider, createTheme } from '@mui/material/styles';
import { deepmerge } from '@mui/utils';
import useMediaQuery from '@mui/material/useMediaQuery';
import { enUS, zhCN, faIR, ruRU, ptBR, esES, frFR, deDE, jaJP } from '@mui/material/locale';
import { enUS, zhCN, ptBR } from '@mui/material/locale';
import { unstable_useEnhancedEffect as useEnhancedEffect } from '@mui/material/utils';
import { getCookie } from 'docs/src/modules/utils/helpers';
import useLazyCSS from 'docs/src/modules/utils/useLazyCSS';
Expand All @@ -18,13 +18,7 @@ import PageContext from './PageContext';
const languageMap = {
en: enUS,
zh: zhCN,
fa: faIR,
ru: ruRU,
pt: ptBR,
es: esES,
fr: frFR,
de: deDE,
ja: jaJP,
};

const themeInitialOptions = {
Expand Down
4 changes: 1 addition & 3 deletions docs/src/modules/components/TopLayoutCareers.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const StyledAppContainer = styled(AppContainer)(({ theme }) => ({
},
}));

function TopLayoutCareers(props) {
export default function TopLayoutCareers(props) {
const { docs } = props;
const { description, rendered, title } = docs.en;

Expand Down Expand Up @@ -57,5 +57,3 @@ function TopLayoutCareers(props) {
TopLayoutCareers.propTypes = {
docs: PropTypes.object.isRequired,
};

export default TopLayoutCareers;

0 comments on commit a267ed6

Please sign in to comment.