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] Fix issues reported by react compiler in docs folder #42881

Merged
merged 3 commits into from
Jul 8, 2024

Conversation

sai6855
Copy link
Contributor

@sai6855 sai6855 commented Jul 7, 2024

part of #42564

@sai6855 sai6855 added the docs Improvements or additions to the documentation label Jul 7, 2024
@mui-bot
Copy link

mui-bot commented Jul 7, 2024

Netlify deploy preview

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

Bundle size report

No bundle size changes (Toolpad)
No bundle size changes

Generated by 🚫 dangerJS against f7d936d

@@ -2,8 +2,8 @@ import * as React from 'react';
import { useRouter } from 'next/router';
import clipboardCopy from 'clipboard-copy';

const CodeBlockContext = React.createContext<React.MutableRefObject<HTMLDivElement | null>>({
current: null,
Copy link
Contributor Author

@sai6855 sai6855 Jul 7, 2024

Choose a reason for hiding this comment

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

when ref is defined as null, react treats ref as unmutable. hence changed null to undefined

Copy link
Member

Choose a reason for hiding this comment

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

Is this documented somewhere?

Copy link
Contributor Author

@sai6855 sai6855 Jul 8, 2024

Choose a reason for hiding this comment

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

I cannot recall where i read, but i guess its infered from below ts playground that, when ref is defined as null, react doesn't allow ref to mutate

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAJQKYEMDG8BmUIjgcilQ3wChS0IA7AZ3iMwEY4BeRYmAOgFcallMAHircQAIyRQAfAAoRAG3kBKcg0ac03KESowWAJnKVa9JJn2t26Lr35nhoidJkrSDfRq069+oA

image

Copy link
Member

Choose a reason for hiding this comment

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

In this case, using React.useRef<number | null>(null) makes the ref mutable.

Copy link
Contributor Author

@sai6855 sai6855 Jul 8, 2024

Choose a reason for hiding this comment

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

okay my bad, i misunderstood.

as of now, react-compiler throws error when modifying ref inside event handler. same issue was reported here facebook/react#29106. looks like it is treated as bug (facebook/react#29106 (comment)) and fixed here facebook/react#29591.

once fix gets published and we update eslint-plugin-react-complier i'm expecting below error to go away. hence reverted all changes done in this file.

Error reported by current version of react-compiler:

image

@sai6855 sai6855 requested a review from aarongarciah July 7, 2024 10:59
@aarongarciah aarongarciah merged commit edb100c into mui:next Jul 8, 2024
19 checks passed
@@ -81,6 +81,16 @@ export function useSetUserLanguage() {

const warnedOnce: Record<string, boolean> = {};

const warn = (userLanguage: string, key: string, ignoreWarning: boolean) => {
Copy link
Member

Choose a reason for hiding this comment

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

function for top-level declarations

Suggested change
const warn = (userLanguage: string, key: string, ignoreWarning: boolean) => {
function warn(userLanguage: string, key: string, ignoreWarning: boolean) {

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.

We should migrate to use the warnOnce helper in the future mui/mui-x#13911. We can't yet, but eventually. I have left a TODO message in the code.

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
docs Improvements or additions to the documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants