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

Method call in story which looks like xyz.add(arg1, arg2) breaks story #13068

Closed
christianruhstaller opened this issue Nov 10, 2020 · 1 comment

Comments

@christianruhstaller
Copy link

christianruhstaller commented Nov 10, 2020

Describe the bug
If in the story source file you use a method call with following definition xyz.add(arg1, arg2) it seems that storybook will use the value of the arg1 and inject it to it's generated code and throws following warning and breaks the story.
The method does not have to do anything with storybook and the method call is empty.

index.js:53 Unexpected error: ReferenceError: {arg1} is not defined.

{arg1} will be the value of the arg1.

In the generated main.XYZ.bundle.js following lines will be generated which are wrong (See screenshot):

{arg1}.parameters = Object.assign({
  storySource: {
    source: "null"
  }
}, {arg1}.parameters);

It seems that storybook somehow parses the source and uses some sort of parsing and if it finds the .add method call it will use this as an indicator to add a specific story which in this case and any other case where the call looks like XYZ.add('…', '…') which leads to a warning and the story won't work anymore.

To Reproduce
Steps to reproduce the behavior:

  1. Install a vanilla HTML storybook
  2. Create `src/includes.js' file and add the content from below
  3. Import includes file in stories/1-Button.stories.js: import { problem } from '../src/include'
  4. Add following line after the import problem.add('thiswillgetinjected', null) // won't work
  5. Run storybook and see warning in console (Plus the story won't be available)
problem.add('thiswillgetinjected') // will work
problem.add('thiswillgetinjected', null) // won't work
problem.add('thiswillgetinjected', {}) // won't work
problem.add('thiswillgetinjected', {}, {}) // won't work

Watch out: Ensure that you do not export a story with the value in the add method call then it will work.

Happened to me and cost me some hours until I figured it out why some calls worked and some did not. :)

Expected behavior
There should not be any interference with storybook if you call a method named add and has no side effects inside the method call.

Screenshots
image

Code snippets
src/include.js

export const problem = {
  add: (a, b) => {

  },
}

export default {
  problem
}

System
Environment Info:

System:
OS: macOS 10.15.5
CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Binaries:
Node: 14.5.0 - /usr/local/bin/node
Yarn: 1.22.4 - /usr/local/bin/yarn
npm: 6.14.5 - /usr/local/bin/npm
Browsers:
Chrome: 86.0.4240.193
Firefox: 81.0.1
Safari: 13.1.1
npmPackages:
@storybook/addon-actions: ^6.0.28 => 6.0.28
@storybook/addon-essentials: ^6.0.28 => 6.0.28
@storybook/addon-links: ^6.0.28 => 6.0.28
@storybook/html: ^6.0.28 => 6.0.28

@shilman
Copy link
Member

shilman commented Nov 10, 2020

Closing as duplicate to #12208 tho it might be slightly different. Would like to fix it in #12561

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

2 participants