Turbo: implement partial page updates

Created on 28 October 2023, 8 months ago

Problem/Motivation

Turbo Drive works reasonably well but detaching and attaching behaviours over the entire page is arguably overkill when only some regions change. The 8.x-1.x branch had a lot of logic to update only regions that changed and we should re-implement this in the Turbo port. Wim Leers explains the issue in #2692343-2 β†’ :

Finally, this means once again replacing the entire <body> and detaching/attaching Drupal behaviors (i.e. run all JS) on them. Which means it defeats a significant portion of the purpose: improve perceived speed by having the browser do less work. i.e. using the official Turbolinks JS significantly increases the amount of work the browser has to. This makes sense for that library because it wants to work on almost any HTML. But in the case of Drupal, we can take advantage of its cacheability metadata to automatically figure out which portions of the page change.

Caveats are that this was posted almost 8 years ago in 2016 before Hotwire Turbo existed, so this was about the predecessor, Turbolinks, which had less flexibility, and browsers have implemented more JavaScript/DOM optimizations since then. That said, he's right that this is still not optimal to update regions we don't have to.

Steps to reproduce

πŸ‘€

Proposed resolution

One possibility would be to use a custom renderer as supported by Turbo to only swap out the regions that have changed in the response and attach behaviours to the updated regions rather than the whole document.

How we determine how a region has changed will need some thought, but re-using the logic from the 8.x-1.x branch is probably our best bet, in that it uses cacheability metadata to decide if a region needs updating.

Remaining tasks

TBD.

User interface changes

None.

API changes

Maybe some additions? Not sure yet.

Data model changes

None.

πŸ“Œ Task
Status

Active

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