Storybook: Hot reloading doesn't add IntlProvider decorator after changes

Created on 14 Sep 2017  路  4Comments  路  Source: storybookjs/storybook

This is my .storybook/confg.js

import { addDecorator, configure } from '@storybook/react';
import { IntlProvider } from 'react-intl';
// ...
addDecorator(story => (
  <IntlProvider locale={DEFAULT_LOCALE} key={DEFAULT_LOCALE} messages={DEFAULT_MESSAGES}>
      { story() }
  </IntlProvider>
));

// ... loadStories, etc

configure(loadStories, module);

After each change in components code, hot reloading module reload iframe in the storybook and I get an error instead of component:

[React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry.
Invariant Violation: [React Intl] Could not find required `intl` object. <IntlProvider> needs to exist in the component ancestry.
    at invariant (http://localhost:6006/static/preview.bundle.js:23458:15)
    at invariantIntlContext (http://localhost:6006/static/preview.bundle.js:72412:54)
    at new InjectIntl (http://localhost:6006/static/preview.bundle.js:72485:13)
    at http://localhost:6006/static/preview.bundle.js:56978:18
    at measureLifeCyclePerf (http://localhost:6006/static/preview.bundle.js:56758:12)
    at ReactCompositeComponentWrapper._constructComponentWithoutOwner (http://localhost:6006/static/preview.bundle.js:56977:16)
    at ReactCompositeComponentWrapper._constructComponent (http://localhost:6006/static/preview.bundle.js:56963:21)
    at ReactCompositeComponentWrapper.mountComponent (http://localhost:6006/static/preview.bundle.js:56871:21)
    at Object.mountComponent (http://localhost:6006/static/preview.bundle.js:63530:35)
    at ReactDOMComponent.mountChildren (http://localhost:6006/static/preview.bundle.js:62882:44)

But after reloading the whole page, all works normally.

compatibility with other tools decorators has workaround inactive

Most helpful comment

@Kein1945 It's a known issue with global decorators

As a workaround put your decorator inside configure:

function loadStories() {
  addDecorator(story => (
    <IntlProvider locale={DEFAULT_LOCALE} key={DEFAULT_LOCALE} messages=
  {DEFAULT_MESSAGES}>
        { story() }
    </IntlProvider>
  ));
}

configure(loadStories, module);

All 4 comments

@Kein1945 It's a known issue with global decorators

As a workaround put your decorator inside configure:

function loadStories() {
  addDecorator(story => (
    <IntlProvider locale={DEFAULT_LOCALE} key={DEFAULT_LOCALE} messages=
  {DEFAULT_MESSAGES}>
        { story() }
    </IntlProvider>
  ));
}

configure(loadStories, module);

That works for me. Thank you for your quick reply!

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. We do try to do some housekeeping every once in a while so inactive issues will get closed after 90 days. Thanks!

Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dnlsandiego picture dnlsandiego  路  3Comments

xogeny picture xogeny  路  3Comments

levithomason picture levithomason  路  3Comments

shilman picture shilman  路  3Comments

ZigGreen picture ZigGreen  路  3Comments