File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed
Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -68,6 +68,7 @@ export default class SubMenu extends AbstractMenu {
6868 if ( this . props . forceOpen || this . state . visible ) {
6969 const wrapper = window . requestAnimationFrame || setTimeout ;
7070 wrapper ( ( ) => {
71+ if ( ! this . subMenu ) return ;
7172 const styles = this . props . rtl
7273 ? this . getRTLMenuPosition ( )
7374 : this . getMenuPosition ( ) ;
@@ -88,6 +89,7 @@ export default class SubMenu extends AbstractMenu {
8889 } ) ;
8990 } else {
9091 const cleanup = ( ) => {
92+ if ( ! this . subMenu ) return ;
9193 this . subMenu . removeEventListener ( 'transitionend' , cleanup ) ;
9294 this . subMenu . style . removeProperty ( 'bottom' ) ;
9395 this . subMenu . style . removeProperty ( 'right' ) ;
Original file line number Diff line number Diff line change @@ -42,4 +42,19 @@ describe('<SubMenu/>', () => {
4242 await user . hover ( wrapper ) ;
4343 await expect ( ( ) => waitForMenuVisible ( submenu ) ) . rejects . toThrow ( ) ;
4444 } ) ;
45+
46+ it ( 'should not crash after immediate unmount' , async ( ) => {
47+ let callback = null ;
48+ jest . spyOn ( window , 'requestAnimationFrame' ) . mockImplementation ( ( cb ) => {
49+ callback = cb ;
50+ return 1 ;
51+ } ) ;
52+ const { unmount } = render ( < SubMenu title = 'Title' hoverDelay = { 0 } /> ) ;
53+ const user = userEvent . setup ( ) ;
54+ const wrapper = screen . getByText ( 'Title' ) ;
55+ await user . hover ( wrapper ) ;
56+ unmount ( ) ;
57+
58+ expect ( callback ) . not . toThrow ( ) ;
59+ } ) ;
4560} ) ;
You can’t perform that action at this time.
0 commit comments