Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Source-loader: Overhaul to remove decorators, support user-configurable source #9547

Merged
merged 10 commits into from
Jan 28, 2020

Conversation

atanasster
Copy link
Member

@atanasster atanasster commented Jan 20, 2020

Issue:

What I did

  • refactor source-loader to reduce code changes to minimum (only the story source and the id map is kept)
  • removed decorators of stories that used to 'emit' source code, now only the parameters: { storySource: { source, locationsMap } } are used
  • refactor addons/StorySource to use story parameters instead of replying on messages from source-loader code
  • rewrite addons/StorySource in typescript

How to test

Hopefully all should work as before, just less code generated and less possible sources of issues.
I am not that familiar with older formats - if you have stories using storiesOf or any third-party addons using source-loader would be great help.

@vercel
Copy link

vercel bot commented Jan 20, 2020

This pull request is being automatically deployed with ZEIT Now (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://zeit.co/storybook/monorepo/9i4evbn98
✅ Preview: https://monorepo-git-fork-atanasster-source-loader-refactor.storybook.now.sh

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

THIS IS AWESOME!!!

I think we can make a few more tweaks (see comments), but it's a HUGE improvement 😍

addons/docs/src/blocks/Source.tsx Show resolved Hide resolved
addons/storysource/package.json Outdated Show resolved Hide resolved
addons/storysource/src/StoryPanel.tsx Outdated Show resolved Hide resolved
addons/storysource/src/StoryPanel.tsx Outdated Show resolved Hide resolved
}
export const StoryPanel: React.FC<StoryPanelProps> = ({ api }) => {
const [state, setState] = React.useState<SourceParams & { currentLocation?: SourceBlock }>({
source: 'loading source...',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any way to detect when the source-loader failed and show an error message?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe if no source code is found at all in the storySourc parameter?

kind?: string;
parameters?: {
storySource?: SourceParams;
mdxSource?: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while we're cleaning this up, maybe we can get rid of mdxSource? i think now you support an empty locationsMap, so we can put the MDX source in storySource.source and it's a lot cleaner.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it might break some code, no?
I saw examples in the code like:
two.story.parameters = { mdxSource: '<Button>Two</Button>' };

addons/storysource/src/preview.ts Outdated Show resolved Hide resolved
lib/source-loader/src/server/build.js Outdated Show resolved Hide resolved
@atanasster
Copy link
Member Author

@shilman - checked in the updated code, without the removal of mdxSource.

@atanasster
Copy link
Member Author

For mdxSource we can:

  • remove mdxSource completely and mark it as a breaking change for 6.0 for both Preview and parameters.
  • keep mdxSource as a prop to Preview only, remove it from parameters and still mark it as a breaking change.
  • keep mdxSource backwards compatible, but change mdx-compiler to output to storySource. All the code in Source, Preview will still need to check for both mdxSource and storySource parameters.

@shilman
Copy link
Member

shilman commented Jan 21, 2020

@atanasster Removing mdxSource is all about cleaning things up (assuming it does clean things up--if it doesn't, let's discuss!), so let's remove it completely if we make the change. Docs is quite new and hopefully people will understand that the API is still in flux, esp. in a major release. Furthermore mdxSource is an undocumented advanced usage.

@atanasster
Copy link
Member Author

@shilman - yes, makes sense.

Would you like to first merge this PR, its gotten quite large already and remove mdxSource in another PR?

@shilman
Copy link
Member

shilman commented Jan 21, 2020

@atanasster sounds good. will do!

@shilman shilman added the maintenance User-facing maintenance tasks label Jan 21, 2020
@ndelangen
Copy link
Member

Amazing job on this! Didn't mean to close the PR at all. Really appreciate the source-loader getting an improvement like this!

@atanasster
Copy link
Member Author

Cool, its not an improvement, its a re-design and a rewrite and i would really appreciate this getting merged in the alphas to get some testing. Its a lot of work, including the full typescript rewrite of the source addon.

@atanasster
Copy link
Member Author

And just in case its missed - the source-loader was doing ungodly things manipulating the source code, probably useful at the time, but now affecting both for performance and usability and a rewrite was a bit overdue.

@shilman shilman changed the title Source loader refactor Source-loader: Overhaul for user-configurable source, no decorators Jan 28, 2020
@shilman shilman added this to the 6.0.0 milestone Jan 28, 2020
@shilman
Copy link
Member

shilman commented Jan 28, 2020

@atanasster Thanks for your patience on this. I'm merging this with the understanding that this is the start of an iterative process, but that merging & releasing will get the ball rolling.

We need to figure out a good process for experimenting with new code. You suggested an "experimental" branch, but it's already cumbersome enough to patch changes back and forth between next and master, and in the past when we had three branches it's been untenable for me as the primary person responsible for keeping track. I think, instead, that I'll more aggressively merge stuff into next provided that there is some understanding about follow-up work.

In this case, the follow-up work probably includes:

  • Getting rid of mdxSource if we can
  • Addressing the DeepScan warnings
  • Testing with users and iterating based on the issues that come up (as with any change we introduce)
  • Updating the documentation to reflect the changes

There's probably more, but I trust that we can figure it all out over the coming weeks.

@shilman shilman changed the title Source-loader: Overhaul for user-configurable source, no decorators Source-loader: Overhaul to remove decorators, support user-configurable source Jan 28, 2020
@shilman shilman merged commit 2bee5dd into storybookjs:next Jan 28, 2020
@shilman shilman deleted the source-loader-refactor branch January 28, 2020 08:47
@ndelangen
Copy link
Member

🎉

@atanasster
Copy link
Member Author

atanasster commented Jan 28, 2020

Thanks a bunch @shilman as we discussed this was blocking me from testing the default ‘knobs-2’ passing props as the first parameter to storyFn

I am a happy camper again, sorry for venting my frustration.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants