-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
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-infra] Move Ads component to TypeScript #42842
Conversation
Netlify deploy previewhttps://deploy-preview-42842--material-ui.netlify.app/ Bundle size report |
// The ratio of ads display reported to Google Analytics. Used to avoid an exceed on the Google Analytics quotas. | ||
GA_ADS_DISPLAY_RATIO: 0.1, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure it's the best place to move the constants
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imo, ideally we move _app
to the docs infra package, add the ads display ratio as a prop and provide it in a context.
For now I guess the approach works, though I don't like to depend on process.env
in libraries, it's implicit API and bundlers may not always handle it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}), | ||
...(adShape === 'inline2' && { | ||
display: 'flex', | ||
alignItems: 'flex-end', | ||
}), | ||
})} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not found usage of 'inline2'
in material-ui, mui-x, or toolpad repo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me 👍🏻
@@ -198,7 +199,7 @@ export default function Ad() { | |||
|
|||
React.useEffect(() => { | |||
// Avoid an exceed on the Google Analytics quotas. | |||
if (Math.random() > GA_ADS_DISPLAY_RATIO || !eventLabel) { | |||
if (Math.random() > ((process.env.GA_ADS_DISPLAY_RATIO ?? 0.1) as number) || !eventLabel) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing to note as well is that Next.js actually puts a number in process.env.GA_ADS_DISPLAY_RATIO
while in Node.js this would always be a string, so the types will always be incorrect.
Personally, I'd never pass anything to a Next.js env
that is not a string and always parse it from a string on the client side. This would avoid the as number
which circumvents the type checking on this line.
@@ -150,7 +151,7 @@ export default function Ad() { | |||
const ad = React.useContext(AdContext); | |||
const eventLabel = label ? `${label}-${ad.placement}-${adShape}` : null; | |||
|
|||
const timerAdblock = React.useRef(); | |||
const timerAdblock = React.useRef<NodeJS.Timeout>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The codebase uses:
const timerAdblock = React.useRef<NodeJS.Timeout>(); | |
const timerAdblock = React.useRef<ReturnType<typeof setTimeout>>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Modification done in #42944
// The ratio of ads display reported to Google Analytics. Used to avoid an exceed on the Google Analytics quotas. | ||
GA_ADS_DISPLAY_RATIO: 0.1, | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, that's what I meant with #42842 (comment). Didn't know Next.js warned on this. Nice feature 🚀 . |
Moving all Ads related files to TS before moving them in
@mui/docs