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: Refactor preview and deprecate story store #24926

Merged
merged 26 commits into from
Jan 15, 2024
Merged

Conversation

tmeasday
Copy link
Member

@tmeasday tmeasday commented Nov 21, 2023

Relates to #24926

Telescoping on #24658

What I did

Got rid of StoryStore initialization -- now we just create it when we have everything we need. The only reason we didn't before was for SSv6.

We can't get rid of the "initialization promise" concept entirely, because we still need to cope with receiving messages (like setCurrentStory) while the index is still loading. However, now it is isolated (and private) to the preview classes, leading to a simpler store and less code overall.

This breaks __STORYBOOK_STORY_STORE__ and we will need to remove that API also. In the meantime we've created a proxy object that recreates the old behaviour with a deprecation warning.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

core team members can create a canary release here or locally with gh workflow run --repo storybookjs/storybook canary-release-pr.yml --field pr=<PR_NUMBER>

@tmeasday tmeasday marked this pull request as ready for review November 21, 2023 06:16
@tmeasday tmeasday changed the title Move preview init parameters to constructor Move preview init parameters to constructor and simplify StoryStore Nov 21, 2023
@ndelangen
Copy link
Member

I'm left with these errors:

 FAIL  |lib/preview-api| src/modules/store/StoryStore.test.ts > StoryStore > raw > produces an array of stories
Error: warn: StoryStore.raw() is deprecated and will be removed in 9.0, please use extract() instead
 ❯ throwMessage ../../vitest-setup.ts:17:17
     15| const throwMessage = (type: any, message: any) => {
     16|   // eslint-disable-next-line local-rules/no-uncategorized-errors
     17|   const error = new Error(`${type}${message}`);
       |                 ^
     18|   if (!ignoreList.reduce((acc, item) => acc || item(error), false)) {
     19|     throw error;
 ❯ Console.throwWarning ../../vitest-setup.ts:22:40
 ❯ Object.warn ../client-logger/dist/index.js:59:15
 ❯ Module.<anonymous> ../client-logger/dist/index.js:78:22
 ❯ StoryStore.raw src/modules/store/StoryStore.ts:338:5
 ❯ src/modules/store/StoryStore.test.ts:643:20

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/3]⎯

 FAIL  |lib/preview-api| src/modules/preview-web/PreviewWeb.test.ts > PreviewWeb > initial selection > story entries > does not show error display if the render function throws IGNORED_EXCEPTION
ReferenceError: IGNORED_EXCEPTION is not defined
 ❯ src/modules/preview-web/PreviewWeb.test.ts:632:26
    630|         expect(mockChannel.emit).toHaveBeenCalledWith(
    631|           STORY_THREW_EXCEPTION,
    632|           serializeError(IGNORED_EXCEPTION)
       |                          ^
    633|         );
    634|         expect(preview.view.showErrorDisplay).not.toHaveBeenCalled();

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/3]⎯

 FAIL  |lib/preview-api| src/modules/preview-web/PreviewWeb.test.ts > PreviewWeb > onSetCurrentStory > when changing from docs viewMode to story > unmounts docs
AssertionError: expected "spy" to be called at least once
 ❯ src/modules/preview-web/PreviewWeb.test.ts:2475:38
    2473|         await waitForRender();
    2474| 
    2475|         expect(docsRenderer.unmount).toHaveBeenCalled();
       |                                      ^
    2476|       });
    2477| 

⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[3/3]⎯

 Test Files  2 failed | 205 passed | 4 skipped (211)
      Tests  3 failed | 2598 passed | 30 skipped (2631)
   Start at  14:08:10
   Duration  79.58s

Base automatically changed from norbert/remove-storystorev7 to next January 9, 2024 12:15
@tmeasday
Copy link
Member Author

tmeasday commented Jan 11, 2024

Update on this PR: because we don't create the story store immediately any more, the __STORYBOOK_STORY_STORE__ global is now created undefined.

This is a breaking change to an undocumented API that is fairly widely used, including by the a11y addon.

We could set the global when the store is created but this will likely be just as breaking as folks likely read it immediately in many cases.

The path forward here is to create a proxy object for the global that passes function calls through to the store when it's ready as well as advertising deprecation, and properly removing in 9.0.

MIGRATION.md Outdated Show resolved Hide resolved
Copy link
Contributor

github-actions bot commented Jan 13, 2024

Fails
🚫 PR is marked with "BREAKING CHANGE" label.

Generated by 🚫 dangerJS against 4084f37

@tmeasday tmeasday removed the maintenance User-facing maintenance tasks label Jan 14, 2024
@tmeasday tmeasday changed the title Move preview init parameters to constructor and simplify StoryStore Core: Refactor preview and deprecate story store Jan 14, 2024
@shilman shilman added the core label Jan 15, 2024
@shilman shilman merged commit c356639 into next Jan 15, 2024
59 of 64 checks passed
@shilman shilman deleted the tom/simplify-preview branch January 15, 2024 09:15
@github-actions github-actions bot mentioned this pull request Jan 15, 2024
27 tasks
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.

None yet

3 participants