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

Core: Add IS_STORYBOOK global variable #16676

Merged
merged 2 commits into from
Jan 17, 2022
Merged

Conversation

srmagura
Copy link
Contributor

@srmagura srmagura commented Nov 12, 2021

Issue: #16485.

What I did

Added a global variable to the preview window to enable user code to detect if it is running in Storybook. This was suggested in the discussion on #16379.

How to test

  • Is this testable with Jest or Chromatic screenshots?
  • Does this need a new example in the kitchen sink apps? NO
  • Does this need an update to the documentation?

If your answer is yes to any of these, please make sure to include it in your PR.

@nx-cloud
Copy link

nx-cloud bot commented Nov 12, 2021

☁️ Nx Cloud Report

CI ran the following commands for commit 12f44d7. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@@ -76,6 +76,9 @@ export function start<TFramework extends AnyFramework>(
// eslint-disable-next-line no-underscore-dangle
globalWindow.__STORYBOOK_PREVIEW__ = preview;
globalWindow.__STORYBOOK_STORY_STORE__ = preview.storyStore;

// To enable user code to detect if it is running in Storybook
globalWindow.IS_STORYBOOK = true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only gets executed in legacy 6.x mode, and not if you're using features.storyStoreV7

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shilman I see that now, thank you. Is it okay to just move my line of code above the if (FEATURES?.storyStoreV7)?

Yann directed me to this file but I am a bit confused because start.ts does basically nothing if StoryStoreV7 is enabled.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry missed this question first time around. I think moving this to the top of the file will work. you should also check if (globalWindow) ... (i'm not sure when it isn't set, but i'm sure the code is there for a reason)

@MichaelArestad MichaelArestad assigned ndelangen and unassigned yannbf Nov 22, 2021
@stale
Copy link

stale bot commented Jan 9, 2022

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 30 days. Thanks!

@stale stale bot added the inactive label Jan 9, 2022
@srmagura
Copy link
Contributor Author

srmagura commented Jan 9, 2022

Hey @shilman @yannbf, any thoughts on the question I asked earlier?

@stale stale bot removed the inactive label Jan 9, 2022
@srmagura srmagura requested a review from shilman January 14, 2022 15:04
@srmagura
Copy link
Contributor Author

@shilman I believe this is ready to merge. I saw some E2E tests failed but it seems unrelated to my change. Thanks.

@yannbf
Copy link
Member

yannbf commented Jan 14, 2022

Hey @srmagura thanks for this work! I'll make sure to properly test this out and merge on Monday the latest! In the meantime, could you rebase with latest next? Seems like your PR is introducing more changes than it was intended

This is to let user code detect if it is running in Storybook.
@srmagura
Copy link
Contributor Author

My bad, those changes were not intentional. It should be good now!

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Merging, thanks for your patience @srmagura and your contribution!!!

docs/faq.md Outdated Show resolved Hide resolved
@shilman shilman changed the title Add IS_STORYBOOK global variable Core: Add IS_STORYBOOK global variable Jan 17, 2022
@shilman shilman merged commit 1a99d9d into storybookjs:next Jan 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants