Improve accuracy of styling in preview: attach default theme's asset libraries

Created on 7 August 2024, 4 months ago
Updated 19 August 2024, 3 months ago

Overview

When I visit /node/1 on my site I can see the saved XB layout rendered. I can see that the Hero SDC is rendered and inside that the heading saying "hello, world!" is displayed with a font-family of "metropolis",sans-serif"

However, when I view that same layout in the preview iFrame at /xb/node/1 the same heading is displayed with the font-family of "Helvetica, Arial, sans-serif"

Another example of the issue is that when viewing the site the <body> has a margin of 0px but in the preview iFrame it has a margin of 8px (which is the browser default)

Proposed resolution

I believe the issue is because the HTML returned when calling /api/preview/node/1 does not have all the correct CSS libraries attached (font-family: "metropolis",sans-serif"; is coming from base.css). I think attaching the libraries should happen in src/Controller/SdcController.php but I don't know how specifically to do it.

User interface changes

๐Ÿ› Bug report
Status

Closed: duplicate

Component

Page builder

Created by

๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom jessebaker

Live updates comments and jobs are added and updated live.
  • Novice

    It would make a good project for someone who is new to the Drupal contribution process. It's preferred over Newbie.

Sign in to follow issues

Comments & Activities

  • Issue created by @jessebaker
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Where is this metropolis coming from? I can find base.css at

    ui/node_modules/@radix-ui/themes/src/styles/tokens/base.css
    

    โ€ฆ but I cannot find metropolis anywhere in there.

    Aha, it's core/themes/olivero/css/base/fonts.pcss.css that does this. This is part of the olivero/global-styling asset library. Which is declared as the sole global asset library in oliver.info.yml ๐Ÿ‘

    ๐Ÿ‘‡

    That asset library must be attached in \Drupal\experience_builder\Controller\SdcController::preview().

    (That'll also allow reverting most of ๐Ÿ› First `preview` request fails to generate a response for empty layout Needs review and will hence simplify that controller ๐Ÿ‘)

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    This is a back-end issue, not a front-end one!

  • First commit to issue fork.
  • @omkar-pd opened merge request.
  • Status changed to Needs work 4 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia omkar-pd

    Attached the default theme CSS assets. One test is failing :(

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Great start! ๐Ÿ‘๐Ÿ˜„

    Fortunately, I think this can be even simpler ๐Ÿ˜Š See review on the MR!

  • Assigned to omkar-pd
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia omkar-pd
  • Issue was unassigned.
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia omkar-pd

    Addressed feedback in MR.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    One test failed. The failure looks legit:

         AssertionError: expected null to exist
          at Context.eval (webpack://vite-template-redux/../tests/src/Cypress/cypress/e2e/xb-general.cy.js:60:14)
    

    โ€ฆ if we look at line 60, it's this bit:

        // Confirm that the iframe loads the SDC CSS.
        cy.getIframe()
          .its('head').should('not.be.undefined')
          .then((head) => {
            expect(head.querySelector('link[rel="stylesheet"][href*="experience_builder/components/my-hero/my-hero.css"]'))
              .to.exist
          })
    

    You can see that output here: https://git.drupalcode.org/issue/experience_builder-3466571/-/jobs/23766...(failed).png

    ๐Ÿ‘‡

    Either this is detecting a genuine bug, or the test assertion needs to be updated.

  • Assigned to wim leers
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Actually โ€ฆ it works fine locally? ๐Ÿค” Re-running the Cypress E2E CI job.

  • Issue was unassigned.
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    I wonder if a more recent upstream commit changed it. I'll push a change.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Applied my own suggestion to address my review feedback, which also triggers a build against 0.x HEAD, and hopefully now it'll pass ๐Ÿคž

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia omkar-pd

    Recent changes work fine. But getting couple of warnings.

    Warning: Undefined array key "#attached" in Drupal\experience_builder\Controller\SdcController->preview() (line 356 of modules/contrib/experience_builder/src/Controller/SdcController.php).

    Warning: Trying to access array offset on null in Drupal\experience_builder\Controller\SdcController->preview() (line 356 of modules/contrib/experience_builder/src/Controller/SdcController.php).

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    I made it pass tests, but:

    1. one bug is still present, see MR review
    2. it's not using the correct infrastructure yet, see MR review
    3. we should expand the Cypress E2E test coverage

    Good job getting it to this point already, @omkar-pd! ๐Ÿ‘ And thank you! ๐Ÿ˜Š๐Ÿ™

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia omkar-pd

    Thanks @Wim Leers.

    Upon checking the network tab, I see

    The website encountered an unexpected error. Try again later.
    
    Error: Only arrays and Traversables can be unpacked in Drupal\experience_builder\Controller\SdcController->preview() (line 356 of modules/contrib/experience_builder/src/Controller/SdcController.php).
  • Assigned to omkar-pd
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia omkar-pd
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ
  • Issue was unassigned.
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia omkar-pd

    @Wim Leers.

    I've addressed the given feedback.
    Had to add couple of extra lines to fix errors and warnings. Please review.

    Error: Only arrays and Traversables can be unpacked in Drupal\experience_builder\Controller\SdcController->preview() (line 356 of modules/contrib/experience_builder/src/Controller/SdcController.php).
    
    Warning: Undefined array key "#attached" in Drupal\experience_builder\Controller\SdcController->preview() (line 356 of modules/contrib/experience_builder/src/Controller/SdcController.php).
    
    Warning: Trying to access array offset on null in Drupal\experience_builder\Controller\SdcController->preview() (line 356 of modules/contrib/experience_builder/src/Controller/SdcController.php).
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Still needs tests.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Last step: tests.

    All this needs is one extra assertion for an additional CSS file in:

        // Confirm that the iframe loads the SDC CSS.
        cy.getIframe()
          .its('head').should('not.be.undefined')
          .then((head) => {
            expect(head.querySelector('link[rel="stylesheet"][href*="experience_builder/components/my-hero/my-hero.css"]'))
              .to.exist
          })
    

    ๐Ÿ™

  • Status changed to Needs review 3 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia omkar-pd

    Added an assertion for the olivero css file (Don't have much experience writing tests ๐Ÿ˜Š).

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    LGTM!

    Cypress E2E test is failing though โ€ฆ re-testing to see if that's an ephemeral failure.

  • Assigned to jessebaker
  • Status changed to RTBC 3 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Also, I'd like @jessebaker to do the final sign-off on this, given he reported it.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Re-testing once moreโ€ฆ reliability of the Cypress E2E CI job is being improved in ๐Ÿ“Œ Document Cypress test best practices (especially how to write reliable tests) Needs review . ๐Ÿ‘

  • Issue was unassigned.
  • ๐Ÿ‡ฌ๐Ÿ‡งUnited Kingdom jessebaker

    I have merged in 0.x since the MR to harden the Cypress tests was merged in but this is still failing on a test so that needs to be addressed before I can approve/merge this.

  • Status changed to Needs work 3 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ
          cy:command โœ”  its	.head
          cy:command โœ”  assert	expected **<head>** not to be undefined
          cy:command โœ”  assert	expected **undefined** to exist in the DOM
          cy:command โœ˜  assert	expected **null** to exist
    

    That's indeed the updated test coverage ๐Ÿ‘†, so something must be wrong in here:

        cy.getIframe()
          .its('head').should('not.be.undefined')
          .then((head) => {
            expect(head.querySelector('link[rel="stylesheet"][href*="experience_builder/components/my-hero/my-hero.css"]'))
              .to.exist;
            expect(head.querySelector('link[rel="stylesheet"][href*="/core/themes/olivero/css/base/base.css"]'))
              .to.exist;
          })
    
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia omkar-pd

    @Wim Leers

    I see the same test failing for a super simple MR.
    https://www.drupal.org/project/experience_builder/issues/3467818 ๐Ÿ“Œ Update XB to match the latest Drupal 11 phpcs.xml.dist- 2024-08-13 Needs review

  • First commit to issue fork.
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States bnjmnm Ann Arbor, MI

    I Improved the test result output for this to state what is being looked for in <head> and, on failure, what is actually in <head> and it doesn't look like the base.css is in there.

     AssertionError: Tried to find [href*="/core/themes/olivero/css/base/base.css"] in <head> <link rel="stylesheet" media="all" href="/web/core/../modules/custom/experience_builder/components/my-hero/my-hero.css?si5uut">
    <style>.preview-dragging .sortable-list{
      min-height: 2rem;
    }
    .preview-dragging .sortable-list:empty{
      background: #fff;
    }
    .slot-container {
      display: flex;
      > .sortable-item {
        width: 100%;
      }
    }
    .sortable-list:empty {
      min-height: 1.5rem;
      border: 2px dashed #ccc;
      position: relative;
    }
    .sortable-list:empty:after {
      content: 'Slot';
      top: 0;
      right: 0;
      text-align: right;
      position: absolute;
    }
    .sortable-item {
      cursor: grab;
    }
    .preview-dragging *,
    .preview-dragging {
      cursor: grabbing;
    }
    .sortable-ghost {
      opacity: 0.5;
      padding: 0;
      height: 2rem;
      max-height: 2rem;
      width: 100%;
      margin: 0;
      clear: none;
      position: relative;
      background: linear-gradient(135deg, #DDD 12.50%, transparent 12.50%, transparent 50%, #DDD 50%, #DDD 62.50%, transparent 62.50%, transparent 100%) center / 5.66px 5.66px;
      outline: 1px solid #ccc;
      box-shadow: none;
      flex-grow: 1;
      overflow: hidden;
    }
    .sortable-ghost * {
      visibility: hidden;
    }
    </style>
    : expected null to exist
  • Status changed to Needs review 3 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia omkar-pd

    Fixed tests by installing and setting Olivero as the default theme in XBTestSetup.php.
    Back to Needs Review.

  • Status changed to Needs work 3 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    There's a conflict with ๐Ÿ› Account for GitlabCI intermittent path differences in SDC CSS test Fixed โ€” should be easy to resolve :)

  • Status changed to Needs review 3 months ago
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia omkar-pd

    Resolved Conflicts.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Not yet passing tests. Re-running.

  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    I showed in #18 that this is not yet quite yielding the kind of preview we'd like.

    Yet, this issue still is a step in the right direction, so it should land ๐Ÿ‘

    To make the preview actually good enough, we need design and research. Created ๐Ÿ“Œ [needs design] [RESEARCH] Previewed component tree for Content Creator does not match the result for Visitor Active for that.

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia omkar-pd

    Checking the failed pipelines.

    Timed out retrying after 4000ms: Expected to find element: button[aria-label="Add section"], but never found it.
    

    If I run the same tests with Claro as a default theme then they pass without error but error occurs on Olivero. ๐Ÿ˜•

  • Status changed to Closed: duplicate 3 months ago
  • ๐Ÿ‡ง๐Ÿ‡ชBelgium wim leers Ghent ๐Ÿ‡ง๐Ÿ‡ช๐Ÿ‡ช๐Ÿ‡บ

    Due to the scope clarification by @lauriii over at #3468106-4: Render component tree inside the default theme, as a regular page โ†’ , this issue has become pointless to finish ๐Ÿ™ˆ Sorry. I'll credit y'all though!

  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia omkar-pd

    ๐Ÿ‘๐Ÿ‘

Production build 0.71.5 2024