Problem/Motivation

When generating stories, parameter.server.url is automatically set in each stories file based on the internal:/storybook/stories/render URI. Due to Storybook's rules of parameter inheritance this makes it impossible to set the server url to a different environment other than the one in which the stories file was generated.

By allowing the server url to be set as a global parameter, static Storybook builds can be generated for different environments without having to regenerate a specific set of stories.json files each time. This is useful when deploying a Storybook build to static server such as Pantheon's multi-dev environments.

API changes

This adds a new CLI option to the storybook:generate-stories command that will omit the server url parameter from the generated stories allowing it to be set globally in Storybook.

Usage:

drush storybook:generate-all-stories --omit-server-url

In you will then need to set the server url globally in .storybook/preview.js. For example

const preview = {
  ...
    parameters: {
    server: {
      url: process.env.STORYBOOK_SERVER_URL || 'http://my-local-site.lndo.site/storybook/stories/render',
    },
  ...
}

Requires an update to twig-storybook

Data model changes

Issue fork storybook-3424336

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

pixelwhip created an issue. See original summary.

pixelwhip’s picture

Issue summary: View changes
pixelwhip’s picture

Issue summary: View changes
markie’s picture

Curious.. Why not have a `--server-url` switch instead of `--omit-url`, this way build commands could utilize the functionality. And if switch is not used, default.. Just a thought

drush storybook:generate-all-stories --server-url=https://spiffy.url
pixelwhip’s picture

The `--server-url` is already possible with Drush's `--uri` option. In my case, I need to omit the server url from the stories.json file completely so it can be set in the Storybook configuration.

Example:

drush storybook:generate-all-stories --uri=https://spiffy.url

I discovered this recently when setting Storybook up with Tugboat for the Prototype theme. If you don't have the URI configured for Drush, the URL will end up being `http://default*`

pixelwhip’s picture

Status: Active » Needs review
bander2’s picture

Looks like this does not omit the server url, it sets it to an empty string:

"parameters":{"server":{"url":""}}

Which gives me this error:

URL constructor: /<my-server-id> is not a valid URL.

When I manually delete the parameters section above, it works. So I think url needs to be completely omitted.

brayn7’s picture

@bander2 You have to patch the vendor dependency too.

            "e0ipso/twig-storybook": {
                "Feature allow global server url": "https://github.com/e0ipso/twig-storybook/pull/11.patch"
            }

This works great for me.

bander2’s picture

brayn7, that works. Thanks!

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

bradwade’s picture

I tested the following patches on our website and they are working as expected... json stories are generated without a server URL parameter when `--omit-server-url` flag is provided .

"drupal/storybook": {
  "Issue #3424336: Fix ...": "patches/contrib/storybook-issue-3424336-mr-6.patch",
},
"e0ipso/twig-storybook": {
  "Issue #10 Allow the server url to be set as a global parameter": "patches/contrib/twig-storybook-issue-10-pr-11.patch"
}

Since it seems multiple people have successfully tested, is the next step to create a new tag for e0ipso/twig-storybook which contains the already-merged-to-main issue 10 (https://github.com/e0ipso/twig-storybook/pull/11), then bump the version requirement here in composer.json so that new tag is pulled in as a dependency... then merge this MR 6?

Sorry MR9 is showing in this thread. That was for another issue.

e0ipso’s picture

Status: Needs review » Fixed

Thank you everyone for your contribution!

e0ipso’s picture

I had to resolve merge conflicts on the README.md

  • e0ipso committed cd8aaa62 on 1.x authored by pixelwhip
    Issue #3424336 by pixelwhip, bradwade, e0ipso, bander2, brayn7, markie:...

Status: Fixed » Closed (fixed)

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