Replace Contextual Links BackboneJS usage with VanillaJS equivalent

Created on 16 March 2021, about 4 years ago
Updated 12 February 2023, over 2 years ago

Problem/Motivation

It was decided that core use of BackboneJS will be replaced with VanillaJS equivalents: #3145958: [META] Re-evaluate use of Backbone.js in core

This issue's scope to to replace contextual links; use of Backbone with Vanilla JS. No functionality should change, just the JS used to achieve it.

Steps to reproduce

Proposed resolution

Remaining tasks

User interface changes

API changes

The *ModelView objects take care of rendering things at the appropriate time so there are no events published on the outside for other code to listen to. It's fine since contrib doesn't extend this.

Data model changes

Release notes snippet

📌 Task
Status

Needs work

Version

10.1

Component
Contextual 

Last updated 4 days ago

Created by

🇺🇸United States bnjmnm Ann Arbor, MI

Live updates comments and jobs are added and updated live.
  • Needs reroll

    The patch will have to be re-rolled with new suggestions/changes described in the comments in the issue.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • 🇮🇳India karishmaamin

    Fixed some of indentation error. Keeping it Needs work to fix PHPStan error

  • 🇮🇳India nikhil_110

    Re-roll patch #36 and Try to fix Cs issue

  • 🇮🇳India nitin shrivastava

    fix command failures #37

  • 🇮🇳India prem suthar Ahemdabad- Gujrat , Jodhpur - Rajsthan

    Try To Fix the #38 Patch.

  • 🇮🇳India vsujeetkumar Delhi

    @Prem Suthar, Interdiff is missing in #39, We should add that along with the patch. Its help to the reviewers to find the difference and what are the changes we have made from last patch. Also some Tests fails because some of the files are missing in the patch. Please compare with #26.

  • 🇮🇳India vsujeetkumar Delhi

    Re-roll patch created for 11.x, We have added some missing JS files according to #26 and removed es6.js files with reference of this document . Keeps as is "Needs work" because we have some unaddressed comments above.

  • last update over 1 year ago
    30,318 pass, 35 fail
  • 🇬🇧United Kingdom catch

    📌 [meta] Deprecate Toolabr module Active will be unblocked soon, which will leave this as the last remaining usage of backbone in Drupal core. It would be great to be able to remove the backbone library from Drupal 12. Bumping this to major.

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Rebased the MR off 11.x

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10
  • Pipeline finished with Failed
    2 months ago
    Total: 168s
    #445317
  • Pipeline finished with Failed
    2 months ago
    Total: 677s
    #446603
  • Pipeline finished with Failed
    2 months ago
    Total: 393s
    #446625
  • 🇺🇸United States smustgrave

    Fixed the pipeline so it would run but appears to have broken a few tests.

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Fixed the bad reroll which could have been me but also could have been a previous iteration.
    Seems to be working locally in manual testing.

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Failing tests look valid

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    There were some underscore references left behind. Got rid of those because they're not needed in 2025 - we have native methods

    Spot checked some tests locally and its looking good

  • 🇺🇸United States nicxvan

    There is a functional JS failure that looks relevant, I can't rerun it since a core committer created the branch.

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Yep it's a real fail
    Closing the contextual link list used to place focus on the trigger but that isn't happening now.
    Tried a few things but they all end up in a loop
    Will revisit this week

  • Pipeline finished with Failed
    about 1 month ago
    Total: 233s
    #470395
  • Pipeline finished with Failed
    about 1 month ago
    Total: 226s
    #470405
  • Assigned to larowlan
  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Dug some more into the final fail
    The issue is that when the dialog is opened from the contextual link that uses ajax and a dlalog, when jQueryUI attempts this code

    this.opener = $( this.document[ 0 ].activeElement );
    

    we've already blurred the link and hence there's no focussed element to use as the opener, which means we can't return the focus.

    Any ideas @bnjmnm?

  • Pipeline finished with Failed
    17 days ago
    Total: 542s
    #484291
  • Pipeline finished with Failed
    17 days ago
    #484308
  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Realized that the order events was being attached were different so re-ordered to ensure that ajax events are added first.
    Also worked to reduce the amount of re-renders.
    Then also tried using a targeted event (e.g. click.contextualLinks)

    None of those helped

  • Pipeline finished with Failed
    17 days ago
    #484317
  • Pipeline finished with Failed
    17 days ago
    Total: 752s
    #484490
  • Merge request !11971Resolve #3203920 "Replace contextual links alt" → (Closed) created by nod_
  • 🇫🇷France nod_ Lille

    Tried to go back a few commits and fixed a problem with hovering out of a region and contextual links not closing, not sure it's the same issue as #51 but it was broken before and now it's not. Can you let me know how to reproduce the failure with dialog?

    opened a new MR to not erase the work in case it's a different bug.

    Also all the comments have been removed, would be good to keep them around, they help with understanding what's going on

  • Pipeline finished with Failed
    17 days ago
    Total: 1798s
    #484572
  • 🇫🇷France nod_ Lille

    could reproduce the problem with ajax using contextual_test module.

    It seems it's the event delegation that used to be in backbone that was making things work. Somewhere it was switched to direct event binding and because there is so much re-rendering the event listeners were trashed and it caused issues apparently.

  • Pipeline finished with Failed
    17 days ago
    Total: 164s
    #484742
  • 🇫🇷France nod_ Lille
  • Pipeline finished with Success
    17 days ago
    #484753
  • 🇫🇷France nod_ Lille

    MR is green, need the comments added back for the various function we copy/pasted.

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    larowlan changed the visibility of the branch 3203920-rebased to hidden.

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Added the docs back

  • Pipeline finished with Success
    16 days ago
    Total: 514s
    #486231
  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    This is green and should be pretty close, thanks @nod_ for the last fix

  • 🇺🇸United States nicxvan

    I can't content on the mr for some reason.

    Some comments could still use cleanup:

    // This uses proxy to look for added instances. Backbone also listened for
    // reset and remove, which I'm unsure how do accomplish.

    Otherwise looks good, JS is not my forte though.

  • 🇦🇺Australia larowlan 🇦🇺🏝.au GMT+10

    Addressed feedback, ready for review again

  • Pipeline finished with Failed
    10 days ago
    Total: 400s
    #489700
  • Pipeline finished with Success
    10 days ago
    Total: 657s
    #489710
  • Pipeline finished with Success
    8 days ago
    Total: 610s
    #491858
  • 🇺🇸United States nicxvan

    Ok, I think this is ready.

    I tested manually both in 11.x and this branch locally.
    I tested block and view contextual links and tested with both mouse and keyboard. As far as I can tell both act exactly the same.

    I searched for references to backbone, the only references remaining are for toolbar. There are no more references in contextual.

    Javascript is not my forte as mentioned, but I am familiar with it, reviewing the code directly I see nothing that looks amiss.

    As far as I can tell both larowlan and _nod have worked on this to a non trivial extent.

    The only thing I didn't check that may be worth it is performance. I'm not super familiar with JS performance testing so I'll leave that up to a committer to determine if it's necessary.

    _nod's comment in 56 make me think the change has been addressed as far as I can tell.

  • Pipeline finished with Failed
    7 days ago
    Total: 644s
    #492954
  • Pipeline finished with Success
    7 days ago
    Total: 937s
    #492968
    • nod_ committed d3815233 on 11.x
      Issue #3203920 by larowlan, nod_, bnjmnm, vsujeetkumar, smustgrave,...
  • 🇫🇷France nod_ Lille

    Committed d381523 and pushed to 11.x. Thanks!

Production build 0.71.5 2024