Include compiled CSS from global asset library when displaying component library preview thumbnails

Created on 19 May 2025, about 1 month ago

Overview

After landing 📌 Compile Tailwind CSS globally for code components Active , we make use of the compiled CSS saved in the global asset library. The preview thumbnails for the component library sidebar needs to include this CSS.

Proposed resolution

  1. Include the CSS when rendering the preview thumbnails for the component library sidebar.
  2. Please ensure that the auto-saved version gets included, if exists.
  3. Be aware of 🐛 Canvas and hover preview out of sync after drag-drop and publish Active . While there might be overlap, it is a different issue. See comment #11 🐛 Canvas and hover preview out of sync after drag-drop and publish Active which suggest to test that issue without involving anything from the global CSS.

User interface changes

Code components are displayed with their CSS in the preview thumbnails for the component library sidebar. An easy way to test the success of this issue is to create a new code component, don't change anything, simply add it to the components, then look at its preview thumbnail in the library. If the component shows up with yellow background we made it!

📌 Task
Status

Active

Version

0.0

Component

Page builder

Created by

🇳🇱Netherlands balintbrews Amsterdam, NL

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

Merge Requests

Comments & Activities

  • Issue created by @balintbrews
  • 🇳🇱Netherlands balintbrews Amsterdam, NL

    Now that 🐛 Canvas and hover preview out of sync after drag-drop and publish Active is straightforward to land, let's do that first, so we don't get confused by the problem that issue fixes.

  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    +1 — the reason we didn't do this originally is because the global asset library functionality was not yet implemented in February — it was just "compiled into" each individual code component's CSS.

    This will require \Drupal\experience_builder\Hook\ComponentSourceHooks::pageAttachments()-like behavior but within each code component's asset library, and taking into account draft-or-not. Thanks to 🐛 Regression after #3500386: import map scope mismatch when auto-saved code component's JS sends a 307 Active , that should be trivial to achieve.

    It's too late for me to test this in detail and to think through everything, but I think this is enough:

    diff --git a/src/Plugin/ExperienceBuilder/ComponentSource/JsComponent.php b/src/Plugin/ExperienceBuilder/ComponentSource/JsComponent.php
    index 92ce9e429..dca8d53cd 100644
    --- a/src/Plugin/ExperienceBuilder/ComponentSource/JsComponent.php
    +++ b/src/Plugin/ExperienceBuilder/ComponentSource/JsComponent.php
    @@ -16,6 +16,7 @@ use Drupal\experience_builder\AutoSave\AutoSaveManager;
     use Drupal\experience_builder\AutoSaveData;
     use Drupal\experience_builder\ComponentDoesNotMeetRequirementsException;
     use Drupal\experience_builder\ComponentMetadataRequirementsChecker;
    +use Drupal\experience_builder\Entity\AssetLibrary;
     use Drupal\experience_builder\Entity\Component as ComponentEntity;
     use Drupal\experience_builder\Entity\ComponentInterface;
     use Drupal\experience_builder\Entity\JavaScriptComponent;
    @@ -167,8 +168,12 @@ final class JsComponent extends GeneratedFieldExplicitInputUxComponentSourceBase
           $component = $component->forAutoSavePreview($autoSave->data);
         }
         if ($isPreview) {
    +      $build['#attached']['library'][] = 'experience_builder/asset_library.' . AssetLibrary::GLOBAL_ID . '.draft';
           $build['#cache']['tags'][] = AutoSaveManager::CACHE_TAG;
         }
    +    else {
    +      $build['#attached']['library'][] = 'experience_builder/asset_library.' . AssetLibrary::GLOBAL_ID;
    +    }
     
         $valid_props = $component->getProps() ?? [];
     
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Could you give this a try? 😇

  • 🇳🇱Netherlands balintbrews Amsterdam, NL

    It works! 🙂 Assigning to Ted for code review.

  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Still needs tests.

  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    The changes here are trivial. So, self-RTBC'ing.

  • Pipeline finished with Skipped
    about 1 month ago
    #502669
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺
    • wim leers committed 0383fe2b on 0.x
      Issue #3525374 by wim leers, balintbrews: Include compiled CSS from...
  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    .

    (d.o issue status rendering is wrong due to #9 and #10 racing)

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

Production build 0.71.5 2024