-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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: Fix docs generating when using lang="ts"
or optional chaining
#24096
Conversation
@JReinhold The "sveltedoc-parser" plugin is duplicated between vite and webpack. I tried to mutualise the code, but I didn't know where I can put it. the "@storybook/svelte" is only build for a browser, and can't host code for the server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this! 💪
Could you add an e2e test for this?
Ideally it would be enough with a story to test this, but since this is docs related it's more involved than that, because Chromatic doesn't capture docs.
To do this:
-
Add a stories-file with autodocs to https://github.com/storybookjs/storybook/tree/next/code/renderers/svelte/template/stories that demonstrates this behavior.
-
You can test out the stories you're writing by generating a sandbox with
yarn task --task sandbox --template svelte-vite/default-ts
, it should symlink your stories into the sandbox. -
Add an e2e test file at
code/e2e-tests/framework-svelte-vite.spec.ts
that visits the docs page and asserts that the source content is correct. You can see how this is done for NextJS here (the important part is to skip if the framework doesn't match). https://github.com/storybookjs/storybook/blob/next/code/e2e-tests/framework-nextjs.spec.ts
Let me know if this guidance isn't enough for you to move forward with it, or if you need me to write a test for this instead.
The "sveltedoc-parser" plugin is duplicated between vite and webpack
That's okay, that's just how it is structured, I don't think it's a big deal, but thanks for considering it. The best we can do is to link between the two files with a comment, so that if it's updated one place we remember to update it both places.
559910c
to
8ed50ff
Compare
I had to remove the e2e test of the documentation for typescript sandbox. vite uses esbuild which removes jsdoc from the component - the doc is then not visible by the parser. @benmccann maybe you know a workaround for this ? |
that would not be good. they don't work the same so output can differ. why exactly is the name parsed from a comment in the output at all? 99.9% it's sufficient to derive it from the filename (that's what svelte is doing too). And for the other 0.1, you could just have an option? |
We should maybe only preprocess for typescript with svelte-preprocess in the plugin extracting the documentation. |
I'm not familiar with the flow, but why are we extracting the docs after processing? Shouldn't it extract the docs before that as the user authored? For example, if the Svelte component property is typed |
is this a typo or are you expanding svelte.config.js with your own keys? |
I suppose you ask because I shouldn`t do that ? What the best way to configure this preprocessor ? |
Why does the preprocessor even need to be configured? I'd remove the options altogether. |
I have added a possibility to configure it to handle edge-cases discuted here, like "what if the component is written with mdsvex", but I can remove it. |
👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎ This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored. |
Hey @JReinhold would you mind to check this out whenever you have the time? Thanks! |
Co-authored-by: Ben McCann <[email protected]>
lang="ts"
or optional chaining
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! Thanks for the hard work and the patience! ❤️
(just waiting for the CI to finish)
@j3rem1e CI shows that this breaks for non-TS projects, because the preprocessor will try to import To summarize my findings:
|
It's look ok to me. Sorry for that, I though that typescript was a required dependency with storybook, I didn't check more. |
probably |
I took a stab at |
Closes #24008 #24137
What I did
When sveltedoc-parser fails to parse a Svelte component, Storybook was not injecting the documentation metadata.
This metadata was used to determine the component name. If the information is missing, then we use
component.name
, which is not always good. For example, when using vite and HMR, svelte generate a proxy namedProxy<Component>
and Storybook was displaying this name instead of the real component name.This PR always injects documentation metadata, with the real name of the component (build at compile time).
Moreover, sveltedoc-parser is configured to parse ecmascript v9 and fails to parse elvis operator, or "??". This PR also change sveltedoc-parser to enable ecmascript v12. However, the configuration is not officially exposed so I have to patch the lib.. I have proposed a real PR to the author of the library.
Checklist for Contributors
Testing
The changes in this PR are covered in the following automated tests:
Manual testing
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
<Proxy<Button> .../>
instead.Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal
,ci:merged
orci:daily
GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli/src/sandbox-templates.ts
Make sure this PR contains one of the labels below:
Available labels
bug
: Internal changes that fixes incorrect behavior.maintenance
: User-facing maintenance tasks.dependencies
: Upgrading (sometimes downgrading) dependencies.build
: Internal-facing build tooling & test updates. Will not show up in release changelog.cleanup
: Minor cleanup style change. Will not show up in release changelog.documentation
: Documentation only changes. Will not show up in release changelog.feature request
: Introducing a new feature.BREAKING CHANGE
: Changes that break compatibility in some way with current major version.other
: Changes that don't fit in the above categories.🦋 Canary release
This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the
@storybookjs/core
team here.core team members can create a canary release here or locally with
gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>