-
Notifications
You must be signed in to change notification settings - Fork 4.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
Fixed snackbar console error #38365
Fixed snackbar console error #38365
Conversation
Console Error : react-dom.js?ver=17.0.1:4088 Uncaught TypeError: Cannot read properties of undefined (reading 'current') at dismissMe (components.js)
👋 Thanks for your first Pull Request and for helping build the future of Gutenberg and WordPress, @manjeet-wisetr! In case you missed it, we'd love to have you join us in our Slack community, where we hold regularly weekly meetings open to anyone to coordinate with each other. If you want to learn more about WordPress development in general, check out the Core Handbook full of helpful information. |
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.
Thanks for contributing! The fix looks sensible to me 👍
Before merging, could we:
- fix the linting errors
- add a changelog entry for this bug fix
I think the e2e test failure is a flake... let's see if it goes away on the next run.
@mirka Just a quick question, is this a side-effect of a bigger problem? Why would this code error out? It's a simple focus. Maybe changing when useEffect fires would be better? |
My read of the problem was that the listRef focus call was added under the assumption that a Snackbar would always be rendered as a child of |
@mirka I don't have historical context around here either. Just wanted to ask to be sure. Focus relates to accessibility and I've got my eye on accessibility going forward to try to prevent regressions. |
@alexstine Ah ok thanks, I see your point. This PR does not introduce a regression in that sense, but it doesn't solve the focus restoration problem either, so I made a new issue for it (#38425). |
if ( listRef && listRef.current ) { | ||
listRef.current.focus(); | ||
} | ||
|
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.
if ( listRef && listRef.current ) { | |
listRef.current.focus(); | |
} | |
listRef.current?.focus(); |
suggestion (non-blocking): We could use "Optional chaining" here.
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.
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.
Thank works as well.
Only the changelog entry is missing, and we can merge this PR.
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.
changelog entry added
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.
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.
Thank you. Since the changelog is related to this change, I think it should be part of this PR.
Sorry, I probably should've mentioned this initially.
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.
Hi, @manjeet-wisetr
Can you consolidate the changelog commit with this PR?
Hi @manjeet-wisetr, The Thank you for your contribution! |
Description
Console error when click on snackbar:
react-dom.js?ver=17.0.1:4088 Uncaught TypeError: Cannot read properties of undefined (reading 'current') at dismissMe (components.js)
Screenshots
Types of changes
check added on listRef object in dismissMe function in snackbar component