diff --git a/core/misc/ajax.es6.js b/core/misc/ajax.es6.js index 959c3565f2..91680d510b 100644 --- a/core/misc/ajax.es6.js +++ b/core/misc/ajax.es6.js @@ -982,6 +982,9 @@ /** * Provide a wrapper for new content via Ajax. * + * Wrap the inserted markup when trying to insert multiple root elements with + * a ajax effect. + * * @param {jQuery} $newContent * Response elements after parsing. * @param {Drupal.Ajax} ajax @@ -989,10 +992,10 @@ * @param {object} response * The response from the Ajax request. * - * @deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.0. - * Use data with desired wrapper. + * @deprecated in Drupal 8.6.x and will be removed before Drupal 9.0.0. + * Use data with desired wrapper. See https://www.drupal.org/node/2974880. * - * @todo: Add trigger an error after it will be possible. See + * @todo: Add deprecation warning after it will be possible. See * https://www.drupal.org/project/drupal/issues/2973400 */ Drupal.theme.ajaxWrapperNewContent = ($newContent, ajax, response) => ( @@ -1000,9 +1003,10 @@ $newContent.filter( i => !( + // We can not consider HTML comments or whitespace text as separate + // roots, since they do not cause visual regression with effect. $newContent[i].nodeName === '#comment' || - ($newContent[i].nodeName === '#text' && - /^(\s|\n|\r)*$/.test($newContent[i].textContent)) + ($newContent[i].nodeName === '#text' && /^(\s|\n|\r)*$/.test($newContent[i].textContent)) ), ).length > 1 ? Drupal.theme('ajaxWrapperMultipleRootElements', $newContent) @@ -1015,10 +1019,10 @@ * @param {jQuery} $elements * Response elements after parsing. * - * @deprecated in Drupal 8.5.x and will be removed before Drupal 9.0.0. - * Use data with desired wrapper. + * @deprecated in Drupal 8.6.x and will be removed before Drupal 9.0.0. + * Use data with desired wrapper. See https://www.drupal.org/node/2974880. * - * @todo: Add trigger an error after it will be possible. See + * @todo: Add deprecation warning after it will be possible. See * https://www.drupal.org/project/drupal/issues/2973400 */ Drupal.theme.ajaxWrapperMultipleRootElements = ($elements) => ( @@ -1084,8 +1088,9 @@ // Parse response.data into an element collection. let $newContent = $($.parseHTML(response.data, document, true)); - // For backward compatibility, in some cases a wrapper will be added. Use - // theming to change it. See https://www.drupal.org/node/2940704. + // For backward compatibility, in some cases a wrapper will be added. This + // behavior will be removed before Drupal 9.0.0. Use theming to change it. + // See https://www.drupal.org/node/2940704. $newContent = Drupal.theme('ajaxWrapperNewContent', $newContent, ajax, response); // If removing content from the wrapper, detach behaviors first. diff --git a/core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php b/core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php index 68c85ad3d9..1897719f61 100644 --- a/core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php +++ b/core/modules/system/tests/modules/ajax_test/src/Controller/AjaxTestController.php @@ -43,7 +43,7 @@ public static function dialogContents() { } /** - * Example content for testing whether response should be wrapped in div. + * Example content for testing the wrapper of the response. * * @param string $type * Type of response. @@ -52,16 +52,13 @@ public static function dialogContents() { * Renderable array of AJAX response contents. */ public function renderTypes($type) { - $content = [ + return [ '#title' => 'AJAX Dialog & contents', 'content' => [ '#type' => 'inline_template', '#template' => $this->getRenderTypes()[$type]['render'], ], ]; - - $content['effect'] = 'fade'; - return $content; } /**