Problem/Motivation
After Updating to Drupal ~10.3.0 Contextual disappears intermittently, leading to console errors
settings_tray.js?v=10.3.0:171
Uncaught TypeError: Cannot read properties of null (reading 'id')
at settings_tray.js?v=10.3.0:171:31
at Array.forEach (<anonymous>)
at prepareAjaxLinks (settings_tray.js?v=10.3.0:162:8)
at HTMLDocument.<anonymous> (settings_tray.js?v=10.3.0:191:5)
at HTMLDocument.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 HTMLDocument.<anonymous> (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)
Steps to reproduce
- Drupal ~10.3.0
- Place inline block via layout builder or block via block layout
- Observe the issue.
Note that the issue doesn't always appear, so clearing the cache and then reloading sometimes causes the issue to occur. Additionally, the layout builder block's contextual feature sometimes breaks, resulting in the same error.
Proposed resolution
instance.options.data.dialogOptions.settingsTrayActiveEditableId = closestSettingsTray ? closestSettingsTray.id : undefined;
instead of instance.options.data.dialogOptions.settingsTrayActiveEditableId = closestSettingsTray.id;