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

Experiencing some CORS issue in v6.0.0 while using storybook composition feature. #11892

Closed
rannyeli opened this issue Aug 11, 2020 · 15 comments
Closed

Comments

@rannyeli
Copy link

rannyeli commented Aug 11, 2020

Experiencing some CORS issue in v6.0.0 while using storybook composition feature.
I'm adding a ref for a local storybook:

refs: {
    react_components: { 
      title: "React Components", 
      url: "http://localhost:9010"
    },

The local storybook works well on port 9010, but not loaded from the combined storybook
image

dev-tools output:
image

node - v14.5.0
react - v16.13.1

In addition, I would like to know if there is an option to give a path of the storybook build directory as a url of ref?

Originally posted by @rannyeli in #9311 (comment)

@rannyeli rannyeli changed the title Experiencing some CORS issue in 6.0.0-rc while using storybook composition feature. Experiencing some CORS issue in v6.0.0 while using storybook composition feature. Aug 11, 2020
@tmeasday
Copy link
Member

@rannyeli -- can you check the network tab -- there should be a "no cors" fetch request to http://localhost:9010/iframe.html also -- is that failing also?

@rannyeli
Copy link
Author

@tmeasday http://localhost:9010/iframe.html works and returns 200.

@tmeasday
Copy link
Member

@rannyeli -- to be clear -- do you mean that you yourself browsed there, or that the request that SB makes in the background worked?

@tmeasday
Copy link
Member

OK, I reproduced this. @ndelangen the bug here is the assumption encoded in this test:

https://github.com/storybookjs/storybook/blob/824fe5402f9e6f63c5a4b3474ee247ab69bb86c1/lib/api/src/tests/refs.test.js#L601:L601

and in these lines:

promise.then(
(r) => (r.ok ? r : (false as const)),
() => false as const
)

When you do a no-cors fetch, even if it works, ok is false it seems:

image

@tmeasday
Copy link
Member

@ndelangen there is an issue here because there is no way to tell if a mode: 'no-cors' request 404s or otherwise. We need to go over this again.

@tmeasday
Copy link
Member

I suspect the obvious solution is to add CORS headers to the dev server.

@TechieQian
Copy link

TechieQian commented Aug 15, 2020

I built storybook static and served the assets from a cors enabled python http server.

I was able to get the right response headers (Access-Control-Allow-Origin: *).

But I was still getting a cors issue for stories.json. I actually don't see any stories.json being generated. Is this a different issue?

@TechieQian
Copy link

Thanks it works now! I think it would be beneficial to add npx sb extract to composition documentations. I've never used chromatic so stories.json is new to me.

@ndelangen
Copy link
Member

ndelangen commented Aug 17, 2020

there is no way to tell if a mode: 'no-cors' request 404s or otherwise. We need to go over this again.

if there's no method to determine if a no-cors request succeeded of failed we can remove that check entirely, but we're left with a bug where if the composed storybook 404's it will just be in a pending state forever.

@basher
Copy link

basher commented Aug 17, 2020

I get the same CORS error while trying out composition for the first time.

I'm using @storybook/html": "^6.0.4".

I get 200 OK response for both stories.json and iframe.html.

Here's a screenshot of my response:

storybook-composition-response-payload

I've highlighted the empty HTML storybook in the left menu, and the response which shows what should be displayed in the story iframe.


Question:
Before trying composition, I was using standalone Storybook to preview my HTML stories, because I use Parcel bundler rather than Webpack.

i.e. I ran npm run storybook -- --preview-url=http://localhost:1337/iframe.html to view my HTML (with Parcel) stories.

Is Storybook composition a replacement for standalone?

@ndelangen
Copy link
Member

related:
#11783

@ndelangen
Copy link
Member

ndelangen commented Aug 17, 2020

I suspect the obvious solution is to add CORS headers to the dev server.

Should be easy enough to do!

@tmeasday
Copy link
Member

tmeasday commented Aug 17, 2020

Mode stories.json w/ credentials stories.json no credentials iframe.html no cors iframe.html w/ credentials iframe.html no credentials iframe.html from node
Chromatic(public)
Chromatic (private) 403 403 403
Netlify 404
Netlify w/ stories.json
SB6 dev mode 404 404
SB5 dev mode
Broken ref 404

@ndelangen
Copy link
Member

PR is open, with a fix

@shilman
Copy link
Member

shilman commented Aug 20, 2020

Crikey!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.0.14 containing PR #12085 that references this issue. Upgrade today to try it out!

Closing this issue. Please re-open if you think there's still more to do.

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

No branches or pull requests

6 participants