Skip to content

Commit

Permalink
[docs–infra] Prevent displaying multiple ads
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Jun 24, 2023
1 parent 314c3d4 commit 1e468b4
Showing 1 changed file with 21 additions and 23 deletions.
44 changes: 21 additions & 23 deletions docs/src/modules/components/AdCarbon.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,32 @@
import * as React from 'react';
import GlobalStyles from '@mui/material/GlobalStyles';
import { styled } from '@mui/material/styles';
import loadScript from 'docs/src/modules/utils/loadScript';
import AdDisplay from 'docs/src/modules/components/AdDisplay';
import { adStylesObject } from 'docs/src/modules/components/ad.styles';

const CarbonRoot = styled('span')(({ theme }) => {
const styles = adStylesObject['body-image'](theme);

return {
'& #carbonads': {
...styles.root,
'& .carbon-img': styles.imgWrapper,
'& img': styles.img,
'& a, & a:hover': styles.a,
'& .carbon-text': styles.description,
'& .carbon-poweredby': styles.poweredby,
},
'& [id^=carbonads_]': {
display: 'none',
},
};
});

function AdCarbonImage() {
const ref = React.useRef(null);

React.useEffect(() => {
// The isolation logic of carbonads is flawed.
// The isolation logic of carbonads is broken.
// Once the script starts loading, it will asynchronous resolve, with no way to stop it.
// This leads to duplication of the ad. To solve the issue, we debounce the load action.
const load = setTimeout(() => {
Expand All @@ -24,27 +42,7 @@ function AdCarbonImage() {
};
}, []);

return (
<React.Fragment>
<GlobalStyles
styles={(theme) => {
const styles = adStylesObject['body-image'](theme);

return {
'#carbonads': {
...styles.root,
'& .carbon-img': styles.imgWrapper,
'& img': styles.img,
'& a, & a:hover': styles.a,
'& .carbon-text': styles.description,
'& .carbon-poweredby': styles.poweredby,
},
};
}}
/>
<span ref={ref} />
</React.Fragment>
);
return <CarbonRoot ref={ref} />;
}

export function AdCarbonInline(props) {
Expand Down

0 comments on commit 1e468b4

Please sign in to comment.