-
-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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.
6af0f53
to
2e6a7ed
Compare
@valentinpalkovic I rebased my branch on top of next and just pushed the fix for indexer's Note:
|
Btw, @valentinpalkovic I accidentally committed a new sandbox template for Marko (writing stories in Marko is the whole reason I'm sending this PR). I'll remove it in the next commit. Would a PR to add Marko JS as a sandbox template and fully supported framework acceptable? |
2e6a7ed
to
537aa25
Compare
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.
Great cleanup, much easier to review now. 😅 Still a couple of questions and feedback points to touch on.
Could you fill out the "Manual Testing" section in the PR, with steps on how to test this? Just something minimal, with a custom indexer returning a custom virtual importPath
, and a very minimal Vite plugin that adds that virtual module with some CSF content in it.
I'm sorry if it feels like I'm nitpicking here, but you're touching on some of the most essential code in Storybook, and breaking it could cause issues for many users. We'll get there! 😊
code/lib/core-server/src/utils/__tests__/index-extraction.test.ts
Outdated
Show resolved
Hide resolved
537aa25
to
6e78ca9
Compare
Hey, @JReinhold, don't worry about it! I wanna get this right! ;) I was actually trying to get a sandbox for Marko to test this fix, but I ran into to a lot of issues while trying to do that. Can you help me get that up and running? I think it would become an awesome example of customization since it will touch on all that one can do using custom indexers. In trying to fix it, I started adding Marko alongside all the other frameworks in every place I could find, and it feels like I'm close now. I've pushed my WIP to the It would be great to use the add-on I'm already creating as the manual test. But if this is all too much work, let me know and I'll come up with something else. I intend to work on this tomorrow to address all the comments you've made. |
I quickly looked through it, looks straightforward and you are touching the right files, but I don't think the git submodule idea will hold. I suggest you draw inspiration from the Solid and Qwik integrations, which are both examples of frameworks+renderers that are initable and sandboxable but are actually not in the monorepo. I think there are some limitations with this, but for now this the best we can do. https://github.com/storybookjs/storybook/blob/next/code/lib/cli/src/sandbox-templates.ts/#L492-L504 https://github.com/storybookjs/storybook/blob/next/code/lib/cli/src/generators/QWIK/index.ts https://github.com/storybookjs/storybook/blob/next/code/lib/cli/src/project_types.ts/#L23-L26
We use the Manual Test section to manually verify things work before we to minor/major releases (in about 2 months). The best way to do that are with minimal steps, similar to a minimal reproduction. It's just more fool proof if the manual steps are minimal, and don't depend on bigger things. If things fail it could be impossible to tell if they fail because of some bug in the Marko integration or because there's an issue with the import paths, and I want to avoid that confusion if I can. |
That's great! I was concerned I was doing way too much just to support sandboxing.
That's just to make my exploration easier. I didn't intend to propose it.
Great! That makes it way easier.
I agree. This should not be too hard. In fact, I think I should also add a unit test for indexers returning virtual paths. And a note to the docs about it (since there's a recommendation from vite/rollup regarding their syntax). I think I'll take inspiration on the JSON stories from the docs and make an example that embeds the stories file content in a virtual path using base64. That will eliminate the fs loading and parsing in vite which can be cumbersome to do at runtime. One more thing... I noticed your comment about the dynamic snapshot. That was the easiest path to make sure everything was working. The only way I see out of that is to make the path relative again. We can use the Also, we can do this in the generator's extractStories() function, but that wouldn't work for all tests or all paths. The only way to ensure the removal of machine-specific paths in the return would be to process the generator's result in the tests before comparing it to the snapshot. Please let me know how to proceed. I'll work on the final touches tonight/tomorrow |
The reason it is there is that Storybook passes an absolute path to the importer. Since the test importers simply return the path, the absolute path gets into the index.
That was my first reaction too, but if you think about it, there's nothing preventing the indexer code of reading the entire filesystem if it wants to. AFAIK, unless Storybook implements a require/import handler to override node's fs module (if that's even possible), that will remain to be the case, right? Or is there something I'm missing here? I do feel it is kinda odd to deal with absolute paths, in a web app. But may get complicated on that front when you factor in all the variables involved. If we do relativize the path, what will be used as the base for import? The project root, the build/web root, the custom indexer file? When the bundler plugin for the indexer gets the file, will it get the relative or the absolute path? If it's a relative path, can we make sure the What I'm trying to point out here is that there are a lot of things to think about when forcibly modifying the indexer's return. This is a decision that the Storybook team will need to discuss and take very carefully. I think it is outside of the scope of this PR though. The goal here is just to make indexers work as advertised in the docs. Right now, what is documented in the site does not work. It never has. I hope the fact the the indexers are I'll be pushing the fixes for all other issues later today! |
The CWD is what we have been using up until now. Basically the import path is going to be relative to the virtual module that defines the This isn't really something the indexer can change -- it isn't the thing doing the importing so should have to fit with the existing So I'd propose:
I'm not really too concerned about the behaviour of customer (experimental as you say) indexers, I am concerned about the default behaviour in Storybook as exhibited by the tests. Am I off base about that? |
I think you are right. As long as we only have imports of real files in the
Not at all! What I meant was that Storybook isn't introducing any security risks by exposing the absolute path to the indexer. But that's because I assumed that the code generated for those imports was only used in |
Right, so yes, the |
I understand your concern. And yeah, even in dev mode, people would complain about it. So, I stumbled on an issue here. How should we deal with virtual paths that look like absolute paths? Check this example from [
Right now, it would be resolved to something like this...
We can enforce a specific prefix for virtual paths (traditionally Or we could add a new property called What do you guys think, @tmeasday and @JReinhold ? |
@svallory but that path wouldn't end up in the |
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:
|
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>