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] Fix React Compiler ESLint issues in website components #42566

Merged
2 changes: 1 addition & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ module.exports = {
rules: {
'import/no-default-export': 'error',
'import/prefer-default-export': 'off',
...(ENABLE_REACT_COMPILER_PLUGIN ? { 'react-compiler/react-compiler': 'off' } : {}),
'react-compiler/react-compiler': 'off',
Copy link
Member

Choose a reason for hiding this comment

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

Is ENABLE_REACT_COMPILER_PLUGIN no longer useful?

Copy link
Member Author

Choose a reason for hiding this comment

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

For now we leave it always off for Base UI.

},
},
{
Expand Down
3 changes: 2 additions & 1 deletion docs/src/components/banner/AppFrameBanner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export default function AppFrameBanner() {
return null;
}

// eslint-disable-next-line react-hooks/rules-of-hooks
// TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler
// eslint-disable-next-line react-hooks/rules-of-hooks -- FEATURE_TOGGLE never changes
const pageContext = React.useContext(PageContext);
const productName = convertProductIdToName(pageContext) || 'MUI';
const message = `Influence ${productName}'s 2024 roadmap! Participate in the latest Developer Survey`;
Expand Down
7 changes: 5 additions & 2 deletions docs/src/components/productMaterial/MaterialStyling.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ export const useResizeHandle = (
if (target.current && dragging && clientX) {
const objectRect = target.current.getBoundingClientRect();
const newWidth = clientX - objectRect.left + dragOffset;
target.current.style.width = `clamp(${minWidth}, ${Math.floor(newWidth)}px, ${maxWidth})`;
target.current.style.setProperty(
Copy link
Member Author

Choose a reason for hiding this comment

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

Using style.setProperty so there's no "mutation".

Copy link
Member

Choose a reason for hiding this comment

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

This feels strange: facebook/react#29832.

'width',
`clamp(${minWidth}, ${Math.floor(newWidth)}px, ${maxWidth})`,
);
}
}
function stopResize() {
Expand Down Expand Up @@ -148,7 +151,7 @@ export default function MaterialStyling() {
// 1px border-width
infoRef.current!.scroll({ top: scrollTo[index] * 18 + 16 - 1, behavior: 'smooth' });

objectRef.current!.style.width = '100%';
objectRef.current!.style.setProperty('width', '100%');
}, [index]);

return (
Expand Down
7 changes: 3 additions & 4 deletions docs/src/components/productX/XHero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,10 @@ export default function XHero() {
[],
);

let rowGroupingCounter = 0;
const rowGroupingCounterRef = React.useRef(0);
const isGroupExpandedByDefault = React.useCallback(() => {
// eslint-disable-next-line react-hooks/exhaustive-deps
rowGroupingCounter += 1;
return rowGroupingCounter === 3;
rowGroupingCounterRef.current += 1;
return rowGroupingCounterRef.current === 3;
DiegoAndai marked this conversation as resolved.
Show resolved Hide resolved
}, []);

return (
Expand Down
8 changes: 7 additions & 1 deletion docs/src/components/productX/XPlans.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,13 @@ export default function XPlans2() {
<Grid xs={12} md={6}>
<Stack spacing={2} useFlexGap>
{content.map(({ icon, title, description, link }) => (
<InfoCard title={title} icon={icon} description={description} link={link} />
<InfoCard
key={title}
title={title}
icon={icon}
description={description}
link={link}
/>
))}
</Stack>
</Grid>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function useApiPageOption(
const [option, setOption] = React.useState(getOption(storageKey, defaultValue));

useEnhancedEffect(() => {
// TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler -- useEnhancedEffect uses useEffect under the hood
neverHydrated = false;
const newOption = getOption(storageKey, defaultValue);
setOption(newOption);
Expand Down
1 change: 1 addition & 0 deletions docs/src/modules/components/AppNavDrawer.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ function PersistScroll(props) {
}

return () => {
// TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler -- useEnhancedEffect uses useEffect under the hood
Copy link
Member

Choose a reason for hiding this comment

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

What's the plan with these comments? To fix it in the future or to keep the disable?

Copy link
Member Author

Choose a reason for hiding this comment

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

The plan is to keep the disable but remove the comment/TODO once we enable the corresponding ESLint plugin.

savedScrollTop[slot] = scrollContainer.scrollTop;
};
}, [enabled, slot]);
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 @@ -25,7 +25,7 @@ function FramedDemo(props) {

const theme = useTheme();
React.useEffect(() => {
document.body.dir = theme.direction;
document.body.setAttribute('dir', theme.direction);
}, [document, theme.direction]);

const { jss, sheetsManager } = React.useMemo(() => {
Expand Down
1 change: 1 addition & 0 deletions docs/src/modules/components/DemoToolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ export default function DemoToolbar(props) {
const devMenuItems = [];
if (process.env.DEPLOY_ENV === 'staging' || process.env.DEPLOY_ENV === 'pull-request') {
/* eslint-disable material-ui/no-hardcoded-labels -- staging only */
// TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler -- valid reason to disable rules of hooks
// eslint-disable-next-line react-hooks/rules-of-hooks -- process.env never changes
const router = useRouter();

Expand Down
3 changes: 2 additions & 1 deletion docs/src/modules/components/ReactRunner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export default function ReactRunner(props: ReactRunnerProps) {
let scope = scopeProp;

if (process.env.NODE_ENV !== 'production') {
// eslint-disable-next-line react-hooks/rules-of-hooks
// TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler -- valid reason to disable the rules of hooks
// eslint-disable-next-line react-hooks/rules-of-hooks -- process.env never changes
scope = React.useMemo(() => {
const handler = {
get() {
Expand Down
2 changes: 1 addition & 1 deletion docs/src/modules/components/ThemeContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ export function ThemeProvider(props) {
}, [calculatedMode]);

useEnhancedEffect(() => {
document.body.dir = direction;
document.body.setAttribute('dir', direction);
aarongarciah marked this conversation as resolved.
Show resolved Hide resolved
}, [direction]);

useEnhancedEffect(() => {
Expand Down