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

CSF3: Fix webpack5 feature flagging & genericize flagging #15375

Merged
merged 1 commit into from Jun 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -60,6 +60,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 @@ -154,6 +155,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