storybook: [Bug]: tsx story's `parameters.docs.source.type = 'code'` shows compiled js code
Describe the bug
Doc’s source view shows precompiled code while trying to provide sample with TypeScript code.
It also includes unnecessary parts such as play
, args
etc…
where previously only showed what’s in render
part.
To Reproduce
zb-sj/storybook-issue-21747/Issue.stories.tsx
// Issue.stories.tsx
import type { Meta, StoryObj } from '@storybook/react';
import { within, userEvent } from '@storybook/testing-library';
import { useState } from 'react';
import { Button } from './Button';
const meta: Meta = {
component: Button,
tags: ['autodocs'],
parameters: {
layout: 'fullscreen',
},
};
export default meta;
function SampleComponent(args: { foo: string }) {
const [label, setLabel] = useState('hello');
return <Button label={label} onClick={() => setLabel(`${args.foo} bar`)} />;
}
type Story = StoryObj<typeof SampleComponent>;
export const CodeIssue: Story = {
render: SampleComponent,
args: {
foo: 'foo',
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
const loginButton = await canvas.getByRole('button', {
name: /Log in/i,
});
await userEvent.click(loginButton);
},
parameters: {
docs: {
source: {
type: 'code',
},
},
},
};
// code in docs
{
render: SampleComponent,
args: {
foo: 'foo'
},
play: function () {
var _play = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(_ref) {
var canvasElement, canvas, loginButton;
return _regeneratorRuntime.wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
canvasElement = _ref.canvasElement;
canvas = within(canvasElement);
_context.next = 4;
return canvas.getByRole('button', {
name: /Log in/i
});
case 4:
loginButton = _context.sent;
_context.next = 7;
return userEvent.click(loginButton);
case 7:
case "end":
return _context.stop();
}
}, _callee);
}));
function play(_x) {
return _play.apply(this, arguments);
}
return play;
}(),
parameters: {
docs: {
source: {
type: 'code'
}
}
}
}
System
Environment Info:
System:
OS: macOS 13.2
CPU: (10) arm64 Apple M1 Pro
Binaries:
Node: 16.19.1 - ~/.nvm/versions/node/v16.19.1/bin/node
Yarn: 3.4.1 - /usr/local/bin/yarn
npm: 8.19.3 - ~/.nvm/versions/node/v16.19.1/bin/npm
Browsers:
Chrome: 111.0.5563.64
Safari: 16.3
Additional context
was first discussed at discord
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 1
- Comments: 15 (8 by maintainers)
Whoopee!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.0.5 containing PR #22048 that references this issue. Upgrade today to the
@latest
NPM tag to try it out!It seems like maybe a reasonable thing to do, let’s open a feature request for it?
Yowza!! I just released https://github.com/storybookjs/storybook/releases/tag/v7.1.0-alpha.4 containing PR #22048 that references this issue. Upgrade today to the
@future
NPM tag to try it out!@shilman Yes, the bug was caused by https://github.com/storybookjs/storybook/pull/21629. I have to investigate a proper solution.