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

[Bug]: Story redirects worked in v6 but don't work in v7 #24292

Closed
nerdyman opened this issue Sep 24, 2023 · 5 comments · Fixed by #24345
Closed

[Bug]: Story redirects worked in v6 but don't work in v7 #24292

nerdyman opened this issue Sep 24, 2023 · 5 comments · Fixed by #24345
Assignees

Comments

@nerdyman
Copy link

nerdyman commented Sep 24, 2023

Describe the bug

Automatic redirects to the first story within a section worked in Storybook v6 but don't work in v7.

Examples:

I found the redirect really useful because it allowed me to link to general sections in static documentation (e.g. README.md for npm) while also allowing me to change the story it would redirect to later without republishing the module. With the current behaviour I'd need to provide an absolute link and republish my modules to npm when I want to change the story which isn't ideal.

To Reproduce

https://github.com/nerdyman/storybook-redirects

pnpm i
# Run each SB v6 (:6006) and v7 (:7007).
pnpm run -r storybook

System

v6

Environment Info:

  System:
    OS: macOS 13.5.2
    CPU: (8) arm64 Apple M1 Pro
  Binaries:
    Node: 20.6.1 - ~/Library/Caches/fnm_multishells/39503_1695570534353/bin/node
    npm: 9.8.1 - ~/Library/Caches/fnm_multishells/39503_1695570534353/bin/npm
  Browsers:
    Chrome: 116.0.5845.187
    Safari: 16.6
  npmPackages:
    @storybook/addon-essentials: ^6.5.16 => 6.5.16 
    @storybook/addon-interactions: ^6.5.16 => 6.5.16 
    @storybook/addon-links: ^6.5.16 => 6.5.16 
    @storybook/react: ^6.5.16 => 6.5.16 

v7

Environment Info:

  System:
    OS: macOS 13.5.2
    CPU: (8) arm64 Apple M1 Pro
  Binaries:
    Node: 20.6.1 - ~/Library/Caches/fnm_multishells/38611_1695569813857/bin/node
    npm: 9.8.1 - ~/Library/Caches/fnm_multishells/38611_1695569813857/bin/npm
  Browsers:
    Chrome: 116.0.5845.187
    Safari: 16.6
  npmPackages:
    @storybook/addon-essentials: ^7.4.4 => 7.4.4 
    @storybook/addon-interactions: ^7.4.4 => 7.4.4 
    @storybook/addon-links: ^7.4.4 => 7.4.4 
    @storybook/addon-onboarding: ^1.0.8 => 1.0.8 
    @storybook/blocks: ^7.4.4 => 7.4.4 
    @storybook/react: ^7.4.4 => 7.4.4 
    @storybook/react-vite: ^7.4.4 => 7.4.4 
    @storybook/testing-library: ^0.2.1 => 0.2.1

Additional context

Have checked the docs and asked on Discord but haven't been able to get the redirect working in v7.

@nerdyman nerdyman changed the title [Bug]: Section redirects worked in v6 but don't work in v7 [Bug]: Story redirects worked in v6 but don't work in v7 Sep 25, 2023
@shilman
Copy link
Member

shilman commented Sep 25, 2023

@tmeasday thoughts? I think you updated the redirect in v7

@tmeasday
Copy link
Member

I think it was intended to work for sure, this is a bug. Does it fix it if you set the storyStoreV7 feature to false @nerdyman ?

@olamothe
Copy link

On my end, I am setting storyStoreV7 to false, and I get the issue with version 7.4.1

A temporary workaround I've implemented is to register an addon:

import {STORY_MISSING} from '@storybook/core-events';
import {addons} from '@storybook/manager-api';

addons.register('SELECT-FIRST-STORY-BY-DEFAULT-ONCE', (api) => {
  api.once(STORY_MISSING, () => {
    const currentId = api.getUrlState().storyId;
    if (!currentId) {
      return api.selectFirstStory();
    }
    api.selectStory(currentId);
  });
});

@nerdyman
Copy link
Author

@shilman @tmeasday Thanks for the quick reply! It doesn't work with storyStoreV7: false either unfortunately on SB 7.4.5.

Also thanks @olamothe! I'll give that a go in the meantime.

@tmeasday
Copy link
Member

tmeasday commented Oct 2, 2023

@ndelangen this behaviour was broken in this PR: https://github.com/storybookjs/storybook/pull/23307/files

The preview is emitting the right events (storySpecified and currentStoryWasSet with the right story id), but the manager overrides it with setCurrentStory for the portion of the id.

I guess we didn't take this use case into account. Should be possible to write an E2E test to ensure we don't regress again (after fixing).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

5 participants