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

Next.js: Make RSC portable-stories compatible #28756

Merged
merged 1 commit into from
Jul 31, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions code/frameworks/nextjs/src/portable-stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {

// ! ATTENTION: This needs to be a relative import so it gets prebundled. This is to avoid ESM issues in Nextjs + Jest setups
import { INTERNAL_DEFAULT_PROJECT_ANNOTATIONS as reactAnnotations } from '../../../renderers/react/src/portable-stories';
import * as rscAnnotations from '../../../renderers/react/src/entry-preview-rsc';
import * as nextJsAnnotations from './preview';

import type { ReactRenderer, Meta } from '@storybook/react';
Expand Down Expand Up @@ -46,6 +47,7 @@ export function setProjectAnnotations(
// This will not be necessary once we have auto preset loading
const defaultProjectAnnotations: ProjectAnnotations<ReactRenderer> = composeConfigs([
reactAnnotations,
rscAnnotations,
nextJsAnnotations,
]);

Expand Down
3 changes: 2 additions & 1 deletion code/renderers/react/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ export const previewAnnotations: PresetProperty<'previewAnnotations'> = async (
options
) => {
const docsConfig = await options.presets.apply('docs', {}, options);
const features = await options.presets.apply('features', {}, options);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Ensure features object is correctly populated to avoid potential issues with feature flags.

const docsEnabled = Object.keys(docsConfig).length > 0;
const result: string[] = [];

return result
.concat(input)
.concat([join(__dirname, 'entry-preview.mjs')])
.concat(docsEnabled ? [join(__dirname, 'entry-preview-docs.mjs')] : [])
.concat(FEATURES?.experimentalRSC ? [join(__dirname, 'entry-preview-rsc.mjs')] : []);
.concat(features?.experimentalRSC ? [join(__dirname, 'entry-preview-rsc.mjs')] : []);
};

/**
Expand Down