Components sourced from JsComponent are missing source component cacheable metadata

Created on 1 May 2025, 11 days ago

Overview

When modifying a JS Component and then publishing the changes, cache invalidation doesn't happen for pages which use that component. When logged in it may appear changed but the cache is still in page_cache or reverse proxies

Proposed resolution

\Drupal\experience_builder\Plugin\ExperienceBuilder\ComponentSource\JsComponent::renderComponent needs to add the JS component cacheable metadata to the build. This is already done in \Drupal\experience_builder\Plugin\ExperienceBuilder\ComponentSource\BlockComponent::renderComponent for the overrides JS component.

User interface changes

None

πŸ› Bug report
Status

Active

Version

0.0

Component

Component sources

Created by

πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

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

Merge Requests

Comments & Activities

  • Issue created by @mglaman
  • πŸ‡ΊπŸ‡ΈUnited States mglaman WI, USA

    Needs tests. Normally I write a kernel test which implements CacheTagsInvalidatorInterface to track invalidations, so we could have a Page using a JS component. Then re-save the JS component and validate the cache tag invalidated.

    But I suppose we could just render a page and verify the JS component cache tags are present now.

  • Pipeline finished with Failed
    11 days ago
    Total: 566s
    #486643
  • First commit to issue fork.
  • πŸ‡ΊπŸ‡ΈUnited States phenaproxima Massachusetts

    Added a basic set of assertions to prove that the JS component's cache metadata is added to the render array, but I'm leaving the "needs tests" tag here because we should still have coverage to prove that a nested component's cache tags are added.

  • Pipeline finished with Failed
    11 days ago
    Total: 767s
    #486891
  • πŸ‡¦πŸ‡ΊAustralia larowlan πŸ‡¦πŸ‡ΊπŸ.au GMT+10
  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Great find, @mglaman! πŸ™

    Based on the issue summary, I expected our ComponentTreeHydratedTest to need updating. I'm pleased to see it does πŸ‘

    ✨ Create a ComponentSource plugin for JS components Active is the issue that added the JsComponent source, and it did add the following expectation:

                                    'tags' => ['config:experience_builder.component.js.my-cta'],
    

    I just checked that issue + its MR for the substring "cach" and found no discussion about this. So we missed that in that >1000 net new LoC MR. 😞

    Then, as @larowlan points out on the MR, πŸ“Œ Code Components should render with their auto-saved state(if any) when rendered in the XB UI Active subsequently forgot to add \Drupal\experience_builder\AutoSave\AutoSaveManager::CACHE_TAG when appropriate.

    And finally:

    we should still have coverage to prove that a nested component's cache tags are added

    Indeed, this is necessary since a few weeks; it's something we missed in ✨ Store and calculate dependencies in `JavaScriptComponent` Active . It'd have been easier to spot if #3498889 didn't miss it originally.

    Conclusion

    We've been treating JS components ("code components") the same as other components sourced from simpler sources, but these are much more complex: they're assembled from 1 (now possibly multiple) config entities, and when rendered with isPreview: TRUE, they can be even be assembled from auto-save data (which could be changing any second)!

    However, it was the reliance on separate CSS+JS URLs for auto-saved JS components that made this actually work fine : all CSS/JS changes would be reflected correctly (and yes, those use Cache-Control: private, no-store). πŸ‘ˆ This worked fine, and is what all of us were dead-focused on πŸ˜‡

    This issue is specifically reporting that the cacheability metadata being missing is a problem when using the live (non-auto-saved) versions of code components, i.e. when browsing as an end user a live site that is powered by (changed) JS components! That's a crucial thing we haven't been spending enough brain cycles on πŸ˜…πŸ™ˆ

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    Retitling for clarity.

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    FYI: 🌱 [META] Production-ready ComponentSource plugins Active 's lists β†’ a whole sequence of kinda similar "now make it work correctly+well for live sites" remaining issues for the BlockComponent source!

  • πŸ‡§πŸ‡ͺBelgium wim leers Ghent πŸ‡§πŸ‡ͺπŸ‡ͺπŸ‡Ί

    This is well on its way β€” and a whole range of tests fail thanks to recent test infrastructure additions, which makes sense: \Drupal\Tests\experience_builder\Kernel\Plugin\ExperienceBuilder\ComponentSource\JsComponentTest::testRenderJsComponent()'s current expectations expect no cache tags; this changes that! πŸ₯³

  • Pipeline finished with Failed
    3 days ago
    Total: 525s
    #492933
  • Pipeline finished with Failed
    3 days ago
    Total: 546s
    #493066
Production build 0.71.5 2024