Follow-up to #2844261: Allow dialog links to specify a renderer in addition to a dialog type
Problem/Motivation
Sometimes the Drupal.ajax.instances
array contains items that are null
.
It seems that when the off-canvas form is opened up in the dialog it creates an element in Drupal.ajax.instances because the forms submit via ajax now after #2785047: In Outside In mode, form validation messages should appear in the off-canvas tray, not the main page. So when the dialog is closed or reloaded this code in ajax.es6js is invoked
detach(context, settings, trigger) {
if (trigger === 'unload') {
Drupal.ajax.expired().forEach((instance) => {
// Set this to null and allow garbage collection to reclaim
// the memory.
Drupal.ajax.instances[instance.instanceIndex] = null;
});
}
},
which sets the element in the array for the form submit to NULL.
To manually confirm this error:
- Enable Settings Tray module
- Goto any front-end page.
- Click "Edit" in the toolbar to go into Edit Mode
- Click any block that will open the off-canvas dialog
- Close the off-canvas dialog
- Click the same block again to open the off-canvas dialog
- Check the Javascript console for your browser and confirm this error shows up
Uncaught TypeError: Cannot read property 'element' of null
at http://www.octo2.dev/d8_2_ux/core/modules/outside_in/js/outside_in.js?v=...
Proposed resolution
Opt out of operating on those instances to avoid throwing an error when opening the same form in settings tray multiple times in a row.
Although it would be great to have tests for this changes it does not actually produce any error except the Javascript console error that we can test for.
In theory the test should just fail because of this error but if you look at the test_only patch in #4 this is not the case.
It is possible to confirm with manually testing list above that patch in #2 does fix the problem.