Fix Storybook issues with Drupal 10.2.0 after cl_server 2.0.0-beta5 and @lullabot/storybook-drupal-addon 2.0.6

Created on 3 January 2024, 6 months ago
Updated 16 April 2024, 2 months ago

Problem/Motivation

Facing issues only with Sotrybook after updates for :

  • Drupal 10.2.0
  • cl_server 2.0.0-beta5
  • @lullabot/storybook-drupal-addon 2.0.6
Response body: The website encountered an unexpected error. Try again later.<br><br><em class="placeholder">Twig\Error\RuntimeError</em>: The merge filter only works with arrays or &quot;Traversable&quot;, got &quot;string&quot; for argument 2. in <em class="placeholder">twig_array_merge()</em> 
the use of array_merge in Drupal is changing!!

Drupal 10 is using "twig/twig": "^3.5.0",
twig/twig 3.8.0 is out and in use for now
But 3.9.0 will be out and it will have deprecations.

https://github.com/twigphp/Twig/blob/v3.5.1/src/Extension/CoreExtension....

/**
 * Merges an array with another one.
 *
 *  {% set items = { 'apple': 'fruit', 'orange': 'fruit' } %}
 *
 *  {% set items = items|merge({ 'peugeot': 'car' }) %}
 *
 *  {# items now contains { 'apple': 'fruit', 'orange': 'fruit', 'peugeot': 'car' } #}
 *
 * @param array|\Traversable $arr1 An array
 * @param array|\Traversable $arr2 An array
 *
 * @return array The merged array
 */
function twig_array_merge($arr1, $arr2)
{
    if (!twig_test_iterable($arr1)) {
        throw new RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as first argument.', \gettype($arr1)));
    }

    if (!twig_test_iterable($arr2)) {
        throw new RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" as second argument.', \gettype($arr2)));
    }

    return array_merge(twig_to_array($arr1), twig_to_array($arr2));
}

Storybook + CL Server having issues passing values and doing twig merge array
Move functions for CoreExtension

fabpot committed 3 weeks ago

https://github.com/twigphp/Twig/blob/v3.8.0/src/Extension/CoreExtension....

function twig_array_merge(...$arrays)
{
    $result = [];

    foreach ($arrays as $argNumber => $array) {
        if (!is_iterable($array)) {
            throw new RuntimeError(sprintf('The merge filter only works with arrays or "Traversable", got "%s" for argument %d.', \gettype($array), $argNumber + 1));
        }

        $result = array_merge($result, twig_to_array($array));
    }

    return $result;
}

Proposed resolution

  • Add Storybook's controls for all Utility Classes and Attributes : for all Stories
  • Remove passing of empty array or empty objects from the Storybook story to to SDC by CL Server

Remaining tasks

  • ✅ File an issue about this project
  • ✅ Addition/Change/Update/Fix to this project
  • ✅ Testing to ensure no regression
  • ➖ Automated unit/functional testing coverage
  • ➖ Developer Documentation support on feature change/addition
  • ➖ User Guide Documentation support on feature change/addition
  • ➖ UX/UI designer responsibilities
  • ✅ Accessibility and Readability
  • ✅ Code review from 1 Varbase core team member
  • ✅ Full testing and approval
  • ✅ Credit contributors
  • ✅ Review with the product owner
  • ✅ Update Release Notes and Update Helper on new feature change/addition
  • ✅ Release varbase-10.0.0-rc2 , varbase_components-2.0.0-alpha30

Varbase update type

  • ✅ No Update
  • ➖ Optional Update
  • ➖ Forced Update
  • ➖ Forced Update if Unchanged

User interface changes

  • N/A

API changes

  • N/A

Data model changes

  • N/A

Release notes snippet

  • Issue #3412132 : Fixed Storybook issues with Drupal 10.2.0 after cl_server 2.0.0-beta5 and @lullabot/storybook-drupal-addon 2.0.6
🐛 Bug report
Status

Fixed

Version

2.0

Component

Code

Created by

🇯🇴Jordan Rajab Natshah Jordan

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

Comments & Activities

Production build 0.69.0 2024