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

Svelte/Vite: Prevent crash when no svelte.config file #21339

Merged
merged 3 commits into from Mar 2, 2023

Conversation

JustinEloffBBD
Copy link
Contributor

What I did

The svelteDocgen plugin crashes Storybook if you have no svelte config file defined. It tries to destructure the options, but with no config file, this value is null, causing a crash. Setting an empty object as a fallback looks like it solved the issue.

How to test

Have no svelte.config.js file. Run storybook.

Checklist

I havn't done any integration/unit testing here. Just made a quick edit on github to propose a potential fix. If this is an issue for this change I can take a more thorough approach tomorrow.

  • Make sure your changes are tested (stories and/or unit, integration, or end-to-end tests)
  • Make sure to add/update documentation regarding your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Maintainers

  • If this PR should be tested against many or all sandboxes,
    make sure to add the ci:merged or ci:daily GH label to it.
  • Make sure this PR contains one of the labels below.

["cleanup", "BREAKING CHANGE", "feature request", "bug", "documentation", "maintenance", "dependencies", "other"]

The svelteDocgen plugin crashes Storybook if you have no svelte config file defined. It tries to destructure the options, but with no config file, this value is null, causing a crash. Setting an empty object as a fallback looks like it solved the issue.
@shilman shilman changed the title Set svelteConfig to empty object by default. Svelte/Vite: Set svelteConfig to empty object by default Mar 2, 2023
@shilman shilman requested review from IanVS and JReinhold March 2, 2023 03:56
@IanVS
Copy link
Member

IanVS commented Mar 2, 2023

Thanks for catching this, @JustinEloffBBD, and for the PR.

I think this change would work, but let's solve it closer to the cause, in the plugin, by adding a default to the parameter:

// code/frameworks/svelte-vite/src/plugins/svelte-docgen.ts

export function svelteDocgen(svelteOptions: Record<string, any> = {}): PluginOption {

That way we won't run into this in the future if we need to use the plugin elsewhere.

@JustinEloffBBD
Copy link
Contributor Author

Cool. I have updated the code accordingly, also tested it on a stock svelte project, with no config file, still works.

@IanVS IanVS changed the title Svelte/Vite: Set svelteConfig to empty object by default Vite: Prevent crash when no svelte.config file Mar 2, 2023
@IanVS IanVS changed the title Vite: Prevent crash when no svelte.config file Svelte/Vite: Prevent crash when no svelte.config file Mar 2, 2023
Copy link
Member

@IanVS IanVS left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

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

Successfully merging this pull request may close these issues.

None yet

4 participants