-
-
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
Fix experimental_indexers importPath
being ignored
#26010
base: next
Are you sure you want to change the base?
Fix experimental_indexers importPath
being ignored
#26010
Conversation
importPath
being ignored
@JReinhold when you have some time, please take a look at the questions I had |
Hey @JReinhold, I got my storybook sandbox working yesterday to test this PR and there was a piece missing. The Initially I thought of importing Similar problems may arise for other builders. Since I'm still learning about the inner workings of Storybook, it would be great if someone from the core team could take at this. It would take me quite some time to verify since I would still need to setup sandboxes for each builder. If someone finds and issue with a builder and points me to the right location, I can quickly fix other builders applying the same logic. After I've received an approval for the implementation, I'll add tests, an |
6d18995
to
e574c36
Compare
1e43f35
to
e574c36
Compare
crap... @ndelangen I wanted to pull and did the opposite 🤦🏻 and I just realized it's too easy to do a force push with Lazygit. I noticed there was a commit from you before I did this atrocity. Was it just a rebase on top of |
e574c36
to
2f0de6d
Compare
I've rebased the branch on top of |
Hey @JReinhold or @valentinpalkovic, it looks to me that what we need now is to update the snapshots due to the change of the import path. But I think it is better if someone from the core team take a look at it |
Can you tell me more about this, why do you assume this? |
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.
I'm seeing lots of changes here unrelated to importPath
- mostly preset handling and typing. Are they a result of a bad rebase/merge or are all these changes intentional?
Either way I think we should keep them out of this PR.
I believe that's actually the point of this whole exercise @tmeasday , and the only use case for indexers to specify their own If you have an input file -
Vite already establishes a convention for this with the https://vitejs.dev/guide/api-plugin#virtual-modules-convention |
That's exactly right. In my case I'm creating an interceptor between Marko and Storybook to allow stories to be written in Marko. I can mess with the files, otherwise I'll break Marko's build. I actually tried (a lot) to get around the need for a virtual path, but not matter what I did, at one point or another, things would go haywire. Vite simply isn't very reliable or predictable when it comes to plug-in execution :(
That's my recommendation too. But just to give credit where credit is due, that mechanism and convention was established by Rollup ;) (Sorry, I guess I'm a bit bitter that Vite become the standard and now I have to endure it hahaahaha but seriously... I've lost countless hours because of it) |
Ok, thanks for filling me in (and sorry for not reading the whole thread). That approach sound sensible to me! |
just came across this thread because i think this would also solve an issue i am currently facing. would it be possible for somebody from the @storybookjs/core team to create a canary release for pr so i can check if this works for my usecase as well or if i need to dig somewhere else? |
Failed to publish canary version of this pull request, triggered by @valentinpalkovic. See the failed workflow run at: https://github.com/storybookjs/storybook/actions/runs/9356213289 |
1 similar comment
Failed to publish canary version of this pull request, triggered by @valentinpalkovic. See the failed workflow run at: https://github.com/storybookjs/storybook/actions/runs/9356213289 |
Same here, happy to test a canary. Thank you @svallory for working on this |
Quick update: Sorry for being MIA. I'm working on a big launch due next week and have no time at all to work on anything else. If anyone wants to take this over the finish line, please go ahead! There isn't much left to be done. I'm available to answer any questions. Just send me a DM on twitter @svallory_en or discord |
I'd love to take over but after reading the thread I am not 100% sure whats left to be done here? Probably fixing the TypeScript types that break the build right now and some manual testing? |
Hey @dunklesToast, that's great! There isn't much left to do. IIRC, all that is left is:
Note Be aware of Rollup's virtual module convention for virtual modules adopted by vite:
|
97c08a4
to
d4b7d4d
Compare
☁️ Nx Cloud ReportCI is running/has finished running commands for commit aff1957. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this CI Pipeline Execution ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
Note that another alternative to virtual paths is to add certain query segments / "sub parts" to the import url, e.g.
(the vue vite plugin uses this, eg https://github.com/vitejs/vite-plugin-vue/blob/ac1255989d53bcd98f72f2e6c16946a00402eac6/packages/plugin-vue/src/main.ts#L314-L320) |
Thinking about this a bit more, would it make sense to write the story index ( const imports = {
story-id: () => import("import-path")
....for each story
}
function importFn(storyId) {
return await imports[storyId]
} where both storybook/code/core/src/preview-api/modules/store/StoryStore.ts Lines 141 to 147 in 6388f93
async loadCSFFileByStoryId(storyId: StoryId): Promise<CSFFile<TRenderer>> {
const moduleExports = await this.importFn(storyId);
// We pass the title in here as it may have been generated by autoTitle on the server.
return this.processCSFFileWithCache(moduleExports, importPath, title);
} |
It's not an alternative to the issue at hand if it requires an existing file. Also, depending on the language/framework you are creating the plugin for, even if there's a file, you may not be able to process the request before the language/framework plugin does |
@tobiasdiez I think the entire process would benefit from a little cleanup (well, more like a big refactoring TBH) The flow is confusing and hard to follow. I suspect over the years the need for optimization, or handling new use cases, led to adding more functions, breaking the process of indexing and loading into so many specialized functions. But now that you guys have a clearer picture, I think a do-over with a cleaner separation of concerns (introducing a CSFFile class/module for example) would go a long way |
Sure! That remark was meant to provide an alternative solution as long as this PR is not finished. I would love to see support for
From what I have seen in the codebase, I agree with your judgement. |
I see your point, and I think the existing Marko plug-in works using a similar technique. The plug-in I created though is not for rendering Marko components in stories, but to write the stories in Marko. And just in case someone doing a similar plug-in finds this... In general, for files that need compilation before becoming a JS CSF File, there are two options:
|
Hey @svallory @tobiasdiez thanks for the discussion.
I won't speak to the confusing part but the architecture of the indexers/ The key point here is that the starting globs ( The reason for this is that the webpack storybook/code/lib/core-webpack/src/to-importFn.ts Lines 46 to 58 in ab66906
-- Another element of this is that the Another future use case is relating dependent CSF files by importPath.
I guess I wonder about what's the issue with the first option? |
Thanks @tmeasday for the nice overview. One problem with this design is that whatever the indexer returns as the As an idea, would it work to use the story index |
But this is my point. Webpack in particular does not and would not use the generated index to construct it's |
I'm completely ignorant when it comes to webpack, but is there a fundamental issue with having the following dependency chain?
Then if the stories are changed, the indexer output changes as well; which invalidates Another idea would be to call the indexer for the generation of the Or how would you envision how the |
@tmeasday AFAIK only the second option would provide a way to define multiple separate metas from the same file. Eg if you had a json-file from which you wanted to create 3 components with 10 stories each. Because CSF only allows one component per file, you'd instead generate 3 virtual files from that single json file path. Although TBH I haven't actually tried returning IndexInputs with different titles from the same file path. The second option does sound slightly interesting to me, based on the Svelte work I've done. Given you could instead create a virtual CSF file that wraps the original Svelte component I imagine the complexity around transforming an already-internally-transformed file would be smaller. A few cases spring to mind:
I'd expect all of the above would be solved by moving away from transforming the file inline to generating a wrapper CSF file instead. |
@tmeasday thanks for the overview!
To add to what @JReinhold said about this, the main issue with "intercepting the transpilation" is that the development of a "simple" plugin for storybook suddenly requires knowledge of how the language compiler works. In the case of Svelte, the plugin needed to run after the Svelte transpilation. In my case, since Marko integrates tightly with the server for extensive runtime optimization (which I believe may also be the case for Qwik and Imba), that wasn't an option. I would need to take control of the Marko compiler, proxying it's integration entirely. Even with deep knowledge of its internals, the implementation would end up fragile and break easily with future changes. |
Closes #25554
What I did
Added a simple "or" to try to use indexers.importPath but fallback to the original file path.
Couple of things to note
importPath
is currently required. I think it is safe to make it optional with the default being the path of the file being indexed. I haven't added a test case because of this.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!
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>