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

Background is flashing when switching stories #17122

Closed
Mikilll94 opened this issue Jan 4, 2022 · 10 comments
Closed

Background is flashing when switching stories #17122

Mikilll94 opened this issue Jan 4, 2022 · 10 comments

Comments

@Mikilll94
Copy link

Mikilll94 commented Jan 4, 2022

Describe the bug
When switching stories, the background is flashing which is really annoying.

Screen Recording 2022-01-04 at 20 51 32

To Reproduce

https://github.com/Mikilll94/storybook-flash

System

Environment Info:

  System:
    OS: macOS 11.6.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
  Binaries:
    Node: 16.13.0 - /usr/local/bin/node
    Yarn: 1.22.15 - /usr/local/bin/yarn
    npm: 8.1.0 - /usr/local/bin/npm
  Browsers:
    Chrome: 96.0.4664.110
    Firefox: 95.0.2
    Safari: 14.1.2

Additional context
This flashing background behavior was not present in Storybook 6.4.0-beta.15. I don't know exactly which Storybook version introduced this annoying behavior.

@shilman
Copy link
Member

shilman commented Jan 5, 2022

Does this help? cc @yannbf #13711

@Mikilll94
Copy link
Author

@shilman
Yeah, this works. But this is not a solution. In my app there is only a black background and I don't want this transition effect by default when switching stories. I don't want to instruct developers to change something in Mac settings. And what if they are working on Windows?

I think this transition effect only makes sense when switching backgrounds, not when switching stories.

@buondevid
Copy link

buondevid commented Jan 13, 2022

Having the same problem... I have a default white background and when I switch stories it briefly goes to grey to become white right after. It's a bit annoying.

This is my solution at the moment if it can be useful for someone (just replace white with your final colour):

// main.js

module.exports = {
  /* fix Storybook background flashing, at least for our default color (white) */
  previewHead: (head) => `
    ${head}
    <style>
      body {
        background-color: white !important;
      }
    </style>
  `
}

The limitation is that it's just gonna avoid flashing with one colour. If you can choose multiple background colours in your Storybook, then when you switch it, it will go back flashing. But it fixes it for at least one colour, the default one.

Before (flashing)
Screen.Recording.2022-01-13.at.12.01.27.mov
After (no flashing)
Screen.Recording.2022-01-13.at.12.02.32.mov
Why it happens

It looks to me that the problem is the background-color declared on the iframe body which somehow gets loaded very fast or takes briefly precedence anyway for some CSS properties. Once you put something that gets loaded as fast or before it, it doesn't get in the way anymore.
Screenshot 2022-01-13 at 12 06 08

@Mikilll94
Copy link
Author

@shilman
Is it going to be fixed? For me it's a major blocker and I cannot update to the latest Storybook version.

You can also remove "needs triage".

@yannbf
Copy link
Member

yannbf commented Jan 17, 2022

I found the version which introduced the bug but I'm not sure what's causing it exactly:

https://github.com/storybookjs/storybook/releases/tag/v6.4.0-beta.33

@tmeasday @shilman do you think it could be related to the changes for the docs loading state?

@tmeasday
Copy link
Member

@yannbf I guess it is likely because the "story loading" spinner is ever so briefly appearing. Probably wouldn't be an issue (?) if there wasn't the animation when the background comes back -- is that right?

I don't really have good context on the backgrounds addon @yannbf but I wonder if there is some way to do this:

I think this transition effect only makes sense when switching backgrounds, not when switching stories.

@Axedyson
Copy link

Axedyson commented Feb 3, 2022

Here is a duplicate issue:
#17010

I have the exact same issue, take a look at my storybook library and switch components to see the bug in action:
https://619aa417876c17003a24f46a-hwutncibag.chromatic.com/?path=/story/button--primary

The repo for the code is here:
https://github.com/AndysonDK/syncbase

@dsk90it
Copy link

dsk90it commented Feb 7, 2022

I also found a workaround that flickering issue occurs due to transition property. By default storybook comes with transitioned background (Pls check attached screenshot).

Annotation 2022-02-07 134059

Solution : Turn off transition property for body element

Step 1. Add preview-body.html inside .storybook folder
Step 2. Inside preview-body.html override default CSS.

<!-- .storybook/preview-body.html -->
<style>
  body {
    transition: none !important;
    /* Add your custom background-color and color properties here it will reflect in all stories by default */
  }
</style>

Step 3. Start the dev server by disabling cache start-storybook --no-manager-cache to see the result. (After working run dev server with your regular script)

@Axedyson
Copy link

@dsk90it Thanks your workaround works for me! I'll be using this until this gets fixed

@shilman
Copy link
Member

shilman commented Mar 31, 2022

Hurrah!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.5.0-alpha.52 containing PR #17753 that references this issue. Upgrade today to the @next NPM tag to try it out!

npx sb upgrade --prerelease

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

@shilman shilman closed this as completed Mar 31, 2022
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

7 participants