storybook-router icon indicating copy to clipboard operation
storybook-router copied to clipboard

Cannot read property 'name' of undefined

Open Moonhint opened this issue 5 years ago • 4 comments

Issue:

Which version are you using? 1.0.3

Are you using storybook-router with a react based project or a vue one? with vue

Please describe the problem:

Screenshot from 2019-04-11 13-36-54 After add this to my story, I found this Cannot read property 'name' of undefined error.

Please explain how to reproduce the issue or (better) provide an example to do it.

Here how I add it: Screenshot from 2019-04-11 13-37-08

Moonhint avatar Apr 11 '19 06:04 Moonhint

Seeing the same issue; initial appearances are that it's the interaction of this addon with storybook-addon-vue-info

Here's my relevant package.json:

"storybook-addon-vue-info": "^1.1.1",
"storybook-vue-router": "^1.0.3",

Most importantly, in my component, when I remove the use of vue-info, the component loads. When I have both vue-info and vue-router addons, I see the same failure message as @Moonhint. When I use only vue-info and not vue-router in a story, I don't get the error message, but then I get a failure when I try to use a <router-link>

Investigating, but not certain I'm gonna get anywhere in terms of a fix... 🤔

jackkoppa avatar May 03 '19 18:05 jackkoppa

experiencing exactly the same problem reported by @jackkoppa . At the moment I'm resigned to avoid using the info addon where I need the router, but it's definitely something related to the interaction with each one.

ThePeach avatar May 09 '19 09:05 ThePeach

Hi @ThePeach, @Moonhint - I thought I responded earlier here.

I have a decent solution, after some experimenting: move storybook-vue-router to be global, loaded after storybook-addon-vue-info. It will be available on all stories now, and you won't be able to setup real routes to test dummy components with, since that has to happen in each story (at least I haven't discovered how).

But, it does mean that you can use this addon, with the router addon, and your stories will function well.

So:

  1. Remove any reference to storybook-vue-router in individual stories
  2. Setup your .storybook/config.js to look roughly like this:
import { configure, addDecorator } from '@storybook/vue'

// begin important part 
import { withInfo } from 'storybook-addon-vue-info';
import withRouter from 'storybook-vue-router'

addDecorator(withInfo)
addDecorator(withRouter())
// end important part

function loadStories() {
	// Dynamically requires any .js file inside of the
	// stories directory
	const stories = require.context('../src/stories/', false, /\.js$/)
	stories.keys().forEach(stories)
}

configure(loadStories, module)
  1. Then, in each story, you just enable this vue-info addon by passing in an info object at the end, the way you may already be doing:
stories.add(
	'Some story name',
	() => {
        // Implement the story
	},
	{
		info: { summary: 'My sample summary' }
	}
)

jackkoppa avatar May 15 '19 19:05 jackkoppa

@jackkoppa thanks for the clarification! loading the router after info works, odd behaviour perhaps but this seems to fix it and make them work together.

🙇 🎉 👍

ThePeach avatar Jun 03 '19 11:06 ThePeach