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

[Grid] ignore RSC error #233

Merged
merged 2 commits into from
Sep 17, 2024
Merged
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
14 changes: 10 additions & 4 deletions packages/pigment-css-react/src/Grid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ import { generateAtomics } from './generateAtomics';
import styled from './styled';

function isGridComponent(element) {
// For server components `muiName` is avaialble in element.type._payload.value.muiName
// relevant info - https://github.com/facebook/react/blob/2807d781a08db8e9873687fccc25c0f12b4fb3d4/packages/react/src/ReactLazy.js#L45
// eslint-disable-next-line no-underscore-dangle
return element.type.muiName === 'Grid' || element.type?._payload?.value?.muiName === 'Grid';
try {
// For server components `muiName` is avaialble in element.type._payload.value.muiName
// relevant info - https://github.com/facebook/react/blob/2807d781a08db8e9873687fccc25c0f12b4fb3d4/packages/react/src/ReactLazy.js#L45
// eslint-disable-next-line no-underscore-dangle
return element.type.muiName === 'Grid' || element.type?._payload?.value?.muiName === 'Grid';
} catch (error) {
Copy link
Member

@DiegoAndai DiegoAndai Sep 13, 2024

Choose a reason for hiding this comment

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

Can we check for the specific error so we don't catch unintended ones?

if (error.message.startsWith("Cannot access default.muiName on the server.") {
  // Covers for the case in which the Grid is a server component and the child is a client component
  // https://github.com/mui/material-ui/issues/43635
  return false;
} else {
  throw error
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Are you sure, the message check is quite fragile. Given the size of the function, eventhough it catches, I think it's still better than checking message.

cc @brijeshb42

// Covers for the case in which the Grid is a server component and the child is a client component
// https://github.com/mui/material-ui/issues/43635
return false;
}
}

const gridAtomics = generateAtomics(({ theme }) => {
Expand Down
14 changes: 10 additions & 4 deletions packages/pigment-css-react/tests/Grid/fixtures/Grid.output.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ import clsx from 'clsx';
import PropTypes from 'prop-types';
import * as React from 'react';
function isGridComponent(element) {
// For server components `muiName` is avaialble in element.type._payload.value.muiName
// relevant info - https://github.com/facebook/react/blob/2807d781a08db8e9873687fccc25c0f12b4fb3d4/packages/react/src/ReactLazy.js#L45
// eslint-disable-next-line no-underscore-dangle
return element.type.muiName === 'Grid' || element.type?._payload?.value?.muiName === 'Grid';
try {
// For server components `muiName` is avaialble in element.type._payload.value.muiName
// relevant info - https://github.com/facebook/react/blob/2807d781a08db8e9873687fccc25c0f12b4fb3d4/packages/react/src/ReactLazy.js#L45
// eslint-disable-next-line no-underscore-dangle
return element.type.muiName === 'Grid' || element.type?._payload?.value?.muiName === 'Grid';
} catch (error) {
// Covers for the case in which the Grid is a server component and the child is a client component
// https://github.com/mui/material-ui/issues/43635
return false;
}
}
const gridAtomics = /*#__PURE__*/ _atomics({
styles: {
Expand Down
Loading