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

[styles] Fix issues reported by eslint-plugin-react-compiler #43118

Merged
merged 4 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/mui-styles/src/StylesProvider/StylesProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export default function StylesProvider(props) {
if (!context.jss.options.insertionPoint && injectFirst && typeof window !== 'undefined') {
if (!injectFirstNode) {
const head = document.head;
// TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler -- injectFirstNode is called inside callback
injectFirstNode = document.createComment('mui-inject-first');
head.insertBefore(injectFirstNode, head.firstChild);
}
Expand Down
4 changes: 3 additions & 1 deletion packages/mui-styles/src/makeStyles/makeStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ function useSynchronousEffect(func, values) {
let output;

// Store "generation" key. Just returns a new object every time
// TODO: uncomment once we enable eslint-plugin-react-compiler // eslint-disable-next-line react-compiler/react-compiler
const currentKey = React.useMemo(() => ({}), values); // eslint-disable-line react-hooks/exhaustive-deps

// "the first render", or "memo dropped the value"
Expand Down Expand Up @@ -238,7 +239,8 @@ export default function makeStyles(stylesOrCreator, options = {}) {

const classes = getClasses(instance.current, props.classes, Component);
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
// eslint-disable-next-line react-hooks/rules-of-hooks -- process.env never changes
React.useDebugValue(classes);
}
if (process.env.NODE_ENV !== 'production') {
Expand Down
12 changes: 6 additions & 6 deletions packages/mui-styles/src/makeStyles/makeStyles.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ import { createStyles, makeStyles } from '@mui/styles';
}));
}

const useStyles = makeStyles<Theme>((theme) => ({
root: {
background: 'blue',
},
}));

function PartialTypeInferenceTest() {
// If any generic is provided, inference breaks.
// If the proposal https://github.com/Microsoft/TypeScript/issues/26242 goes through, we can fix this.
const useStyles = makeStyles<Theme>((theme) => ({
root: {
background: 'blue',
},
}));

const classes = useStyles();

// This doesn't fail, because inference is broken
Expand Down
1 change: 1 addition & 0 deletions packages/mui-styles/src/withStyles/withStyles.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const withStyles =

if (typeof name === 'string' || withTheme) {
// name and withTheme are invariant in the outer scope
// 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
theme = useTheme() || defaultTheme;

Expand Down