Storybook: Experiencing some CORS issue in `v6.0.0` while using storybook composition feature.

Created on 11 Aug 2020  ยท  15Comments  ยท  Source: storybookjs/storybook

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 https://github.com/storybookjs/storybook/issues/9311#issuecomment-671426067_

composition question / support tracked

Most helpful comment

PR is open, with a fix

All 15 comments

@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?

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

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

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:

https://github.com/storybookjs/storybook/blob/824fe5402f9e6f63c5a4b3474ee247ab69bb86c1/lib/api/src/modules/refs.ts#L68-L71

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

image

@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.

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

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?

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.

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.

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?

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

Should be easy enough to do!

| 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 |

PR is open, with a fix

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hansthinhle picture hansthinhle  ยท  57Comments

Olian04 picture Olian04  ยท  78Comments

moimikey picture moimikey  ยท  67Comments

tycho01 picture tycho01  ยท  76Comments

joeruello picture joeruello  ยท  79Comments