[Bug]:切换故事时,Storybook背景 Flink

czq61nw1  于 3个月前  发布在  Flink
关注(0)|答案(1)|浏览(137)

描述bug

Hi @shilman,我正在使用Storybook V8.0.10和storybook-dark-mode v4.0.0
以下是当前的情况:在清除缓存后首次导航到一个故事时,屏幕会在深色模式和浅色模式之间 Flink 。然而,如果我之前访问过那个特定的故事,这种 Flink 行为就不会发生。
未命名_.May.9.2024.10_19.PM.webm

main.ts

import type { StorybookConfig } from '@storybook/react-vite';
import { mergeConfig } from 'vite';

const glob = require('glob');
const path = require('path');
const appDirectory = path.resolve(__dirname, '../');
const getStories = () =>
  glob.sync(
    `${appDirectory}/packages/**/*.@(stories.js|stories.jsx|stories.ts|stories.tsx)`,
    {
      ignore: `${appDirectory}/packages/**/dist/**/*.@(stories.js|stories.jsx|stories.ts|stories.tsx)`,
    }
  );

const config: StorybookConfig = {
  core: {},
  framework: {
    name: '@storybook/react-vite',
    options: {},
  },
  stories: getStories(),
  addons: [
    '@storybook/addon-links',
    '@storybook/addon-essentials',
    '@storybook/addon-a11y',
    '@storybook/addon-interactions',
    '@storybook/addon-coverage',
    'storybook-dark-mode',
  ],
  async viteFinal(storybookConfig) {
    return mergeConfig(storybookConfig, {
      resolve: {
        preserveSymlinks: true,
      },
      server: {
        fs: {
          allow: ['..'],
        },
        watch: {
          ignored: ['!**/node_modules/@banking-platform/**'],
        },
      },
      assetsInclude: ['**/*.md'],
    });
  },
  docs: {
    autodocs: true,
  },
};

export default config;

preview.jsx

import { create } from '@storybook/theming';

import Docs from '../../.storybook/docs';

import { createDarkTheme, createLightTheme } from '../../.storybook/theme';

import '../../.storybook/assets/stories.scss';
import '../../.storybook/assets/style.scss';

import ThemeDecorator from './theme-decorator';

const lightTheme = create({
  ...createLightTheme,
});

const darkTheme = create({
  ...createDarkTheme,
});

const customViewports = {
  mobile: {
    name: 'Mobile',
    styles: {
      width: '600px',
      height: '963px',
    },
  },
  tablet: {
    name: 'Tablet',
    styles: {
      width: '840px',
      height: '1194px',
    },
  },
};

const parameters = {
  backgrounds: {
    default: 'Surface',
    values: [
      {
        name: 'Background',
        value: 'var(--color-background-default)',
      },
      {
        name: 'Surface',
        value: 'var(--color-surface-default)',
      },
    ],
  },
  controls: {
    matchers: {
      color: /(background|color)$/i,
      date: /Date$/,
    },
  },
  options: {
    storySort: {
      order: ['Foundation', 'Actions', 'Inputs'],
    },
  },
  darkMode: {
    current: 'light',
    dark: darkTheme,
    light: lightTheme,
  },
  docs: {
    page: () => <Docs framework="react" />,
  },
  viewport: { viewports: customViewports },
};

const decorators = [
  (Story) => (
    <ThemeDecorator>
      <Story />
    </ThemeDecorator>
  ),
];

const preview = {
  parameters,
  decorators,
};

export default preview;

重现链接

N/A

重现步骤

  • 无响应*

系统

Storybook Environment Info:

  System:
    OS: Windows 11 10.0.22631
    CPU: (16) x64 AMD Ryzen 7 PRO 4750U with Radeon Graphics
  Binaries:
    Node: 20.9.0 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.22.22 - C:\Program Files (x86)\Yarn\bin\yarn.CMD <----- active
    npm: 10.1.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Chromium (127.0.2651.74)
  npmPackages:
    @storybook/addon-a11y: ^8.2.6 => 8.2.6
    @storybook/addon-actions: ^8.2.6 => 8.2.6
    @storybook/addon-coverage: ^1.0.4 => 1.0.4
    @storybook/addon-essentials: ^8.2.6 => 8.2.6
    @storybook/addon-interactions: ^8.2.6 => 8.2.6
    @storybook/addon-links: ^8.2.6 => 8.2.6
    @storybook/manager-api: ^8.2.6 => 8.2.6
    @storybook/react: ^8.2.6 => 8.2.6
    @storybook/react-vite: ^8.2.6 => 8.2.6
    @storybook/test: ^8.2.6 => 8.2.6
    @storybook/test-runner: ^0.19.1 => 0.19.1
    eslint-plugin-storybook: ^0.8.0 => 0.8.0
    storybook: ^8.2.6 => 8.2.6
    storybook-dark-mode: ^4.0.2 => 4.0.2

其他上下文

  • 无响应*
tag5nh1u

tag5nh1u1#

免责声明
由于信息是自动生成的,可能存在不准确的情况。
为了解决在切换故事时出现的 Flink 问题,您可以尝试以下步骤:

  1. 更新 preview.tsx:确保 backgrounds 参数设置正确,以避免与暗黑模式插件发生冲突。修改 preview.tsx 中的 parameters 对象,包括 backgrounds 选项:
export const parameters = {
  backgrounds: {
    default: 'light',
    values: [
      { name: 'light', value: '#ffffff' },
      { name: 'dark', value: '#000000' },
    ],
  },
  darkMode: {
    current: 'light',
    dark: darkTheme,
    light: lightTheme,
  },
  // other parameters...
};
  1. 检查 main.ts:确保 storybook-dark-mode 插件正确地列在 addons 数组中:
const config: StorybookConfig = {
  // other configurations...
  addons: [
    '@storybook/addon-links',
    '@storybook/addon-essentials',
    '@storybook/addon-a11y',
    '@storybook/addon-interactions',
    'storybook-dark-mode',
  ],
  // other configurations...
};
  1. 确保一致的主题应用:在 preview.tsx 中,确保主题在所有故事中被一致地应用。您可以使用装饰器将所有故事用主题提供者 Package 起来:
const decorators = [
  (Story) => (
    <ThemeDecorator>
      <Story />
    </ThemeDecorator>
  ),
];

export const preview = {
  parameters,
  decorators,
};

这些步骤应该有助于减轻在切换故事时出现的 Flink 问题。

参考资料

/.github/DISCUSSION_TEMPLATE/help.yml
/test-storybooks/server-kitchen-sink/stories/addons/backgrounds.stories.json
/.github/DISCUSSION_TEMPLATE/ideas.yml
/code/presets/server-webpack/src/lib/compiler/testfixtures/backgrounds.json
/code/.storybook
/docs/_snippets/storybook-backgrounds-addon-default-params.md
/code/lib/cli/src/automigrate/fixes/new-frameworks.ts
/.github/comments/invalid-link.md
/code/renderers/server/template/cli/button.stories.json
/code/frameworks/angular/src/builders/build-storybook/schema.json
/code/lib/cli/src/automigrate/fixes/mdx-to-csf.test.ts
/code/core/src/core-server/utils/mockdata/errors/NoMeta.stories.ts
/test-storybooks/external-docs/.storybook
/code/lib/cli/src/automigrate/fixes/vta.ts
/code/addons/onboarding/CHANGELOG.md
/code/core/src/manager/components/sidebar/Brand.tsx
/docs/_snippets/storybook-main-disable-addon.md
/code/lib/cli/src/automigrate/fixes/sb-binary.ts
/docs/_snippets/storybook-main-js-md-files.md
/code/core/src/server-errors.ts
/code/lib/cli/src/automigrate/fixes/cra5.ts
/code/addons/docs/template/stories/docspage
/code/addons/backgrounds/template/stories/parameters.stories.ts
/code/core/src/telemetry/storybook-metadata.test.ts
/code/lib/cli/src/automigrate/fixes/addon-postcss.ts

相关问题