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

Fix for storybook to resolve alias #589

Merged
merged 4 commits into from
Aug 20, 2021
Merged

Fix for storybook to resolve alias #589

merged 4 commits into from
Aug 20, 2021

Conversation

pavish
Copy link
Member

@pavish pavish commented Aug 19, 2021

Fixes #528

This PR:

  • Fixes the issues with using aliases
  • Fixes issues with using es2020 features
  • Updates storybook to use webpack5 builder, instead of webpack4. The support is mentioned to be experimental, but it should be mainstream soon.

Technical details

Configuring storybook to work with aliases was straight forward. All we had to do was specify the aliases in webpackFinal field, and it does the trick.

It lead to the identification of another problem. Storybook was not able to render the components, when optional chaining or nullish coalescing was used.

Turns out webpack4 has this issue, because it uses an older version of acorn. Reference: webpack/webpack#10227

One of the workarounds was to force the resolution of acorn to a later version. When doing this, storybook did not work properly.

The other option was to try a different builder. Webpack5 or vite. I tried both.

When I tried using webpack5, it lead to svelte components not being able to render within storybook. The errors did not provide relevant information to debug this.

I switched to vite, which had even more issues since the support was still experimental. To start with, hmr didn't work, and svelte-addon-csf didn't work well with it.

It look a while to try different workarounds and options which didn't lead to fruition. However, I did come across this issue in the addon-svelte-csf package, when working with webpack5: storybookjs/addon-svelte-csf#23

It gave more clarity on how the package worked, essentially it has 2 separate svelte bundles/runtimes, one for the code itself and one for the stories written in svelte.

The fix for it was as simple as specifying the path to svelte modules, as an alias.

Checklist

  • My pull request has a descriptive title (not a vague title like Update index.md).
  • My pull request targets the master branch of the repository
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no
    visible errors.

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@pavish pavish requested review from a team, kgodey and mathemancer August 19, 2021 18:44
@kgodey
Copy link
Contributor

kgodey commented Aug 19, 2021

@pavish How do I test this PR locally?

@pavish
Copy link
Member Author

pavish commented Aug 19, 2021

@kgodey We can run npm run storybook in the ui container. I have enabled back the story which was causing issues, as mentioned in #528.

To Reproduce

Add the .svelte extension to src/components/modal/__meta__/Modal.stories.
Run Storybook.

If storybook runs without any issues, this PR works.

@pavish
Copy link
Member Author

pavish commented Aug 19, 2021

@kgodey Please make sure to restart the ui container before testing. There are new package dependencies, which wont be installed unless the container is restarted or rebuilt.

Alternatively, you could also do npm install within the ui container.

Copy link
Contributor

@kgodey kgodey left a comment

Choose a reason for hiding this comment

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

Looks great, thank you!

I think it would be good to add the instructions to run storybook to the main README file. You can do it in this PR and then merge it. Thanks!

@pavish
Copy link
Member Author

pavish commented Aug 19, 2021

@kgodey The frontend readme file contains information on all aspects of frontend development. Considering storybook is only going to be used for reusable components, I am not sure if we should place it on the main readme.

I have placed a link to the frontend readme file in the main readme, in this commit: 880d042

Let me know if this is okay, or if you feel it would be better to also mention it on the main readme, I'll include it.

@kgodey
Copy link
Contributor

kgodey commented Aug 20, 2021

@pavish I think linking to the frontend README file is fine, thanks!

@kgodey kgodey merged commit 8eb6b90 into master Aug 20, 2021
@kgodey kgodey deleted the storybook_alias_fix branch August 20, 2021 11:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

Storybook does not resolve paths from TS config
2 participants