storybook-addon-performance icon indicating copy to clipboard operation
storybook-addon-performance copied to clipboard

Bug: preview hooks inside a decorator thrown an error

Open lgraziani2712 opened this issue 4 years ago • 6 comments

When I'm trying to meassure the performance of a story with decorators with preview hooks, the renders throws an error:

Storybook preview hooks can only be called inside decorators and story functions

image

If I remove the decorator's preview hooks, everything works correctly.

  • Repro: https://github.com/lgraziani2712/sb-perf-preview-decorators-bug

Than you for your work!

lgraziani2712 avatar Aug 28 '20 18:08 lgraziani2712

I'm experiencing the same. @lgraziani2712 maybe you want to update the title of this issue to make it more descriptive, I clicked on it to check if by any chance was the same thing I'm reproducing, and it was! However maybe other people just ignore the issue if it just says "Bug".

markelarizaga avatar Dec 04 '20 12:12 markelarizaga

Thank you for noticing this, @markelarizaga! I was pretty sure I did write a descriptive title, but wasn't the case!

It is now fixed :)

lgraziani2712 avatar Dec 09 '20 14:12 lgraziani2712

Can confirm the same issue. It also happens when you the performance addon in conjunction with the popular pseudo-states addon. As of right now, they are mutually exclusive because of this bug. :"(

SatorCube avatar Mar 29 '21 23:03 SatorCube

Same issue when used in conjunction with storybook-miragejs.

Sadly, the only way to use this addon is to make sure other decorators that come before it in the chain do not use storybook hooks e.g useChannel, useParams, etc. Using React hooks are fine.

Was able to work-around by recreating the storybook-miragejs addon functionality I needed from scratch using purely react hooks. Nonetheless, this issue is very limiting for most realistic storybook implementations.

iyobo avatar Feb 15 '22 23:02 iyobo

The issue is still relevant. In case you use preview hooks, the package does not work - image

viktor-panasiuk-97 avatar Apr 02 '24 14:04 viktor-panasiuk-97

This issue is still relevant, I've got the same error when using useArgs in a story

trouba avatar Jul 23 '24 09:07 trouba