question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

globalTypes does not work properly with Composition

See original GitHub issue

Describe the bug A clear and concise description of what the bug is.

When using composition, the global toolbar options appear, but the default value is not set, when you update the value, the story doesn’t re-render. This situation is slightly improved if you create the globalType in the global storybook preview.js file, as it sets the default value, and will update the global value in the url.

Checking the Console Logs, I see:

received globals from a non-local ref. This is not currently supported.

To Reproduce Please create a reproduction by running npx sb@next repro and following the instructions. Read our documentation to learn more about creating reproductions. Paste your repository and deployed reproduction here. We prioritize issues with reproductions over those without.

  1. Create a Core Storybook, and a Composition Storybook
  2. Define in preview.js in composition storybook.
export const globalTypes = {
  locale: {
    name: 'locale',
    description: 'Locale',
    defaultValue: 'en-NZ',
    toolbar: {
      icon: 'globe',
      items: [
        { value: 'keys', title: 'keys' },
        { value: 'en-NZ', title: 'en-NZ' },
        { value: 'zh-CN', title: 'zh-CN' },
        { value: 'ru-RU', title: 'ru-RU' },
      ],
    },
  },
};
  1. Define a Story that uses globals:
const Story = (args, ctx) => {
  const locale = ctx.globals.locale;
  return <p>{locale}</p>;
};
  1. Use the toolbar to update the value, notice it doesn’t update the story, and it doesn’t update the url, and it doesn’t even set the toolbar highlight.
  2. Define in preview.js in core storybook.
export const globalTypes = {
  locale: {
    name: 'locale',
    description: 'Locale',
    defaultValue: 'en-NZ',
  },
};
  1. Notice that now the toolbar now highlights, and the url updates, but the story does not reload.

System Please paste the results of npx sb@next info here.

npm: 7.15.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.22000.1.0), Chromium (92.0.902.67)
  npmPackages:
    @storybook/addon-essentials: ^6.3.6 => 6.3.6
    @storybook/addon-links: ^6.3.6 => 6.3.6    @storybook/react: ^6.3.6 => 6.3.6

Additional context Add any other context about the problem here.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:7
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
tmeasdaycommented, Jul 20, 2022

Perhaps there is something sensible we can do in the case that a set of global types is identical in both the composing and composed storybook? We might not need to address the fullblown problem of what happens when they are different in that case?

1reaction
WilliamABradleycommented, Nov 1, 2021

So I think what is missing is some method of synchronising the global state between the composed and host storybook. The only way to synchronise them at the moment is to refresh the page.

Read more comments on GitHub >

github_iconTop Results From Across the Web

6 Ways To Configure Global Styles for Storybook
For every story, selecting the Docs tab, we can verify that the markdown page is not impacted by story styling. Well, we put...
Read more >
Configure Storybook
Configure Storybook. Storybook is configured via a folder called .storybook , which contains various configuration files. Note that you can change the folder ......
Read more >
Add global properties to Vue 3 using TypeScript
The prototype approach does not work with TypeScript. I found an example that I converted into this code as config.d.ts import Vue from...
Read more >
A Decentralized Analysis of Multiparty Protocols
An elusive problem for MPST is to ensure both protocol ... Routers are synthesized from global types, and do not change the behavior...
Read more >
reading a xml schema in schema editor - webMethods
hI! i have a simple problem whose solution i m not ableto find in tamino ... schema composition (include and import) - global...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found