Skip to content

Commit

Permalink
Merge pull request #15375 from storybookjs/fix/csf3-feature-flag-webp…
Browse files Browse the repository at this point in the history
…ack5

CSF3: Genericize feature flagging and fix webpack5
  • Loading branch information
shilman committed Jun 28, 2021
1 parent ac7f832 commit 6ccbe53
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 22 deletions.
4 changes: 2 additions & 2 deletions lib/builder-webpack4/src/preview/iframe-webpack.config.ts
Expand Up @@ -64,7 +64,7 @@ export default async ({
presets,
typescriptOptions,
modern,
previewCsfV3,
features,
}: Options & Record<string, any>): Promise<Configuration> => {
const logLevel = await presets.apply('logLevel', undefined);
const frameworkOptions = await presets.apply(`${framework}Options`, {});
Expand Down Expand Up @@ -154,7 +154,7 @@ export default async ({
globals: {
LOGLEVEL: logLevel,
FRAMEWORK_OPTIONS: frameworkOptions,
PREVIEW_CSF_V3: previewCsfV3,
FEATURES: features,
},
headHtmlSnippet,
bodyHtmlSnippet,
Expand Down
2 changes: 2 additions & 0 deletions lib/builder-webpack5/src/preview/iframe-webpack.config.ts
Expand Up @@ -59,6 +59,7 @@ export default async ({
presets,
typescriptOptions,
modern,
features,
}: Options & Record<string, any>): Promise<Configuration> => {
const envs = await presets.apply<Record<string, string>>('env');
const logLevel = await presets.apply('logLevel', undefined);
Expand Down Expand Up @@ -153,6 +154,7 @@ export default async ({
globals: {
LOGLEVEL: logLevel,
FRAMEWORK_OPTIONS: frameworkOptions,
FEATURES: features,
},
headHtmlSnippet,
bodyHtmlSnippet,
Expand Down
6 changes: 4 additions & 2 deletions lib/core-client/src/preview/StoryRenderer.test.ts
Expand Up @@ -36,8 +36,10 @@ jest.mock('@storybook/client-logger', () => ({
},
}));

jest.mock('./csf3', () => ({
isCsf3Enabled: () => true,
jest.mock('global', () => ({
// @ts-ignore
...global,
FEATURES: { previewCsfV3: true },
}));

function prepareRenderer() {
Expand Down
5 changes: 2 additions & 3 deletions lib/core-client/src/preview/StoryRenderer.tsx
Expand Up @@ -11,9 +11,8 @@ import { StoryStore } from '@storybook/client-api';

import { NoDocs } from './NoDocs';
import { RenderStoryFunction, RenderContextWithoutStoryContext } from './types';
import { isCsf3Enabled } from './csf3';

const { document } = global;
const { document, FEATURES = {} } = global;

// We have "changed" story if this changes
interface RenderMetadata {
Expand Down Expand Up @@ -282,7 +281,7 @@ export class StoryRenderer {
const storyContext = await applyLoaders();
const storyFn = () => unboundStoryFn(storyContext);
await this.render({ ...context, storyContext, storyFn });
if (isCsf3Enabled() && !forceRender) {
if (FEATURES.previewCsfV3 && !forceRender) {
await runPlayFunction();
}
this.channel.emit(Events.STORY_RENDERED, id);
Expand Down
10 changes: 0 additions & 10 deletions lib/core-client/src/preview/csf3.ts

This file was deleted.

6 changes: 4 additions & 2 deletions lib/core-client/src/preview/normalizeStory.ts
@@ -1,8 +1,10 @@
import global from 'global';
import { logger } from '@storybook/client-logger';
import { storyNameFromExport, toId } from '@storybook/csf';
import dedent from 'ts-dedent';
import deprecate from 'util-deprecate';
import { isCsf3Enabled } from './csf3';

const { FEATURES = {} } = global;

const deprecatedStoryAnnotation = dedent`
CSF .story annotations deprecated; annotate story functions directly:
Expand Down Expand Up @@ -97,4 +99,4 @@ export const normalizeV3 = (key: string, storyExport: any, meta: any, globalRend
};
};

export const normalizeStory = isCsf3Enabled() ? normalizeV3 : normalizeV2;
export const normalizeStory = FEATURES.previewCsfV3 ? normalizeV3 : normalizeV2;
2 changes: 1 addition & 1 deletion lib/core-common/src/types.ts
Expand Up @@ -155,7 +155,7 @@ export interface BuilderOptions {
cache: FileSystemCache;
configDir: string;
docsMode: boolean;
previewCsfV3?: boolean;
features?: StorybookConfig['features'];
versionCheck?: VersionCheck;
releaseNotesData?: ReleaseNotesData;
disableWebpackDefaults?: boolean;
Expand Down
2 changes: 1 addition & 1 deletion lib/core-server/src/build-dev.ts
Expand Up @@ -78,7 +78,7 @@ export async function buildDevStandalone(options: CLIOptions & LoadOptions & Bui
const fullOptions: Options = {
...options,
presets,
previewCsfV3: features?.previewCsfV3,
features,
};

const { address, networkAddress, managerResult, previewResult } = await storybookDevServer(
Expand Down
2 changes: 1 addition & 1 deletion lib/core-server/src/build-static.ts
Expand Up @@ -79,7 +79,7 @@ export async function buildStaticStandalone(options: CLIOptions & LoadOptions &
const fullOptions: Options = {
...options,
presets,
previewCsfV3: features?.previewCsfV3,
features,
};

const core = await presets.apply<{ builder?: string }>('core');
Expand Down

0 comments on commit 6ccbe53

Please sign in to comment.