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

head.html is not loaded in storyshots #894

Closed
shilman opened this issue Apr 15, 2017 · 24 comments
Closed

head.html is not loaded in storyshots #894

shilman opened this issue Apr 15, 2017 · 24 comments

Comments

@shilman
Copy link
Member

shilman commented Apr 15, 2017

Issue by eric-burel
Tuesday Apr 11, 2017 at 09:47 GMT
Originally opened as storybook-eol/storyshots#96


In v2.1.0, .storybook/head.html/ does not seem to be taken into account. My issue is that its where I load jQuery, which is mandatory for bootstrap to work (I found no other solution than using head.html to get Bootstrap working with webpack).
Edit: same issue with 3.1.1 so far, I am trying to find a solution.

@HBCharles
Copy link

I'm also having the issue with 4.5.0. Is there any solution to this ?

tmeasday added a commit to tmeasday/storybook that referenced this issue May 31, 2017
@tmeasday
Copy link
Member

Reproduced here: https://github.com/tmeasday/storybook/tree/issue-894

Note that (a) the tests fail in the test-cra app, but (b) the storybook runs without errors.

@shilman
Copy link
Member Author

shilman commented May 31, 2017

@tmeasday thanks for creating a repro. my understanding: head.html is loaded in the preview window's iframe. therefore it doesn't show up in the outer window.

Added the following head.html to create-react-app/getstorybook yields:

<style> body {  background: yellow; }</style>

storybook

@tmeasday
Copy link
Member

@shilman -- correct. It's just that storyshots doesn't respect that, so the environment a story renders in in the UI (the preview window) is different from how it is rendered in the test (with a simple renderer.create(..)), thus the errors.

@shilman
Copy link
Member Author

shilman commented May 31, 2017

@tmeasday oh sorry this is a storyshots issue. my misunderstanding!

@tmeasday
Copy link
Member

tmeasday commented Jun 1, 2017

Hmm, thinking about this some more, I'm not sure there is a good solution to the problem. Does any one have any good ideas?

@shilman shilman changed the title head.html is not loaded head.html is not loaded in storyshots Jun 2, 2017
@zeroasterisk
Copy link

see: 5c0eb41

it should work with either, but it's officially renamed to preview-head.html

@stale
Copy link

stale bot commented Nov 27, 2017

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 60 days. Thanks!

@stale stale bot added the inactive label Nov 27, 2017
@tmeasday
Copy link
Member

Looking at this again, I reckon the real "solution" here is to not put JS includes in preview-head.html.

I wonder if the problem (needing static includes) could be solved in some other way, like a require from .storybook/config?

@stale stale bot removed the inactive label Nov 28, 2017
@Hypnosphi
Copy link
Member

Hypnosphi commented Nov 28, 2017

You always can insert scripts dynamically:

const script = document.createElement('script')
script.src = "..."
document.head.appendChild(script)

You can even extract it into a helper function which would accept src string

@tmeasday
Copy link
Member

Perhaps @eric-burel or @HBCharles could confirm if the above technique, as posted by @Hypnosphi helps?

@stale
Copy link

stale bot commented Jan 12, 2018

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 60 days. Thanks!

@stale stale bot added the inactive label Jan 12, 2018
@johnend
Copy link

johnend commented Jan 14, 2018

Did anyone find a solution to this? I want to start using StoryBook as part of our front-end development workflow on Vue projects, but having done some testing tonight I have come across this problem.

Attempting to include:

<script defer src="../build/fontawesome-all.js"></script>

Within preview-head.html did not work, neither did including a script and dynamically attempting to reference the file, as below.

<script>
  const script = document.createElement('script')
  script.src = "../build/fontawesome-all.js"
  document.head.appendChild(script)
</script>

I'm simply getting 404s for both methods.

@stale stale bot removed the inactive label Jan 14, 2018
@tmeasday
Copy link
Member

@johnend -- did @Hypnosphi's solution work for you?

@johnend
Copy link

johnend commented Jan 14, 2018

Sorry just updated, posted too early.

@johnend
Copy link

johnend commented Jan 14, 2018

I'm wondering if it might be cross origin stuff going on due to the use of iFrames?

@Hypnosphi
Copy link
Member

You can try to add that code to config.js instead

@tmeasday
Copy link
Member

@johnend -- the preview-head.html file is not evaluated for storyshots at all (storyshots only runs your JS code, so it doesn't necessarily make sense to try and evaluate HTML code -- although we could with JSDOM perhaps).

So the solution as suggested by @Hypnosphi is to try to avoid including JS code in preview.head and instead put it in .storybook/config.js where possible.

@johnend
Copy link

johnend commented Jan 15, 2018

Ok so having done that, I'm still getting a 404 for the script for font awesome. Tag is being included in the head and is referencing the correct folder. Just updating to let you know.

@tmeasday
Copy link
Member

@johnend is this in storyshots or regular storybook now?

@johnend
Copy link

johnend commented Jan 16, 2018

This is in regular storybook. Sorry I think I’ve posted my comments on the wrong issue. Didn’t realise storyshots was an add on and not just the iframe for the components.

@tmeasday
Copy link
Member

tmeasday commented Jan 16, 2018 via email

@stale
Copy link

stale bot commented Mar 2, 2018

Hi everyone! Seems like there hasn't been much going on in this issue lately. If there are still questions, comments, or bugs, please feel free to continue the discussion. Unfortunately, we don't have time to get to every issue. We are always open to contributions so please send us a pull request if you would like to help. Inactive issues will be closed after 60 days. Thanks!

@stale stale bot added the inactive label Mar 2, 2018
@stale
Copy link

stale bot commented Mar 17, 2018

Hey there, it's me again! I am going close this issue to help our maintainers focus on the current development roadmap instead. If the issue mentioned is still a concern, please open a new ticket and mention this old one. Cheers and thanks for using Storybook!

@stale stale bot closed this as completed Mar 17, 2018
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

8 participants