-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[pickers] Add "use client"
directive to every public component and hook
#14562
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5ba88cf
[pickers] Add use client directive
flaviendelangle 2099284
Review Lukas
flaviendelangle 5506dae
Skip internal components and hooks
flaviendelangle 68f3c97
Add CI step
flaviendelangle c7cf3d6
Merge branch 'master' into use-client
flaviendelangle 863f0fe
Regen
flaviendelangle b66fdab
Fix CI
flaviendelangle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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,147 @@ | ||
import path from 'path'; | ||
import * as yargs from 'yargs'; | ||
import * as fse from 'fs-extra'; | ||
import findComponents from '@mui-internal/api-docs-builder/utils/findComponents'; | ||
import findHooks from '@mui-internal/api-docs-builder/utils/findHooks'; | ||
|
||
type CommandOptions = { grep?: string }; | ||
|
||
type Project = { | ||
name: string; | ||
rootPath: string; | ||
additionalPaths?: string[]; | ||
additionalFiles?: string[]; | ||
ignorePaths?: string[]; | ||
}; | ||
|
||
const PROJECTS: Project[] = [ | ||
{ | ||
name: 'x-date-pickers', | ||
rootPath: path.join(process.cwd(), 'packages/x-date-pickers'), | ||
}, | ||
{ | ||
name: 'x-date-pickers-pro', | ||
rootPath: path.join(process.cwd(), 'packages/x-date-pickers-pro'), | ||
}, | ||
]; | ||
|
||
async function processFile( | ||
filename: string, | ||
options: { | ||
lineToPrepend?: string; | ||
} = {}, | ||
) { | ||
if (!fse.statSync(filename).isFile()) { | ||
return; | ||
} | ||
|
||
const { lineToPrepend = `'use client';` } = options; | ||
const contents = await fse.readFile(filename, 'utf8'); | ||
|
||
if ( | ||
filename.indexOf('internal') !== -1 || | ||
!!contents.match(/@ignore - internal component\./) || | ||
!!contents.match(/@ignore - internal hook\./) || | ||
!!contents.match(/@ignore - do not document\./) | ||
) { | ||
return; | ||
} | ||
|
||
const lines = contents.split(/\r?\n/); | ||
if (lines[0] === lineToPrepend) { | ||
return; | ||
} | ||
|
||
const newContents = `${lineToPrepend}\n${contents}`; | ||
|
||
await fse.writeFile(filename, newContents); | ||
} | ||
|
||
async function findAll( | ||
directories: string[], | ||
grep: RegExp | null, | ||
findFn: typeof findComponents | typeof findHooks, | ||
) { | ||
const result = await Promise.all( | ||
directories.map((dir) => { | ||
return findFn(dir).filter((item) => { | ||
if (grep === null) { | ||
return true; | ||
} | ||
return grep.test(item.filename); | ||
}); | ||
}), | ||
); | ||
|
||
return result.flat(); | ||
} | ||
|
||
async function run(argv: yargs.ArgumentsCamelCase<CommandOptions>) { | ||
const grep = argv.grep == null ? null : new RegExp(argv.grep); | ||
|
||
await PROJECTS.reduce(async (resolvedPromise, project) => { | ||
await resolvedPromise; | ||
|
||
const projectSrc = path.join(project.rootPath, 'src'); | ||
|
||
let directories = [projectSrc]; | ||
|
||
if (Array.isArray(project?.additionalPaths)) { | ||
directories = [ | ||
...directories, | ||
...project.additionalPaths.map((p) => path.join(project.rootPath, p)), | ||
]; | ||
} | ||
|
||
const components = await findAll(directories, grep, findComponents); | ||
|
||
components.forEach(async (component) => { | ||
try { | ||
if (!project.ignorePaths?.some((p) => component.filename.includes(p))) { | ||
processFile(component.filename); | ||
} | ||
} catch (error: any) { | ||
error.message = `${path.relative(process.cwd(), component.filename)}: ${error.message}`; | ||
throw error; | ||
} | ||
}); | ||
|
||
const hooks = await findAll(directories, grep, findHooks); | ||
|
||
hooks.forEach(async (hook) => { | ||
try { | ||
processFile(hook.filename); | ||
} catch (error: any) { | ||
error.message = `${path.relative(process.cwd(), hook.filename)}: ${error.message}`; | ||
throw error; | ||
} | ||
}); | ||
|
||
if (Array.isArray(project?.additionalFiles)) { | ||
project.additionalFiles.forEach(async (file) => { | ||
const fullPath = path.join(project.rootPath, file); | ||
processFile(fullPath); | ||
}); | ||
} | ||
|
||
return Promise.resolve(); | ||
}, Promise.resolve()); | ||
} | ||
|
||
yargs | ||
.command({ | ||
command: '$0', | ||
describe: 'prepends the use client directive to components', | ||
builder: (command) => { | ||
return command.option('grep', { | ||
description: | ||
'Only process files for component filenames matching the pattern. The string is treated as a RegExp.', | ||
type: 'string', | ||
}); | ||
}, | ||
handler: run, | ||
}) | ||
.help() | ||
.strict(true) | ||
.version(false) | ||
.parse(); |
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,14 @@ | ||
{ | ||
"name": "rsc-builder", | ||
"version": "1.0.0", | ||
"private": "true", | ||
"main": "./buildRsc.ts", | ||
"dependencies": { | ||
"fs-extra": "^11.2.0", | ||
"yargs": "^17.7.2" | ||
}, | ||
"devDependencies": { | ||
"@types/mocha": "^10.0.7", | ||
"@types/node": "^20.14.8" | ||
} | ||
} |
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,27 @@ | ||
{ | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"isolatedModules": true, | ||
"noEmit": true, | ||
"noUnusedLocals": false, | ||
"resolveJsonModule": true, | ||
"skipLibCheck": true, | ||
"esModuleInterop": true, | ||
"types": ["node", "mocha"], | ||
"target": "ES2020", | ||
"module": "CommonJS", | ||
"moduleResolution": "node", | ||
"strict": true, | ||
"baseUrl": "./", | ||
"paths": { | ||
"@mui-internal/api-docs-builder": [ | ||
"../../node_modules/@mui/monorepo/packages/api-docs-builder/index.ts" | ||
], | ||
"@mui-internal/api-docs-builder/*": [ | ||
"../../node_modules/@mui/monorepo/packages/api-docs-builder/*" | ||
] | ||
} | ||
}, | ||
"include": ["./**/*.ts", "./**/*.js"], | ||
"exclude": ["node_modules"] | ||
} |
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/DateRangeCalendar/DateRangeCalendar.tsx
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'; | ||
import clsx from 'clsx'; | ||
|
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/DateRangeCalendar/useDragRange.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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/DateRangePicker/DateRangePicker.tsx
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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/DateRangePicker/DateRangePickerToolbar.tsx
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'; | ||
import clsx from 'clsx'; | ||
|
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/DateRangePickerDay/DateRangePickerDay.tsx
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'; | ||
import clsx from 'clsx'; | ||
|
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/DateTimeRangePicker/DateTimeRangePicker.tsx
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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/DateTimeRangePicker/DateTimeRangePickerTabs.tsx
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 clsx from 'clsx'; | ||
import PropTypes from 'prop-types'; | ||
|
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/DateTimeRangePicker/DateTimeRangePickerToolbar.tsx
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'; | ||
import clsx from 'clsx'; | ||
|
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/DesktopDateRangePicker/DesktopDateRangePicker.tsx
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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/DesktopDateTimeRangePicker/DesktopDateTimeRangePicker.tsx
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'; | ||
import { | ||
|
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/MobileDateRangePicker/MobileDateRangePicker.tsx
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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/MobileDateTimeRangePicker/MobileDateTimeRangePicker.tsx
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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/MultiInputDateRangeField/MultiInputDateRangeField.tsx
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'; | ||
import clsx from 'clsx'; | ||
|
1 change: 1 addition & 0 deletions
1
...ages/x-date-pickers-pro/src/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.tsx
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'; | ||
import clsx from 'clsx'; | ||
|
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/MultiInputTimeRangeField/MultiInputTimeRangeField.tsx
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'; | ||
import { clsx } from 'clsx'; | ||
|
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/PickersRangeCalendarHeader/PickersRangeCalendarHeader.tsx
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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/SingleInputDateRangeField/SingleInputDateRangeField.tsx
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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/SingleInputDateRangeField/useSingleInputDateRangeField.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
1 change: 1 addition & 0 deletions
1
...es/x-date-pickers-pro/src/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.tsx
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
1 change: 1 addition & 0 deletions
1
.../x-date-pickers-pro/src/SingleInputDateTimeRangeField/useSingleInputDateTimeRangeField.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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/SingleInputTimeRangeField/SingleInputTimeRangeField.tsx
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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/SingleInputTimeRangeField/useSingleInputTimeRangeField.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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers-pro/src/StaticDateRangePicker/StaticDateRangePicker.tsx
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'; | ||
import clsx from 'clsx'; | ||
|
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
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 { | ||
singleItemFieldValueManager, | ||
singleItemValueManager, | ||
|
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 clsx from 'clsx'; | ||
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
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 { | ||
singleItemFieldValueManager, | ||
singleItemValueManager, | ||
|
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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers/src/DateTimePicker/DateTimePickerTabs.tsx
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 clsx from 'clsx'; | ||
import PropTypes from 'prop-types'; | ||
|
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers/src/DateTimePicker/DateTimePickerToolbar.tsx
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
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers/src/DayCalendarSkeleton/DayCalendarSkeleton.tsx
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'; | ||
import clsx from 'clsx'; | ||
|
1 change: 1 addition & 0 deletions
1
packages/x-date-pickers/src/DesktopDatePicker/DesktopDatePicker.tsx
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be part of CI? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not in the core, but it would be a nice addition
I'm trying to add it 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be a tricky process to do in CI since you'll then want the code to be committed back.
Ideally, it should be part of the build (or did you mean build) ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CI reminds you to run the script locally anytime you create a new public component (if you did not add "use client" manually).
Similar to what we have for
pnpm l10n
, it does not commit the localization files but it makes sure we don't forget to do it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brijeshb42
It is either part of the build, and we don't commit anything, or it can be a check, where if there are changes after the script is run, the CI fails.