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

@@ -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
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
3 participants