Overview
If I have a code component with CSS using a variable defined in global CSS, it isn't available. That's because the AssetLibrary CSS library is one o the last stylesheets added.
Proposed resolution
Make all code component libraries depend on the global AssetLibrary's asset library.
User interface changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #4 | image (2).png | 13.71 KB | libbna |
| #4 | image (1).png | 25.06 KB | libbna |
Issue fork experience_builder-3529677
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
libbna commentedGiving it a try on this.
Comment #3
libbna commentedHi @mglaman,
Could you please share the steps to reproduce this issue?
Below are the steps I followed—please let me know if they are correct or if I’m missing something. The CSS appears to be getting applied, but I’m not sure if I’m approaching it the right way. I’d appreciate your guidance on this.
Thanks!
Comment #4
libbna commentedI again tried but couldn't reproduce the issue. In the last comment I forgot to attach the screenshot so I have attached it now!
Comment #5
wim leersThe problem/challenge here is that it's possible that both the code component (
JavaScriptComponentconfig entity)'s and theAssetLibraryconfig entity (only a single one allowed for now, with the IDglobal) can have a draft (auto-saved) version.So dependencies don't quite end up working, because it depends on the context which should be loaded:
which is then used by
\Drupal\experience_builder\Entity\JavaScriptComponent::getCssLibrary():isPreviewwill be true when editing inside XB, not outside of it, and an auto-save entry can (dis)appear at any time. Similar thing for the global asset library:—
\Drupal\experience_builder\Hook\ComponentSourceHooks::pageAttachments()Comment #6
wim leersComment #8
libbna commentedComment #9
wim leersHowever … the work I did on #3508922: Regression after #3500386: import map scope mismatch when previewed code component's JS is a 307 due to it not having an auto-save/draft gave me an idea:
ApiConfigAutoSaveControllers::getCss()andApiConfigAutoSaveControllers::getJs()do the disambiguation: return auto-save data if it exists, return stored/live data if notCan you test this, @mglaman? Quick manual test suggests it works fine. 😊
Comment #10
larowlanJust a couple of minor nits about the use of the verbose
matchfor booleansComment #11
wim leersAll tests are passing, the tests are pretty detailed, manual testing reveals no regressions and … this really does simplify the "asset loading" logic of config-defined CSS/JS a lot. It makes all this much easier to reason about.
Only +1s from @larowlan, so going ahead and RTBC'ing even ahead of @mglaman's manual testing.
Comment #12
wim leersComment #14
wim leers