- Issue created by @isholgueras
- π³π±Netherlands balintbrews Amsterdam, NL
I added more details and what I propose as the data shape.
- π§πͺBelgium wim leers Ghent π§πͺπͺπΊ
Note: spend zero seconds on making
pageTitle
work, until π Handle adding page title to content Active is in. Hardcode some string for now. - π§πͺBelgium wim leers Ghent π§πͺπͺπΊ
Added some implementation guidance.
- π³π±Netherlands balintbrews Amsterdam, NL
#3: We need the page title in
drupalSettings.xbData
regardless of that. π Handle adding page title to content Active will enable the page title block to work, but we would like to support building a dynamic code component where users can access the raw page title and add custom markup around it. It was amongst our original goals for β¨ Code Components as Block Overrides, step 1 Active , but we dropped that due to the challenges with page title block. Or maybe what you're saying is that we need π Handle adding page title to content Active even to be able to populate it indrupalSettings.xbData
? π - Merge request !1177Issue #3531249: Populate data in `drupalSettings` to enable simple use cases in dynamic code components β (Merged) created by isholgueras
- π§πͺBelgium wim leers Ghent π§πͺπͺπΊ
Nice work here!
I'm missing three key things:
JavaScriptComponent
config entities should at minimum declare that they depend ondrupalSettings
JavaScriptComponent
config entities should ideally declare that they depend on indrupalSettings
β especially breadcrumbs data, because it massively worsens cacheability- a strategy for avoiding worsened cacheability and scalability (see MR comments for details)
I'm fine with a
@todo
+ stable-blocking follow-up issue to address the dependency information, but shipping a 1.0 like this is a no-go. - πͺπΈSpain isholgueras
There is only one thing left to do. How are the code component going to require that it depends on... breadcrumbs for example?
I still missing how, if I'm creating a code component, I'm going to depend on breadcrumb or pageTitle.
I mean, in the whole process as a user or XB user, I click in Add new, I get the editor and... where I define what features I will require?
I was playing around with a new schema Choice property,
drupalSettings
, similar to ablockOverride
and list there all the options allowing developers to add it to the yaml files, maybe in the future adding them to the UI, but that's very much out of scope here.Any thoughts here?
- π§πͺBelgium wim leers Ghent π§πͺπͺπΊ
- π The current MR is based on the simple on/off presence of
preg_match('/drupalSettings\.xbData/', $component->getJs()
. I agree with the pragmatism until such a time we can use explicitimport
statements. - π While better than when I reviewed it in #8 late last week, it still has too much of a negative impact on cacheability and hence scalability. See my analysis and rough proposal, and my implementation outline. That outline partially works. Next step: debug why
\Drupal\experience_builder\Hook\ComponentSourceHooks::jsSettingsAlter()
is not being called. - π The problem with the absence of explicit import statements for specific subsets of data is that this de facto becomes an API we can not ever evolve nor change. So, I think it should be tweaked slightly, similar to what we did with XB's internal HTTP API at
π
Define API URI naming conventions
Active
: we should version it.
So instead of:
drupalSettings?.xbData?.branding?.homeUrl
it should become
drupalSettings?.xbData?.v0?.branding?.homeUrl
β¦ which will allow for evolvability, backwards compatibility layers, deprecation warnings etc.
- π This currently contains a race condition, because it inspects
::getJs()
, which is the saved JS, not the auto-save JS. This needs to reflect either. In fact, it probably makes sense to ALWAYS load alldrupalSettings.xbData
for draft components, just to avoid race conditions: if I'd adddrupalSettings
while editing the code in the code editor, they wouldn't be populated yet? See π JavaScriptComponent CSS libraries should depend on AssetLibrary libraries Active for inspiration. - π The current MR is based on the simple on/off presence of
- π§πͺBelgium wim leers Ghent π§πͺπͺπΊ
Oh, a crucial bit I forgot:
In Drupal 11, how does the cacheability for `drupalSettings` get associated with the response?
β I
- Settings added in
system_js_settings_build()
are cached and reused - Settings added in
system_js_settings_alter()
are regenerated on every request
β Claude
This is why in the commit I pushed, I used
hook_js_settings_alter()
. XB doesn't create any new problem/challenge then, but just piggybacks on what Drupal core does π - Settings added in
- π§πͺBelgium wim leers Ghent π§πͺπͺπΊ
Paired with @isholgueras to get #12.2 working. Got it working, but not in the way I liked. So I dug deeper. Turns out we're running into a core bug: π `AssetResolver::getJsSettingsAssets()` calls `::getLibrariesToLoad()` with wrong asset type Active . Worked around it in https://git.drupalcode.org/project/experience_builder/-/merge_requests/1... π
Over to @isholgueras to address the remaining feedback β we're on the same page π₯³
-
wim leers β
committed a8956874 on 0.x authored by
isholgueras β
Issue #3531249 by isholgueras, wim leers, balintbrews: Populate data in...
-
wim leers β
committed a8956874 on 0.x authored by
isholgueras β
- πͺπΈSpain isholgueras
After chatting with @balintbrews, the resolution for this issue is not correct.
drupalSettings.xbData
should be in global scope and appear only once. This branch does too much and it has some errors:
- The preview (top right) doesn't work. When users create code, the client is not yet talking to the backend.
- The non-compiled code wont work.The front-end API will consume this settings with methods (not decided yet) like
getPageData()
(for title and breadcrumb) andgetSiteData()
(for base URL and branding). - πΊπΈUnited States effulgentsia
From chatting with @balintbrews, as I understand it there's only two problems with what got merged here:
- π Improve the way to detect if the code component has drupalSettings Active (that issue had already been opened previously, I just now re-titled it).
- π xbData.* libraries aren't reliably attached for use by the preview while editing a code component Active (I just now filed that issue).
Assuming it's only those two problems, let's handle them there, and I'm moving this one back to Fixed.
- π§πͺBelgium wim leers Ghent π§πͺπͺπΊ
FYI: π xbData.* libraries aren't reliably attached for use by the preview while editing a code component Active is green, π Improve the way to detect if the code component has drupalSettings Active is blocked on FE.
Automatically closed - issue fixed for 2 weeks with no activity.