storybook icon indicating copy to clipboard operation
storybook copied to clipboard

noRefCheck functions on the Show Code

Open Smankusors opened this issue 2 years ago • 16 comments

Describe the bug I found something weird when reading the code generated on Storybook, that is every function that I didn't define, shows up as noRefCheck. Even though if I set it manually as undefined.

But no, that's just a background, and I believe that issue might have to do with the react-element-to-jsx-string. The actual issue, is that the first function is always written as () => {} while the rest functions would be written as function noRefCheck() {}. Now that's pretty weird behaviour IMO. Please take a look at this built-in example (?) below

image

Now... isn't that code should be like this below?

<Header
  onCreateAccount={() => {}}
  onLogin={() => {}}
  onLogout={() => {}}
  user={{
    name: 'Jane Doe'
  }}
/>

it looks more pretty.

To Reproduce I don't think I need to create a repo for this. I just simply:

  1. Run npx create-react-app
  2. Run npx sb init
  3. Run npm run storybook
  4. Wait, and open EXAMPLE > Header

System

Environment Info:

  System:
    OS: Windows 10 10.0.19042
    CPU: (8) x64 Intel(R) Core(TM) i7-4720HQ CPU @ 2.60GHz
  Binaries:
    Node: 16.6.0 - A:\Program Files\nodejs\node.EXE
    Yarn: 1.22.17 - ~\AppData\Roaming\npm\yarn.CMD
    npm: 7.24.1 - A:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: 99.0.4844.51
    Edge: Spartan (44.19041.1266.0), Chromium (99.0.1150.39)
  npmPackages:
    @storybook/addon-actions: ^6.4.19 => 6.4.19
    @storybook/addon-essentials: ^6.4.19 => 6.4.19
    @storybook/addon-interactions: ^6.4.19 => 6.4.19
    @storybook/addon-links: ^6.4.19 => 6.4.19
    @storybook/builder-webpack5: ^6.4.19 => 6.4.19
    @storybook/manager-webpack5: ^6.4.19 => 6.4.19
    @storybook/node-logger: ^6.4.19 => 6.4.19
    @storybook/preset-create-react-app: ^4.0.1 => 4.0.1
    @storybook/react: ^6.4.19 => 6.4.19
    @storybook/testing-library: ^0.0.9 => 0.0.9

Additional context I think I found the culprit, just replace the replace with replaceAll. If you allow, I can create a PR to fix this including adding a new unit test to cover this one. wdyt?

Smankusors avatar Mar 13 '22 16:03 Smankusors

I have the same issue image Screenshot from 2022-08-02 09-52-50

aymenmensi avatar Aug 02 '22 08:08 aymenmensi

Joining the party with the same issue.

'Show Code' display: image

While only children are sent to the component: image

ShimiSun avatar Aug 11 '22 21:08 ShimiSun

I'm just facing the same issue. Seems like @Smankusors has already found out how to fix this...? 🙏

365kim avatar Aug 29 '22 07:08 365kim

PR: #19004

zhyd1997 avatar Aug 29 '22 13:08 zhyd1997

Facing the same issue 👀

baptisteArno avatar Sep 05 '22 12:09 baptisteArno

Any news on this issue? It would be awesome if we can gave good code export functionality.

Thank you!

iosifnicolae2 avatar Oct 12 '22 09:10 iosifnicolae2

any update I'm facing the same issue

HemendraKhatik avatar Oct 21 '22 06:10 HemendraKhatik

@iosifnicolae2 @HemendraKhatik

PR #19004

zhyd1997 avatar Oct 21 '22 10:10 zhyd1997

Same issue here.

image image

viniisdsc avatar Nov 08 '22 17:11 viniisdsc

Hi @viniisdsc

Did you try the latest version of storybook?

And what does your Button component look like?

zhyd1997 avatar Nov 08 '22 19:11 zhyd1997

We also have this issue. Running version 6.5.13

dennisschroer avatar Nov 09 '22 08:11 dennisschroer

@dennisschroer

Please try the prerelease version: v7.0.0-alpha.46

zhyd1997 avatar Nov 09 '22 08:11 zhyd1997

Still seeing this in 7.0.18.

jacobrask avatar May 31 '23 09:05 jacobrask

Ditto, We're still seeing this in 7.0.18 as well.

jake-chapman-mark43 avatar Jun 08 '23 20:06 jake-chapman-mark43

We see this in 7.1.0 since we set docs: { source: { type: "dynamic" }, },.

donaldpipowitch avatar Jul 20 '23 07:07 donaldpipowitch

I'm also suffering from this in 7.6.16, however, for me it appears to be due to a missing space.

In everyone's screenshots, function noRefCheck() {} is rendered, however for me function noRefCheck(){}, so for my case the fix was quite simple, and I raised a PR here #26104.

thisisanto avatar Feb 20 '24 00:02 thisisanto

v8.0.0 has been released and contains my fix #26104 , which resolved this issue for me. Try upgrading as it might fix yours too 🤞🏼 if enough people confirm we can close this issue

thisisanto avatar Mar 12 '24 03:03 thisisanto