Overview

#3486236: Add HTML comments to twig output to attempt to allow in-place editing added HTML comments to Twig output, to enable certain XB capabilities without interfering with CSS.

#3491021: Leverage HTML comment annotations, remove wrapping div elements expands on this.

But they result in output like

<!-- xb-start-acf26597-72a4-4833-9cef-97250646576f -->

<div id="block-acf26597-72a4-4833-9cef-97250646576f" class="site-branding block block-system block-system-branding-block">
  
    
    <div class="site-branding__inner">
              <div class="site-branding__text">
        <div class="site-branding__name">
          <a href="/" title="Home" rel="home">XB</a>
        </div>
      </div>
      </div>
</div>
<!-- xb-end-acf26597-72a4-4833-9cef-97250646576f -->

Even for the anonymous user!

+ slot-conveying comments:

<!-- xb-slot-start-uuid-level-2/the_body -->
…

+ prop-conveying comments:

<h1 style="font-size: 3em; margin: 0.5em 0; color: #333;"><!-- xb-prop-start-uuid-level-3/heading -->Hello, from slot level 3!<!-- xb-prop-end-uuid-level-3/heading --></h1>

(Those last 2 are powered by \Drupal\experience_builder\Extension\XbPropVisitor.)

Proposed resolution

Make XbTwigExtension only take effect in the context of rendering an XB preview, i.e. when executed by \Drupal\experience_builder\Render\MainContent\XBPreviewRenderer

User interface changes

Command icon 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

wim leers created an issue. See original summary.

wim leers’s picture

Issue summary: View changes

… 

wim leers’s picture

Priority: Major » Normal

This should be feasible to do at any time, actually; it's not urgent because AFAICT it's low-risk.

roshni upadhyay’s picture

Assigned: Unassigned » roshni upadhyay
wim leers’s picture

Component: Page builder » Internal HTTP API
Issue tags: +stable blocker

Thanks, @roshni upadhyay!

roshni upadhyay’s picture

Hi @wim leers, The wrapper comments in the rendered output are being added by both the Component and ComponentTreeHydrated classes. I wanted to check if the XbTwigExtension is actively being used, or if we can directly handle the wrapper comments logic within the Component and ComponentTreeHydrated classes instead.

Could you please guide me on whether we should continue using XbTwigExtension or refactor the logic to manage these comments directly within the respective classes?

lauriii’s picture

Status: Active » Needs review
wim leers’s picture

danielveza made their first commit to this issue’s fork.

danielveza’s picture

Just to keep this one moving along, I've started to update some of the tests, had a lot of failures before, lets see how this run goes

wim leers’s picture

Status: Needs review » Needs work

Well on its way, the test coverage you added is excellent, @danielveza — thanks! 😄

danielveza’s picture

Made some progress on this today, assigning to me to wrap up

wim leers’s picture

Title: Only run XbTwigExtension inside XBPreviewRenderer » No XB-targeted HTML comments on the live site: only run XbTwigExtension inside XBPreviewRenderer

Clarify issue title. Thanks, @danielveza!

wim leers’s picture

wim leers’s picture

Component: Internal HTTP API » Component sources
Issue tags: +Needs tests

This will need test coverage for \Drupal\experience_builder\Plugin\ExperienceBuilder\ComponentSource\SingleDirectoryComponent::renderComponent() with isPreview: true|false, which we de facto have now:

  • \Drupal\Tests\experience_builder\Kernel\Plugin\ExperienceBuilder\ComponentSource\SingleDirectoryComponentTest::testRenderComponentLive() tests with isPreview: TRUE
  • \Drupal\Tests\experience_builder\Kernel\Plugin\ExperienceBuilder\ComponentSource\SingleDirectoryComponentTest::testGetClientSideInfo() tests with isPreview: FALSE
wim leers’s picture

wim leers’s picture

Title: No XB-targeted HTML comments on the live site: only run XbTwigExtension inside XBPreviewRenderer » SDCs should only have get HTML comments injected when `renderComponent(isPreview: TRUE)`
thoward216’s picture

Assigned: Unassigned » thoward216
wim leers’s picture

This MR is not yet updating \Drupal\experience_builder\Extension\XbWrapperNode and friends, but I'd be happy to land the current MR first — it just needs the test expectations to be updated now 🤓

thoward216’s picture

@wimleers - I have pushed changes to the tests, and removed the test that was added "simplest component tree with nesting (Non preview)" as I believe it is now a duplicate of "simplest component tree with nesting" which tests "non preview" and "simplest component tree with nesting in preview" which tests in the preview. Everything looks to now be passing.

As mentioned I'll next need to look at \Drupal\experience_builder\Extension\XbWrapperNode and update to only show the HTML comments when previewing.

wim leers’s picture

Looks like this is on the right track, thanks! 👍

Your test expectation changes revealed a bug in \Drupal\experience_builder\Entity\Pattern::normalizeForClientSide() though, which I posted a one-liner fix for on the MR 😄

wim leers’s picture

thoward216’s picture

Have pushed an update to remove the other HTML comments, unsure if this is the right track or not. Does look like a number of tests are failing though.

thoward216’s picture

Status: Needs work » Needs review
penyaskito’s picture

Assigned: thoward216 » wim leers
Status: Needs review » Reviewed & tested by the community

Reviewed and LGTM. Assigning to Wim for sign-off.

penyaskito’s picture

Assigned: wim leers » thoward216
Status: Reviewed & tested by the community » Needs work

X-posted 😇

wim leers’s picture

wim leers’s picture

thoward216’s picture

Status: Needs work » Needs review
penyaskito’s picture

Status: Needs review » Reviewed & tested by the community

larowlan made their first commit to this issue’s fork.

larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 0.x thanks!

wim leers’s picture

Assigned: thoward216 » Unassigned

Status: Fixed » Closed (fixed)

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