Problem/Motivation

In core/misc/ajax.js there are two functions marked as removed from Drupal 10 that still exist.

They are ajaxWrapperMultipleRootElements & ajaxWrapperNewContent. In core itself, the only usage of these files are in the ajax.js file & in their associated test.

from catch in the duplicate issue:
They were 'deprecated' in Drupal 8.6.0 before we had a JavaScript deprecation API. We need to actually deprecate them, so they can be removed. Should probably be deprecated in 8.6.0 for removal in 11.0.0 at this point. https://www.drupal.org/node/2940704

Steps to reproduce

Review core/misc/ajax.js and see the deprecations.

Proposed resolution

Remove the deprecated code.

Remaining tasks

Postponed on 12.x branch.

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3352549

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

DanielVeza created an issue. See original summary.

danielveza’s picture

Status: Active » Needs review
Parent issue: » #3284879: [meta] Requirements for tagging Drupal 11.0.0-beta1

Updated the deprecation to 11.0 following advice from @xjm

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Good cleanup

nod_’s picture

Status: Reviewed & tested by the community » Needs work

Let's take care of the todo in this issue too and add a deprecation warning. See https://www.drupal.org/node/3082634

   * @todo Add deprecation warning after it is possible. For more information
   *   see: https://www.drupal.org/project/drupal/issues/2973400
danielveza’s picture

Status: Needs work » Needs review

Added the deprecation errors, I think I've done it right by adding the returns but it would be good to get some eyes over it

nod_’s picture

Status: Needs review » Needs work

code looks good, some linting issues left

sagarchauhan’s picture

StatusFileSize
new3.1 KB
new2.27 KB

Fixing linting issues.

sagarchauhan’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 8: 3352549-8.patch, failed testing. View results

rpayanm made their first commit to this issue’s fork.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone made their first commit to this issue’s fork.

quietone’s picture

Issue summary: View changes

The MR is now against 11.x.

quietone credited catch.

quietone credited _shY.

quietone’s picture

quietone’s picture

catch’s picture

There are dozens of JavaScript test failures here, but from a quick scan, it looks like this deprecation might be all of them:

2x: Javascript Deprecation: The Drupal.theme.ajaxWrapperNewContent is
    deprecated in drupal:8.6.0 and is removed from drupal:11.0.0. See
    https://www.drupal.org/node/2940704
        2x in ViewsWizardTest::testCreateViewWizard from
    Drupal\Tests\views_ui\FunctionalJavascript
---- Drupal\Tests\workspaces\FunctionalJavascript\WorkspaceToolbarIntegration
longwave’s picture

The issue is this code, which triggers the deprecation on every Ajax insert:

      // For backward compatibility, in some cases a wrapper will be added. This
      // behavior will be removed before Drupal 9.0.0. If different behavior is
      // needed, the theme functions can be overridden.
      // @see https://www.drupal.org/node/2940704
      $newContent = Drupal.theme(
        'ajaxWrapperNewContent',
        $newContent,
        ajax,
        response,
      );

I don't think the current deprecation is going to help anyway. The change notice tells you to override the method if you want to change the behaviour; if you do this then the deprecation we add here won't be fired - in fact it's only fired if you *don't* override it, which is the wrong way round?

longwave’s picture

Maybe what we need to do is:

  1. Remove Drupal.theme.ajaxWrapperNewContent and Drupal.theme.ajaxWrapperMultipleRootElements
  2. In Drupal.AjaxCommand.insert if Drupal.theme.ajaxWrapperNewContent exists then:
    1. Issue a deprecation
    2. If Drupal.theme.ajaxWrapperMultipleRootElements exists then issue another deprecation
    3. If Drupal.theme.ajaxWrapperMultipleRootElements doesn't exist, define it (because the first theme function might call it)
    4. Call it as before
  3. Else if Drupal.theme.ajaxWrapperMultipleRootElements exists then issue a deprecation and use it?
  4. Otherwise: just hardcode the wrapper in the multiple elements case? It's not clear from the change record what we will do if there are still more than one root-level element returned.

Or, decide this is too complicated, and just drop it all from Drupal 11 without any deprecations, as we deprecated this several years ago and the code mentions removal from Drupal 9 etc, so in the event anyone was overriding this they have had plenty of notice anyway.

catch’s picture

Or, decide this is too complicated, and just drop it all from Drupal 11 without any deprecations, as we deprecated this several years ago and the code mentions removal from Drupal 9 etc, so in the event anyone was overriding this they have had plenty of notice anyway.

This is very appealing and I think we should do it. We can always try to improve the 10.x deprecations if it turns out to be a problem, but it's also quite possible no-one is relying on it.

longwave’s picture

It's still not clear what to do about the multiple root elements case; this is the breaking change.

@lauriii in #736066-357: ajax.js insert command sometimes wraps content in a div, potentially producing invalid HTML and other bugs:

The support for effects with multiple root elements is meant to be temporary. I also proposed that we give a warning for any users that would be affected by this logic, but we don't have a way to do that until #2962344: [policy, no patch] Document how to handle deprecations in JavaScript has been resolve.

So if we only add the div when there's multiple root elements and an effect, the bug would be fixed in most cases, and there wouldn't be any known breaking changes for existing sites.

However, we still haven't triggered that warning, and there may be users relying on the div wrapper around multiple elements.

So, new proposal:

  • In 10.3.x trigger a deprecation in Drupal.theme.ajaxWrapperNewContent only when the .length > 1 condition is true. If you were overriding this as per the change record, we assume you knew what you were doing; either you were adding divs back everywhere (but we told you this was going away), or you were overriding the multiple divs wrapper, and your code will be obsolete soon.
  • In 11.x remove all this code and drop the multiple div wrapper.
longwave’s picture

Rebased MR!3784 against 10.3.x and implemented #23.

longwave’s picture

Status: Needs work » Needs review

Also opened MR!7670 for the removal in Drupal 11.

longwave’s picture

Status: Needs review » Needs work

Some tests failing on both MRs.

finnsky made their first commit to this issue’s fork.

finnsky’s picture

Seems tests need deeper rework.

damienmckenna’s picture

The merge requests need to be updated to the latest changes on their respective branches.

finnsky changed the visibility of the branch 3352549-leftover-d10-deprecations to hidden.

finnsky’s picture

quietone’s picture

Title: Leftover D10 deprecations in ajax.js » Remove deprecations in ajax.js
Issue summary: View changes
Status: Needs work » Postponed
Parent issue: #3301206: [meta] Fix incomplete/incorrect deprecations in Drupal core » #3466088: [meta] Deprecate dependencies, libraries, modules, and themes that will be removed from Drupal 12 core

The deprecation was updated so this code would be removed in Drupal 12.0.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

andypost’s picture

Status: Postponed » Needs work
finnsky’s picture

Rebased. Please review!

finnsky’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Appears like a good removal.

catch’s picture

Status: Reviewed & tested by the community » Needs work

Discussed this with @longwave. We both think it's OK to go ahead and remove this without the tricky deprecation layer, 8.6 was a very long time ago.

However there are at least two test failures in the latest pipeline that look very related (AJAX test + one performance test).

longwave’s picture

Status: Needs work » Needs review
smustgrave’s picture

Status: Needs review » Needs work

Javascript errors appear to be valid to the change.

smustgrave’s picture

Forgot about this one and was doing deprecation removals in #3575462: Remove deprecations from themes and misc and hitting the same test failures.

smustgrave’s picture

Fixed 1 test but still not sure about testBlockFilter

smustgrave’s picture

Still don't have a fix but the bug is that filtering on layout builder doesn't work at all now

smustgrave’s picture

I’d like to propose we don’t do this lol. It breaks layout builder filtering so may be a fair assumption it’ll break a contrib module. But reason I’m proposing we skip is because htmx will replace Ajax and we can eventually delete this file