Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@storybook/vue not returning template string for a custom decorator in SB 5.0 #6112

Closed
mbellary-chwy opened this issue Mar 15, 2019 · 6 comments

Comments

@mbellary-chwy
Copy link
Contributor

Describe the bug
@storybook/vue not returning template string for a custom decorator in SB 5.0

To Reproduce

For Example:

storiesOf('Accordion', module)
  .addDecorator(withStaticTemplate)
  .add('Default', () => ({
    components: {
      Accordion
    },
    template: `
    <accordion>
      <template slot="accordion-item-1-title">Accordion 1</template>
      <template slot="accordion-item-1">
        <ul>
          <li>Content 1</li>
          <li>Content 1</li>
          <li>Content 1</li>
        </ul>
      </template>
      <template slot="accordion-item-2-title">Accordion 2</template>
      <template slot="accordion-item-2">
        <ul>
          <li>Content 2</li>
          <li>Content 2</li>
          <li>Content 2</li>
        </ul>
      </template>
    </accordion>
    `
  }));

For the above story, in SB4 i have a custom decorator withStaticTemplate in which i was accessing my story template(not rendered one).

export default story => {
  const StoryComponent = story();
  return {
    data() {
      return {
        templateString: story().template
      };
    },
    components: { StoryComponent },
    template: `
      ...
    `
  };
};

The same above custom decorator started failing in SB5.
When debugged i see in @storybook/vue/src/client/preview/index.js, template is being returned if the story is only string type:

if (typeof story === 'string') {
  story = { template: story };
}

Could someone please help me how can i get the story template in any custom decorator.

Expected behavior
Template should be returned all the time irrespective of story type

@backbone87
Copy link
Contributor

The vue handling was changed in the alpha-only 4.2 (and now official in SB5).

Every return value of story functions or decorators are normalized with Vue.extend (that happens a few lines down from the location you found with the string normalization). So you actually get a typeof Vue back (in TS terms). The original options are now available at: story.options (This is default Vue mechanic).

@stale
Copy link

stale bot commented Apr 6, 2019

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. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 30 days. Thanks!

@stale stale bot added the inactive label Apr 6, 2019
@shilman
Copy link
Member

shilman commented Apr 7, 2019

@backbone87 Can we close this now?

@stale stale bot removed the inactive label Apr 7, 2019
@backbone87
Copy link
Contributor

yeah i dont think we can do anything here. the BC breaks in @storybook/vue for v5 could be documented better, but then again the pre sb5 vue integration was fragile anyway

@shilman
Copy link
Member

shilman commented Apr 7, 2019

@backbone87 Would you mind adding a few lines to MIGRATION.md under the From version 4.1.x to 5.0.x heading to explain this change in behavior? I'd like to be able to point people at that if this comes up again.

@backbone87
Copy link
Contributor

see #6447

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants