-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[code-infra] Add "use client" directive to files with React APIs (#45036
- Loading branch information
Showing
20 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/eslint-plugin-material-ui/src/rules/disallow-react-api-in-server-components.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
module.exports = { | ||
create(context) { | ||
let hasUseClientDirective = false; | ||
const apis = new Set([ | ||
'useState', | ||
'useEffect', | ||
'useLayoutEffect', | ||
'useReducer', | ||
'useTransition', | ||
'createContext', | ||
]); | ||
return { | ||
Program(node) { | ||
hasUseClientDirective = node.body.some( | ||
(statement) => | ||
statement.type === 'ExpressionStatement' && | ||
statement.expression.type === 'Literal' && | ||
statement.expression.value === 'use client', | ||
); | ||
}, | ||
CallExpression(node) { | ||
if ( | ||
!hasUseClientDirective && | ||
node.callee.type === 'MemberExpression' && | ||
node.callee.object.name === 'React' && | ||
apis.has(node.callee.property.name) | ||
) { | ||
context.report({ | ||
node, | ||
message: `Using 'React.${node.callee.property.name}' is forbidden if the file doesn't have a 'use client' directive.`, | ||
fix(fixer) { | ||
const sourceCode = context.getSourceCode(); | ||
if ( | ||
sourceCode.text.includes('"use server"') || | ||
sourceCode.text.includes("'use server'") | ||
) { | ||
return null; | ||
} | ||
|
||
const firstToken = sourceCode.ast.body[0]; | ||
return fixer.insertTextBefore(firstToken, "'use client';\n"); | ||
}, | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
meta: { | ||
fixable: 'code', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
|
||
/** | ||
|
1 change: 1 addition & 0 deletions
1
packages/mui-material/src/ButtonGroup/ButtonGroupButtonContext.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
|
||
type ButtonPositionClassName = string; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import type { ButtonGroupProps } from './ButtonGroup'; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
|
||
interface DialogContextValue { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import type { FormControlProps } from './FormControl'; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
|
||
export interface RadioGroupContextValue { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
|
||
export interface StepContextType { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
|
||
export interface StepperContextType { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
|
||
/** | ||
|
1 change: 1 addition & 0 deletions
1
packages/mui-material/src/ToggleButtonGroup/ToggleButtonGroupButtonContext.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
|
||
type ToggleButtonPositionClassName = string; | ||
|
1 change: 1 addition & 0 deletions
1
packages/mui-material/src/ToggleButtonGroup/ToggleButtonGroupContext.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
|
||
const ThemeContext = React.createContext(null); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
'use client'; | ||
import * as React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters