Turbo: Behaviours are often not attached if the script containing the behaviour finishes downloading/is evalutated after Turbo has rendered the new page

Created on 30 October 2023, 8 months ago
Updated 4 November 2023, 8 months ago

Problem/Motivation

See issue title.

Steps to reproduce

Navigate various admin sections and notice everything from table drag to drop buttons have behaviours attached inconsistently and often not at all when first arriving on a page that attaches its library via a Turbo visit and not a full page load.

Proposed resolution

There are a number of ways we could solve this, but since we don't have a way of knowing ahead of time what JavaScript file contains a behaviour and we don't want to naively run all attach callbacks since that will be quite inefficient (and possibly cause more problems if they're not well written), the best way will likely be to implement a MutationObserver that watches for new <script> elements, and when one is added, adds a load event handler to it; at the same time, it stores the current keys from Drupal.behaviors, and when the load handler is triggered, it compares the keys at that time with the previous set to figure out if any new behaviours were added, and if so, which ones, and then run the attach callbacks just for those.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

πŸ‡¨πŸ‡¦Canada Ambient.Impact Toronto

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.69.0 2024