Reduce toolbar user button related browser reflow

Created on 30 March 2023, about 1 year ago
Updated 4 May 2023, about 1 year ago

Problem/Motivation

De-scoped from 🐛 Toolbar tray rendering can result "flickering" resizing of content area to accommodate open trays Fixed

The user toolbar button lazy-builds its text content, which is the username of the current user. This results in a reflow as the button does not account for the increased width once the username is dynamically added. If there is logic that runs before the initial paint that sets that button to its eventual width (the username does not necessarily have to be in there) then the reflow does not occur.

Steps to reproduce

Proposed resolution

Set a dynamic min width to the toolbar button that is added prior to initial rendering so the width does not change when the lazy builder completes.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

📌 Task
Status

Fixed

Version

10.1

Component
Toolbar 

Last updated 4 days ago

  • Maintained by
  • 🇫🇷France @nod_
Created by

🇺🇸United States bnjmnm Ann Arbor, MI

Live updates comments and jobs are added and updated live.
  • Field UX

    Usability improvements related to the Field UI

Sign in to follow issues

Comments & Activities

  • Issue created by @bnjmnm
  • @bnjmnm opened merge request.
  • 🇺🇸United States dww

    Transferring the tag that was removed when this was rescoped to its own issue. 😅 We really do need to be careful here, so explicit security-minded review is required before this should land.

    Thanks!
    -Derek

  • Status changed to Needs work about 1 year ago
  • 🇺🇸United States dww

    This issue now partly reverts 📌 Deprecate/remove js-cookie dependency Fixed , adding that as definitely related.

    Added some review comments on the MR. 1 is just a clarifying comment, 1 a nit, 1 something of substance I think we should fix before this proceeds. Hence NW.

    I'm no longer an active member of the sec team, so I don't feel authorized to remove the security review tag I just added, but my quick read of the MR and I don't see anything to complain about from that perspective. You're only setting the cookie for authenticated users. You change it if the username changes. You clear it if the user logs out. I assume the place we're printing this username is already escaping the output to prevent XSS, etc, so I don't see how it matters if we get the untrusted string from a cookie or from a lazy builder. Not a thorough review, but an initial "all seems reasonable to me". 😅

    Gotta run for client work, but excited to see progress on all these toolbar UI issues!

    Thanks,
    -Derek

  • 🇩🇪Germany jan kellermann

    In Europe we have Data Protection Rights (GDPR) and in germany we have a law calles TTDSG for cookies. by this law the user has explicetly to opt in BEFORE a cookie is set - except it is absolutely needed to deliver service (like Session-Cookie). With this idea for additional cookies any Drupal Site in germany needs an additional opt-in for this cookie, because "reducing repaints" is not "absolutely needed to deliver service". Maybe you can do this optional in a theme. But please no unnecessary cookies in core.

    From my view not a good idea.

  • 🇬🇧United Kingdom longwave UK

    @dww brought this issue up in Slack and I also mentioned the GDPR implications in Europe of storing personal data (the username) in a cookie, before seeing @jan kellermann's comment. I am not a lawyer but I agree that this will likely be problematic; as I understand it European sites that use the toolbar module would have to allow users to explicitly opt in to this feature to stay within the current legal guidelines.

  • 🇬🇧United Kingdom longwave UK

    Does it have to be in a cookie? user_js_settings_alter() already puts the user ID in drupalSettings.user.uid so it would be trivial to add the username here too.

  • Status changed to Postponed about 1 year ago
  • 🇺🇸United States bnjmnm Ann Arbor, MI

    In Europe we have Data Protection Rights (GDPR) and in germany we have a law called TTDSG for cookies. By this law the user has explicitly to opt in BEFORE a cookie is set - except it is absolutely needed to deliver service (like session-cookie). With this idea for additional cookies any Drupal site in germany needs an additional opt-in for this cookie, because "reducing repaints" is not "absolutely needed to deliver service". Maybe you can do this optional in a theme. But please no unnecessary cookies in core.

    From my view not a good idea.

    The cookie approach has been the active approach for a while in 🐛 Toolbar tray rendering can result "flickering" resizing of content area to accommodate open trays Fixed , which addresses many toolbar issues beyond the admittedly more trivial one here. However... I recently had to change that approach to ensure there weren't caching conflicts. With the new approach, it may be possible to simply use localStorage and not have to use Cookies at all.. Since it sounds like the cookie would add major annoyance for German users (and perhaps ones other countries too) it seems like finding a way to accomplish this with localStorage is necessary.

    I'm going to postpone this until I can confirm a localStorage approach works in 🐛 Toolbar tray rendering can result "flickering" resizing of content area to accommodate open trays Fixed

  • 🇩🇪Germany jan kellermann

    @bnjmnm

    > it may be possible to simply use localStorage and not have to use Cookies at all

    Any change in the browser needs explicetly to opt in before the change is made. Changes in the browser means cookies, localStorage and every data saved in the browser.

    See german law here: https://dsgvo-gesetz.de/ttdsg/25-ttdsg/

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,361 pass, 1 fail
  • @bnjmnm opened merge request.
  • Status changed to Needs review about 1 year ago
  • 🇺🇸United States bnjmnm Ann Arbor, MI

    The username does not need to be stored to prevent the reflow, it's only necessary to know how much space to set aside for the name that will eventually be added via lazy loader. The width change is significantly more jarring than the name popping in. The user-button-width MR uses this approach.

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    CI aborted
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,366 pass
  • 🇺🇸United States bnjmnm Ann Arbor, MI
  • Issue was unassigned.
  • 🇺🇸United States bnjmnm Ann Arbor, MI
  • 🇺🇸United States bnjmnm Ann Arbor, MI
  • 🇬🇧United Kingdom longwave UK

    Removing the security review tag, as the new approach doesn't involve storing the username on the client side at all, so this alleviates any GDPR or other security concerns.

  • Status changed to RTBC about 1 year ago
  • 🇺🇸United States smustgrave

    Changes look good.

    Did some basic checking of the toolbar
    Refresh the page a number of times
    Go to several different pages
    Cleared cache a few times

    Didn't notice any issue.

  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,366 pass
  • Open in Jenkins → Open on Drupal.org →
    Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    29,371 pass
  • 🇫🇮Finland lauriii Finland

    Committed 8149f97 and pushed to 10.1.x. Thanks!

  • Status changed to Fixed about 1 year ago
    • lauriii committed 8149f97c on 10.1.x
      Issue #3351356 by bnjmnm, longwave, dww, jan kellermann, smustgrave:...
  • 🇺🇸United States bnjmnm Ann Arbor, MI
  • 🇺🇸United States dww

    Yay, thanks everyone!

    Always love it when everyone who participated in an issue did so meaningfully and all users are credited. 🎉 Refreshing! 😅

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.69.0 2024