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

Initial docs page renders twice, leading to first render not being cleaned up properly #17214

Closed
tmeasday opened this issue Jan 12, 2022 · 2 comments

Comments

@tmeasday
Copy link
Member

tmeasday commented Jan 12, 2022

Describe the bug

  1. Create a v7 store repro with the CLI template: e.g. https://github.com/tmeasday/sb-17214
  2. Visit the default URL (no story specified)
  3. Go to the second story (Button:Primary)
  4. Change an arg
  5. Notice the initial docs only story is rendered

Explanation of bug

The issue is that with the async story loading the following sequence of events happens:

  1. SB loads, no story specified,
  2. Preview picks first story and:
    a. emits storySpecified event
    b. starts rendering
  3. Rendering is async as the story must be loaded (v7 store) -- renderSelection() function is running.
  4. Meanwhile, the manager emits setCurrentStory with the selected story (<- this bit is a bit weird but is existing behaviour in SB).
  5. Preview gets message from 4, and starts renderSelection() again
  6. Function checks if the story is unchanged, but as 3 hasn't finished yet, this.previousStory is not yet set.
  7. So the docs is rendered a second time, setting up handlers twice
  8. When you browse away from docs, the first set of handlers are not torn down.
@tmeasday
Copy link
Member Author

@ghengeveld talked about this a bit more with @shilman and realised the issue is actually very similar to issues we've faced with the render cycle. A summary of the issue is: What guarantees do we make if a setCurrentStory is received while the previous render process is still ongoing?

There are a few async steps in the "render process" that are relevant:

  1. loading the CSF file (this issue)
  2. cleaning up the previous render (can be async if we need to cancel a play function)
  3. running loaders
  4. rendering the story
  5. running the play function.

I believe we thought a bunch about what happens during steps 3-5 but not at all about steps 1-2. I'm wondering your thoughts -- should we just add them as render phases and handle them in a similar way with the abort controller? Or something else?

@shilman
Copy link
Member

shilman commented Mar 9, 2022

¡Ay Caramba!! I just released https://github.com/storybookjs/storybook/releases/tag/v6.5.0-alpha.47 containing PR #17598 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 9, 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

2 participants