storybook: [Bug]: Storybook Composition does not connect properly on Storybook 7
Describe the bug
First off, I would like to point out that I am trying to run my main storybook with composition config on Storybook 7 while my reference storybooks are still on Storybook ~6.5, so I’m not sure if this is intended to work. I can do some more investigation into upgrading those other ones to see if it resolves my issues, but it might be a while before I can get to it.
When my static storybook loads, I get an error from Explorer. In this instance selected is null and ref.id is undefined. The ?. operator causes them to be equal and get an error:

I wrote a patch in my project to have a better check than the above. Basically changing that line to the following:
selectedStoryId={selected?.refId && selected.refId === ref.id ? selected.storyId : null}
This worked for the most part. The only problem is now with that I am seeing double instances of all my references – one that looks exactly how I would expect and another that stays in a perpetual loading state.

Hopefully this is good information. I unfortunately can’t share more because it’s in private repos.
To Reproduce
Will try and set up a repro – composition has always been difficult for me to set up locally.
System
All storybook dependencies `@7.0.5`
Additional context
No response
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 3
- Comments: 16 (6 by maintainers)
We also found that having ref keys in camelCase will cause the same issue. The issue is resolved for us when we lowercase everything
Before:
After:
This seems to fix both the duplication issue as well as the initial load null storyId issue.
so tl;dr ensure all ref keys are lowercased without spaces and hopefully that will fix it.
Just came across this same issue in our composed storybooks when updating from v6.5 to v8. Camel casing in our ref keys caused SB to panic 🤯. A surprising bug. This was the error from my console:
Uncaught TypeError: Cannot read properties of null (reading 'storyId')Using all lowercase key names resolved the issue for me as well (thank you @josephmarkus!).
It would benefit others if the title of this issue was more concrete and easier to find. Maybe something like “Storybook Composition panics / throws error when ref keys don’t match storyId pattern (camel case, ect)”
@B-Stewart You really are a savior! Storybook 8.0.8, faced the same issue,
lowercasedref keys of composition stories and it workedm I just can’t believe its realGuys, could you please specify this in docs?
@B-Stewart unbelievable. That
camelCaseto alllowercaseis what fixed it for me. A lifesaver. Thanks!