Testing Storybook sdc_examples: my-banner Storybook is blank page

Created on 1 December 2024, 3 months ago

Problem/Motivation

I am replicating step by step the tutorial
Drupal & Storybook: Working with Single Directory Components
https://video.mateuaguilo.com/w/cKsHjwRLvW5bK2TawNrDdN

My story is blank on Storybook
I'm not getting any CORS issues in the Inspect

my-banner.stories.json generated with ddev drush storybook:generate-all-stories
Formatted for readability

{
  "title": "SDC\/Examples\/My Banner",
  "parameters": {
    "server": {
      "url": "https:\/\/sb-demo.ddev.site\/storybook\/stories\/render"
    }
  },
  "stories": [
    {
      "name": "1. Default",
      "args": {
        "heading": "Join us at the conference",
        "ctaText": "Click me!",
        "ctaHref": "https:\/\/www.drupal.org",
        "ctaTarget": "_blank"
      },
      "parameters": {
        "server": {
          "id": "eyJwYXRoIjoibW9kdWxlc1wvY29udHJpYlwvc2RjX2V4YW1wbGVzXC9jb21wb25lbnRzXC9teS1iYW5uZXJcL215LWJhbm5lci5zdG9yaWVzLnR3aWciLCJpZCI6ImRlZmF1bHQifQ%3D%3D",
          
        }
      }
    }
  ]
}

my-banner.stories.twig

{% stories my_banner with {
     title: 'SDC/Examples/My Banner',
      } %}
{% story default with {
    name : '1. Default',
    args : {
        heading: 'Join us at the conference'|t,
        ctaText: 'Click me!'|t,
        ctaHref: 'https://www.drupal.org',
        ctaTarget: '_blank',

    }
} %}

  <h2> this can include some other markup</h2>
  <p> We are no longuer coupling stories with components !</p>
  <div style="background:#0a6eb4" >
      {{ include('sdc_examples:my-banner',{
        heading,
        ctaText,
        ctaHref,
        ctaTarget,
    })  }}
  </div>

    {% endstory %}
      {% endstories %}

Steps to reproduce

With
SDC Component modules
https://www.drupal.org/project/sdc_examples/releases/1.x-dev
And
Module storybook 1.0.2
Storybook 8.4.6 for server-webpack5
Working with Single Directory Components

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

💬 Support request
Status

Active

Version

1.0

Component

Storybook

Created by

🇺🇸United States adanbouzoua

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

Comments & Activities

  • Issue created by @adanbouzoua
  • 🇮🇹Italy soundvox

    You can try to remove the comma at the end of the "parameters->server->id" in the json file

  • 🇫🇮Finland YevKo Espoo

    I confirm that neither including or embedding of the twig component doesn't work either. Only HTML in the story works.
    In the iframe, a

    is empty with this story, for example:

      {% story secondary with { name: "Secondary", args: { "button_content": "Secondary", "button_modifiers": ["secondary"] } } %}
        {% include 'button.html.twig' %}
      {% endstory %}

    The included template is located in the same directory as the story.

  • 🇮🇹Italy soundvox

    @yevko Have you tried to include the Twig like the code below?

    
     {% story secondary with { name: "Secondary", args: { "button_content": "Secondary", "button_modifiers": ["secondary"] } } %}
         
          {{ include("theme_name:button", { 
          "button_content": "button_content",
          "button_modifiers": "button_modifiers",
        }) }}
      
      {% endstory %}
    
    

    "button" is the name of the component.
    It should include the file button.twig which should be in the same component folder called button.

  • 🇺🇸United States klu

    @adanbouzoua: Are you getting any output when you visit the site at `/storybook/stories/render`?

    Example based on your generated ID:

    https://yoursite.localhost/storybook/stories/render/eyJwYXRoIjoibW9kdWxl...

    In my case, I was getting a blank page at https://mysite.localhost:6006 before I installed/enabled sdc_examples, i.e.:

    $ ddev composer require 'drupal/sdc_examples:1.x-dev@dev'
    $ ddev drush en sdc_examples -y 
    

    I'm new to SDC and Storybook and the two video tutorials were quite helpful, thanks to the maintainers! I'm using ddev following the additional ddev storybook setup at https://git.drupalcode.org/project/storybook/-/blob/1.x/README.md?ref_ty...

    My troubleshooting steps:

    1. Launch ddev and storybook

    $ ddev restart
    $ ddev yarn storybook --no-open
    

    2. Get the storybook URL from ddev describe

    $ ddev describe
    storybook    https://mysite.localhost:6006
    

    3. Generate the json file using `ddev drush storybook:generate-stories path/to/my-story.stories.twig` or `ddev drush storybook:generate-all-stories`

    $ ddev drush storybook:generate-all-stories
     [success] JSON file generated for modules/composer/sdc_examples/components/my-banner/my-banner.stories.json.
    

    4. Try visiting https://mysite.localhost/storybook/stories/render/[hash] where [hash] is the "id" in my-banner.stories.json

    5. In my-banner.stories.twig, when testing I temporarily removed the include and just added some basic HTML markup, e.g., the hardcoded-demo.stories.twig example.

    In my case, the hardcoded example was working (both visiting https://mysite.localhost/storybook/stories/render/[hash] and
    https://mysite.localhost:6006, which is when I realized that I had not reinstalled/enabled sdc_examples after rebuilding my site, and the my-banner.stories.twig is including the my-banner component from sdc_examples:

        {{ include('sdc_examples:my-banner', {
            heading,
            ctaText,
            ctaHref,
            ctaTarget,
          }) }}

    @yevko: I'm able to include/embed SDC components, e.g., `{% include('sdc_examples:my-button') %}` but as soundvox indicated, it looks like you have to use either an SDC template or a Twig template that is registered with Drupal . If you're using an existing Drupal theme, it may already be registered and you can use the appropriate namespace, e.g., `{% include '@mytheme/path/to/mytemplate.twig' %}`.

Production build 0.71.5 2024