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-infra] Move Ads component to TypeScript #42842

Merged
merged 2 commits into from
Jul 15, 2024

Conversation

alexfauquette
Copy link
Member

@alexfauquette alexfauquette commented Jul 4, 2024

Moving all Ads related files to TS before moving them in @mui/docs

@mui-bot
Copy link

mui-bot commented Jul 4, 2024

Netlify deploy preview

https://deploy-preview-42842--material-ui.netlify.app/

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against 3bf3b81

Comment on lines +74 to 76
// 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,
},
Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we revert this?

SCR-20240722-bvgz

Also related to vercel/next.js#57755 (comment)

Comment on lines 234 to 235
}),
...(adShape === 'inline2' && {
display: 'flex',
alignItems: 'flex-end',
}),
})}
Copy link
Member Author

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

@alexfauquette alexfauquette added the scope: docs-infra Specific to the docs-infra product label Jul 5, 2024
@alexfauquette alexfauquette marked this pull request as ready for review July 5, 2024 11:52
Copy link
Member

@bharatkashyap bharatkashyap left a 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) {
Copy link
Member

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.

@alexfauquette alexfauquette merged commit 42d4aad into mui:next Jul 15, 2024
22 checks passed
@alexfauquette alexfauquette deleted the docs-ts-ads branch July 15, 2024 14:14
@oliviertassinari oliviertassinari changed the title [docs-infra] Move Ads component to TS [docs-infra] Move Ads component to TypeScript Jul 21, 2024
@@ -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>();
Copy link
Member

@oliviertassinari oliviertassinari Jul 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The codebase uses:

Suggested change
const timerAdblock = React.useRef<NodeJS.Timeout>();
const timerAdblock = React.useRef<ReturnType<typeof setTimeout>>();

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Modification done in #42944

Comment on lines +74 to 76
// 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,
},
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we revert this?

SCR-20240722-bvgz

Also related to vercel/next.js#57755 (comment)

@Janpot
Copy link
Member

Janpot commented Jul 26, 2024

Can we revert this?

Yep, that's what I meant with #42842 (comment). Didn't know Next.js warned on this. Nice feature 🚀 .

joserodolfofreitas pushed a commit to joserodolfofreitas/material-ui that referenced this pull request Jul 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: docs-infra Specific to the docs-infra product typescript
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants