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

[core-infra] Remove useless fragments #44516

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { navigationCustomizations } from './customizations/navigation';
import { surfacesCustomizations } from './customizations/surfaces';
import { colorSchemes, typography, shadows, shape } from './themePrimitives';

function AppTheme({ children, disableCustomTheme, themeComponents }) {
function AppTheme(props) {
const { children, disableCustomTheme, themeComponents } = props;
const theme = React.useMemo(() => {
return disableCustomTheme
? {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,8 @@ interface AppThemeProps {
themeComponents?: ThemeOptions['components'];
}

export default function AppTheme({
children,
disableCustomTheme,
themeComponents,
}: AppThemeProps) {
export default function AppTheme(props: AppThemeProps) {
const { children, disableCustomTheme, themeComponents } = props;
const theme = React.useMemo(() => {
return disableCustomTheme
? {}
Expand Down
8 changes: 5 additions & 3 deletions docs/pages/joy-ui/api/stack.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
"type": {
"name": "union",
"description": "'column-reverse'<br>&#124;&nbsp;'column'<br>&#124;&nbsp;'row-reverse'<br>&#124;&nbsp;'row'<br>&#124;&nbsp;Array&lt;'column-reverse'<br>&#124;&nbsp;'column'<br>&#124;&nbsp;'row-reverse'<br>&#124;&nbsp;'row'&gt;<br>&#124;&nbsp;object"
}
},
"default": "'column'"
},
"divider": { "type": { "name": "node" } },
"spacing": {
"type": {
"name": "union",
"description": "Array&lt;number<br>&#124;&nbsp;string&gt;<br>&#124;&nbsp;number<br>&#124;&nbsp;object<br>&#124;&nbsp;string"
}
},
"default": "0"
},
"sx": {
"type": {
Expand All @@ -22,7 +24,7 @@
},
"additionalInfo": { "sx": true }
},
"useFlexGap": { "type": { "name": "bool" } }
"useFlexGap": { "type": { "name": "bool" }, "default": "false" }
},
"name": "Stack",
"imports": ["import Stack from '@mui/joy/Stack';", "import { Stack } from '@mui/joy';"],
Expand Down
7 changes: 4 additions & 3 deletions docs/pages/material-ui/api/container.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
"props": {
"classes": { "type": { "name": "object" }, "additionalInfo": { "cssApi": true } },
"component": { "type": { "name": "elementType" } },
"disableGutters": { "type": { "name": "bool" } },
"fixed": { "type": { "name": "bool" } },
"disableGutters": { "type": { "name": "bool" }, "default": "false" },
"fixed": { "type": { "name": "bool" }, "default": "false" },
"maxWidth": {
"type": {
"name": "union",
"description": "'xs'<br>&#124;&nbsp;'sm'<br>&#124;&nbsp;'md'<br>&#124;&nbsp;'lg'<br>&#124;&nbsp;'xl'<br>&#124;&nbsp;false<br>&#124;&nbsp;string"
}
},
"default": "'lg'"
},
"sx": {
"type": {
Expand Down
14 changes: 9 additions & 5 deletions docs/pages/material-ui/api/grid-2.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@
"type": {
"name": "union",
"description": "Array&lt;number&gt;<br>&#124;&nbsp;number<br>&#124;&nbsp;object"
}
},
"default": "12"
},
"columnSpacing": {
"type": {
"name": "union",
"description": "Array&lt;number<br>&#124;&nbsp;string&gt;<br>&#124;&nbsp;number<br>&#124;&nbsp;object<br>&#124;&nbsp;string"
}
},
"container": { "type": { "name": "bool" } },
"container": { "type": { "name": "bool" }, "default": "false" },
"direction": {
"type": {
"name": "union",
"description": "'column-reverse'<br>&#124;&nbsp;'column'<br>&#124;&nbsp;'row-reverse'<br>&#124;&nbsp;'row'<br>&#124;&nbsp;Array&lt;'column-reverse'<br>&#124;&nbsp;'column'<br>&#124;&nbsp;'row-reverse'<br>&#124;&nbsp;'row'&gt;<br>&#124;&nbsp;object"
}
},
"default": "'row'"
},
"offset": {
"type": {
Expand All @@ -42,13 +44,15 @@
"type": {
"name": "union",
"description": "Array&lt;number<br>&#124;&nbsp;string&gt;<br>&#124;&nbsp;number<br>&#124;&nbsp;object<br>&#124;&nbsp;string"
}
},
"default": "0"
},
"wrap": {
"type": {
"name": "enum",
"description": "'nowrap'<br>&#124;&nbsp;'wrap-reverse'<br>&#124;&nbsp;'wrap'"
}
},
"default": "'wrap'"
}
},
"name": "Grid2",
Expand Down
8 changes: 5 additions & 3 deletions docs/pages/material-ui/api/stack.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
"type": {
"name": "union",
"description": "'column-reverse'<br>&#124;&nbsp;'column'<br>&#124;&nbsp;'row-reverse'<br>&#124;&nbsp;'row'<br>&#124;&nbsp;Array&lt;'column-reverse'<br>&#124;&nbsp;'column'<br>&#124;&nbsp;'row-reverse'<br>&#124;&nbsp;'row'&gt;<br>&#124;&nbsp;object"
}
},
"default": "'column'"
},
"divider": { "type": { "name": "node" } },
"spacing": {
"type": {
"name": "union",
"description": "Array&lt;number<br>&#124;&nbsp;string&gt;<br>&#124;&nbsp;number<br>&#124;&nbsp;object<br>&#124;&nbsp;string"
}
},
"default": "0"
},
"sx": {
"type": {
Expand All @@ -22,7 +24,7 @@
},
"additionalInfo": { "sx": true }
},
"useFlexGap": { "type": { "name": "bool" } }
"useFlexGap": { "type": { "name": "bool" }, "default": "false" }
},
"name": "Stack",
"imports": ["import Stack from '@mui/material/Stack';", "import { Stack } from '@mui/material';"],
Expand Down
7 changes: 4 additions & 3 deletions docs/pages/system/api/container.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
"props": {
"classes": { "type": { "name": "object" }, "additionalInfo": { "cssApi": true } },
"component": { "type": { "name": "elementType" } },
"disableGutters": { "type": { "name": "bool" } },
"fixed": { "type": { "name": "bool" } },
"disableGutters": { "type": { "name": "bool" }, "default": "false" },
"fixed": { "type": { "name": "bool" }, "default": "false" },
"maxWidth": {
"type": {
"name": "union",
"description": "'xs'<br>&#124;&nbsp;'sm'<br>&#124;&nbsp;'md'<br>&#124;&nbsp;'lg'<br>&#124;&nbsp;'xl'<br>&#124;&nbsp;false<br>&#124;&nbsp;string"
}
},
"default": "'lg'"
},
"sx": {
"type": {
Expand Down
14 changes: 9 additions & 5 deletions docs/pages/system/api/grid.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@
"type": {
"name": "union",
"description": "Array&lt;number&gt;<br>&#124;&nbsp;number<br>&#124;&nbsp;object"
}
},
"default": "12"
},
"columnSpacing": {
"type": {
"name": "union",
"description": "Array&lt;number<br>&#124;&nbsp;string&gt;<br>&#124;&nbsp;number<br>&#124;&nbsp;object<br>&#124;&nbsp;string"
}
},
"container": { "type": { "name": "bool" } },
"container": { "type": { "name": "bool" }, "default": "false" },
"direction": {
"type": {
"name": "union",
"description": "'column-reverse'<br>&#124;&nbsp;'column'<br>&#124;&nbsp;'row-reverse'<br>&#124;&nbsp;'row'<br>&#124;&nbsp;Array&lt;'column-reverse'<br>&#124;&nbsp;'column'<br>&#124;&nbsp;'row-reverse'<br>&#124;&nbsp;'row'&gt;<br>&#124;&nbsp;object"
}
},
"default": "'row'"
},
"offset": {
"type": {
Expand All @@ -42,13 +44,15 @@
"type": {
"name": "union",
"description": "Array&lt;number<br>&#124;&nbsp;string&gt;<br>&#124;&nbsp;number<br>&#124;&nbsp;object<br>&#124;&nbsp;string"
}
},
"default": "0"
},
"wrap": {
"type": {
"name": "enum",
"description": "'nowrap'<br>&#124;&nbsp;'wrap-reverse'<br>&#124;&nbsp;'wrap'"
}
},
"default": "'wrap'"
}
},
"name": "Grid",
Expand Down
8 changes: 5 additions & 3 deletions docs/pages/system/api/stack.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
"type": {
"name": "union",
"description": "'column-reverse'<br>&#124;&nbsp;'column'<br>&#124;&nbsp;'row-reverse'<br>&#124;&nbsp;'row'<br>&#124;&nbsp;Array&lt;'column-reverse'<br>&#124;&nbsp;'column'<br>&#124;&nbsp;'row-reverse'<br>&#124;&nbsp;'row'&gt;<br>&#124;&nbsp;object"
}
},
"default": "'column'"
},
"divider": { "type": { "name": "node" } },
"spacing": {
"type": {
"name": "union",
"description": "Array&lt;number<br>&#124;&nbsp;string&gt;<br>&#124;&nbsp;number<br>&#124;&nbsp;object<br>&#124;&nbsp;string"
}
},
"default": "0"
},
"sx": {
"type": {
Expand All @@ -22,7 +24,7 @@
},
"additionalInfo": { "sx": true }
},
"useFlexGap": { "type": { "name": "bool" } }
"useFlexGap": { "type": { "name": "bool" }, "default": "false" }
},
"name": "Stack",
"imports": ["import Stack from '@mui/system/Stack';", "import { Stack } from '@mui/system';"],
Expand Down
41 changes: 21 additions & 20 deletions packages/api-docs-builder/ApiBuilders/ComponentApiBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,58 +628,59 @@ export default async function generateComponentApi(
const filename = componentInfo.filename;
let reactApi: ComponentReactApi;

if (componentInfo.isSystemComponent || componentInfo.name === 'Grid2') {
Copy link
Member Author

@oliviertassinari oliviertassinari Nov 24, 2024

Choose a reason for hiding this comment

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

That hard-coded logic felt wrong, we further added stuff around it in 08dce48#diff-eef575d465fe9894710e7eb399c76ad3e3900a8cbb6d374be7f303c4b6c6ef51R627

try {
try {
reactApi = docgenParse(src, null, defaultHandlers.concat(muiDefaultPropsHandler), {
filename,
});
} catch (error) {
// fallback to default logic if there is no `create*` definition.
if ((error as Error).message === 'No suitable component definition found.') {
reactApi = docgenParse(
src,
(ast) => {
let node;
// TODO migrate to react-docgen v6, using Babel AST now
astTypes.visit(ast, {
visitFunctionDeclaration: (functionPath) => {
// @ts-ignore
if (functionPath.node.params[0].name === 'props') {
node = functionPath;
}
return false;
},
visitVariableDeclaration: (variablePath) => {
const definitions: any[] = [];
if (variablePath.node.declarations) {
variablePath
.get('declarations')
.each((declarator: any) => definitions.push(declarator.get('init')));
}

definitions.forEach((definition) => {
// definition.value.expression is defined when the source is in TypeScript.
const expression = definition.value?.expression
? definition.get('expression')
: definition;
if (expression.value?.callee) {
const definitionName = expression.value.callee.name;

if (definitionName === `create${componentInfo.name}`) {
node = expression;
}
}
});

return false;
},
});

return node;
},
defaultHandlers,
{ filename },
);
} catch (error) {
// fallback to default logic if there is no `create*` definition.
if ((error as Error).message === 'No suitable component definition found.') {
reactApi = docgenParse(src, null, defaultHandlers.concat(muiDefaultPropsHandler), {
defaultHandlers.concat(muiDefaultPropsHandler),
{
filename,
});
} else {
throw error;
}
},
);
} else {
throw error;
}
} else {
reactApi = docgenParse(src, null, defaultHandlers.concat(muiDefaultPropsHandler), {
filename,
});
}

if (!reactApi.props) {
Expand Down
5 changes: 5 additions & 0 deletions packages/api-docs-builder/utils/defaultPropsHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ function getExplicitPropsDeclaration(
): NodePath | undefined {
const functionNode = getRenderBody(componentDefinition, importer);

// No function body available to inspect.
if (!functionNode.value) {
return undefined;
}

let propsPath: NodePath | undefined;
// visitVariableDeclarator, can't use visit body.node since it looses scope information
functionNode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ function isStyledFunction(node: ts.VariableDeclaration): boolean {
);
}

// TODO update to reflect https://github.com/DefinitelyTyped/DefinitelyTyped/pull/65135
function getJSXLikeReturnValueFromFunction(type: ts.Type, project: TypeScriptProject) {
return type
.getCallSignatures()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ function ClickAwayListener(props: ClickAwayListenerProps): React.JSX.Element {
return undefined;
}, [handleClickAway, mouseEvent]);

return <React.Fragment>{React.cloneElement(children, childrenProps)}</React.Fragment>;
return React.cloneElement(children, childrenProps);
}

ClickAwayListener.propTypes /* remove-proptypes */ = {
Expand Down
4 changes: 2 additions & 2 deletions packages/mui-base/src/NoSsr/NoSsr.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ function NoSsr(props: NoSsrProps): React.JSX.Element {
}
}, [defer]);

// We need the Fragment here to force react-docgen to recognise NoSsr as a component.
return <React.Fragment>{mountedState ? children : fallback}</React.Fragment>;
// TODO casting won't be needed at one point https://github.com/DefinitelyTyped/DefinitelyTyped/pull/65135
return (mountedState ? children : fallback) as React.JSX.Element;
}

NoSsr.propTypes /* remove-proptypes */ = {
Expand Down
8 changes: 2 additions & 6 deletions packages/mui-base/src/Portal/Portal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,10 @@ const Portal = React.forwardRef(function Portal(
};
return React.cloneElement(children, newProps);
}
return <React.Fragment>{children}</React.Fragment>;
return children;
}

return (
<React.Fragment>
{mountNode ? ReactDOM.createPortal(children, mountNode) : mountNode}
</React.Fragment>
);
return mountNode ? ReactDOM.createPortal(children, mountNode) : mountNode;
}) as React.ForwardRefExoticComponent<PortalProps & React.RefAttributes<Element>>;

Portal.propTypes /* remove-proptypes */ = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ function ClickAwayListener(props: ClickAwayListenerProps): React.JSX.Element {
return undefined;
}, [handleClickAway, mouseEvent]);

return <React.Fragment>{React.cloneElement(children, childrenProps)}</React.Fragment>;
return React.cloneElement(children, childrenProps);
}

ClickAwayListener.propTypes /* remove-proptypes */ = {
Expand Down
3 changes: 1 addition & 2 deletions packages/mui-material/src/Hidden/HiddenJs.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
'use client';
import * as React from 'react';
import PropTypes from 'prop-types';
import exactProp from '@mui/utils/exactProp';
import withWidth, { isWidthDown, isWidthUp } from './withWidth';
Expand Down Expand Up @@ -50,7 +49,7 @@ function HiddenJs(props) {
return null;
}

return <React.Fragment>{children}</React.Fragment>;
return children;
}

HiddenJs.propTypes = {
Expand Down
Loading