Problem/Motivation
When using the media browser popup, it is possible to trigger
react-dom.min.js?v=16.8.4:121 TypeError: Cannot read properties of null (reading 'style') at dialog:aftercreate (toolbar.js?v=10.2.0:211:24) at dispatch (jquery.min.js?v=3.7.1:2:40035) at v.handle (jquery.min.js?v=3.7.1:2:38006) at Object.trigger (jquery.min.js?v=3.7.1:2:70124) at jquery.min.js?v=3.7.1:2:70726 at Function.each (jquery.min.js?v=3.7.1:2:3129) at ce.fn.init.each (jquery.min.js?v=3.7.1:2:1594) at ce.fn.init.trigger (jquery.min.js?v=3.7.1:2:70701) at openDialog (dialog.js?v=10.2.0:83:17) at dialog.showModal (dialog.js?v=10.2.0:101:7)
when the media browser is rendered as a modal. For example using a combination of Drupal 10.2, Gutenberg v3 and the media browser can trigger it. (It is possible to trigger this issue from other combinations of modules that use the media library popup dialog ui as well)
Steps to reproduce
To reproduce w/the gutenberg editor (it is reproducible from most ways to get to the media browser dialog popup UI)
Insert an image into the node body in gutenberg, click replace on the image in the gui, and hit open media library.
The console will emit errors like the above and
toolbar.js?v=10.2.0:230 Uncaught TypeError: Cannot read properties of null (reading 'style') at dialog:beforeclose (toolbar.js?v=10.2.0:230:24) at dispatch (jquery.min.js?v=3.7.1:2:40035) at v.handle (jquery.min.js?v=3.7.1:2:38006) at Object.trigger (jquery.min.js?v=3.7.1:2:70124) at jquery.min.js?v=3.7.1:2:70726 at Function.each (jquery.min.js?v=3.7.1:2:3129) at ce.fn.init.each (jquery.min.js?v=3.7.1:2:1594) at ce.fn.init.trigger (jquery.min.js?v=3.7.1:2:70701) at Object.closeDialog [as close] (dialog.js?v=10.2.0:87:17) at Object.close (dialog.js?v=10.2.0:31:35)
The dialog will be blank and there is no way to insert anything from the media library.
The error occurs because toolbar.js assumes that the toolbar is always part of the scope when the scope is actually limited in the context of the media browser popup dialog (I think...?)
Proposed resolution
The fix is pretty easy -- in toolbar.js check to see that toolbarBar is a thing before trying to manipulate it. There is no error handling if document.getElementByID('toolbar-bar'); returns null in this scope.
Apply the attached patch to work around it.