Problem/Motivation
When a part of the DOM is replaced using Drupal core's AJAX capabilities, any behaviour attached to a nested element does not run if the replacement is largely the same as the original.
Steps to reproduce
- Fresh install of Drupal
- Install the attached test module
- Go to /ajax-test
- Open the browser console
- Click "What is the time"
- Observe the console to see the results of
console.log(context)
- Click "What is the time" again
- Observe the console to see the results of
console.log(context)
Desired behaviour: The attached JS behaviour should run each time and log the context to console.
Current behaviour: The attached JS behaviour only runs the first time the AJAX replacement occurs.
This issue can be worked around by causing AJAX to replace the affected markup with an empty div, then placing the replacement markup. Uncomment line 66 of \Drupal\ajax_test\Controller\AjaxTestController to see this in action.