-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
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
[Masonry] Initialized with no children results in error #29362
Comments
@joziahg Thanks for the report! The following change will do: diff --git a/packages/mui-lab/src/Masonry/Masonry.js b/packages/mui-lab/src/Masonry/Masonry.js
index 78c23bf31c..c47f92d19b 100644
--- a/packages/mui-lab/src/Masonry/Masonry.js
+++ b/packages/mui-lab/src/Masonry/Masonry.js
@@ -180,6 +180,9 @@ const Masonry = React.forwardRef(function Masonry(inProps, ref) {
React.useEffect(() => {
const handleResize = () => {
+ if (!masonryRef.current.firstChild) {
+ return;
+ }
const parentWidth = masonryRef.current.clientWidth;
const childWidth = masonryRef.current.firstChild.clientWidth;
const firstChildComputedStyle = window.getComputedStyle(masonryRef.current.firstChild); Would you like to create a PR for this 😃? |
@hbjORbj Sure, seems like an easy first PR |
I'm a complete newbie. |
@joziahg I'm so sorry I didn't notice that you intend to do a PR. I'm not an English speaker so I didn't get it. |
No worries! The more contributors the project has, the better. There will
be other opportunities for me.
Thanks for the PR!
On Fri, Oct 29, 2021 at 2:28 PM Abdelrazek alaa ***@***.***> wrote:
@joziahg <https://github.com/joziahg> I'm so sorry I didn't notice that
you intend to do a PR. I'm not an English speaker so I didn't get it.
what should I do now?. how could I undo what I've made.
our maintainers please do what is right for this situation, and if
@joziahg <https://github.com/joziahg> is still wanna do PR please delete
my own PR.
I'm so sorry guys.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#29362 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ADLOOLB3RWUMNWJFK4W4OJDUJLYUZANCNFSM5G5WALKQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
--
Joziah Grimm
(319)-929-6952
|
@joziahg thank you for your kindness. |
@abdelrazek-alaa @joziahg Thank you both :) |
@joziahg Would you still like to create a PR? For testing, please go to import * as React from 'react';
import Masonry from '@mui/lab/Masonry';
export default function EmptyMasonry() {
return <Masonry columns={3} spacing={1} />;
} |
Initializing the
Masonry
component with no children or an empty array of children results in an error.Current Behavior 😯
When
Masonry
is initialized with no children or an empty of children, the component errors.Expected Behavior 🤔
Masonry errors if initialized with no children. Setting children to an empty array after initialization results in no error.
Steps to Reproduce 🕹
Steps:
https://codesandbox.io/s/basicmasonry-material-demo-forked-thsv4?file=/demo.js
Context 🔦
Your Environment 🌎
`npx @mui/envinfo`
The text was updated successfully, but these errors were encountered: