Skip to content

Core: Rename preview.ts to preview.tsx in generated projects#34396

Merged
Sidnioulz merged 9 commits into
nextfrom
agentic/rename-preview-to-tsx
Apr 3, 2026
Merged

Core: Rename preview.ts to preview.tsx in generated projects#34396
Sidnioulz merged 9 commits into
nextfrom
agentic/rename-preview-to-tsx

Conversation

@Sidnioulz
Copy link
Copy Markdown
Member

@Sidnioulz Sidnioulz commented Mar 30, 2026

What I did

Switched preview.ts to preview.tsx in new projects to help agents write JSX decorators without having to iterate over the file name or syntax errors when writing JSX into a JS file.

Checklist for Contributors

Testing

The changes in this PR are covered in the following automated tests:

  • stories
  • unit tests
  • integration tests
  • end-to-end tests

Manual testing

  • Go to repo
  • Create sandbox
  • Check sandbox runs and file is named preview.tsx

Documentation

  • Add or update documentation reflecting your changes
  • If you are deprecating/removing a feature, make sure to update
    MIGRATION.MD

Checklist for Maintainers

  • When this PR is ready for testing, make sure to add ci:normal, ci:merged or ci:daily GH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found in code/lib/cli-storybook/src/sandbox-templates.ts

  • Make sure this PR contains one of the labels below:

    Available labels
    • bug: Internal changes that fixes incorrect behavior.
    • maintenance: User-facing maintenance tasks.
    • dependencies: Upgrading (sometimes downgrading) dependencies.
    • build: Internal-facing build tooling & test updates. Will not show up in release changelog.
    • cleanup: Minor cleanup style change. Will not show up in release changelog.
    • documentation: Documentation only changes. Will not show up in release changelog.
    • feature request: Introducing a new feature.
    • BREAKING CHANGE: Changes that break compatibility in some way with current major version.
    • other: Changes that don't fit in the above categories.

🦋 Canary release

This pull request has been released as version 0.0.0-pr-34396-sha-69743144. Try it out in a new sandbox by running npx storybook@0.0.0-pr-34396-sha-69743144 sandbox or in an existing project with npx storybook@0.0.0-pr-34396-sha-69743144 upgrade.

More information
Published version 0.0.0-pr-34396-sha-69743144
Triggered by @Sidnioulz
Repository storybookjs/storybook
Branch agentic/rename-preview-to-tsx
Commit 69743144
Datetime Mon Mar 30 10:37:50 UTC 2026 (1774867070)
Workflow run 23740501397

To request a new release of this pull request, mention the @storybookjs/core team.

core team members can create a new canary release here or locally with gh workflow run --repo storybookjs/storybook publish.yml --field pr=34396

Summary by CodeRabbit

  • Documentation

    • Updated docs and examples to reference JSX/TSX-style Storybook preview configuration variants.
  • Tests

    • Aligned unit and end-to-end tests with the updated preview configuration conventions.
  • Chores

    • Updated the project configuration generator to emit preview configuration using JSX/TSX-appropriate variants.

@Sidnioulz Sidnioulz requested a review from yannbf March 30, 2026 09:58
@Sidnioulz Sidnioulz added the maintenance User-facing maintenance tasks label Mar 30, 2026
Copilot AI review requested due to automatic review settings March 30, 2026 09:58
@Sidnioulz Sidnioulz added the ci:daily Run the CI jobs that normally run in the daily job. label Mar 30, 2026
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Mar 30, 2026

View your CI Pipeline Execution ↗ for commit 15374c9

Command Status Duration Result
nx run-many -t compile,check,knip,test,lint,fmt... ✅ Succeeded 7m 32s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-03 15:34:17 UTC

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates Storybook’s project scaffolding/docs to use preview.tsx/preview.jsx (instead of preview.ts/preview.js) so generated projects can safely contain JSX in preview decorators without rename churn.

Changes:

  • Switch create-storybook’s generated preview config filename to .storybook/preview.tsx / .storybook/preview.jsx.
  • Update documentation pages and snippet metadata to reference the new preview filename(s).
  • Adjust a small set of tests/docs that referenced preview.ts.

Reviewed changes

Copilot reviewed 103 out of 103 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
docs/writing-tests/interaction-testing.mdx Updates references to the preview config filename in testing docs.
docs/writing-tests/integrations/stories-in-unit-tests.mdx Updates preview filename reference in unit-test integration docs.
docs/writing-tests/accessibility-testing.mdx Updates preview filename references for a11y configuration examples.
docs/writing-stories/tags.mdx Updates preview filename references for applying tags at project level.
docs/writing-stories/parameters.mdx Updates preview filename reference for global parameters.
docs/writing-stories/mocking-data-and-modules/mocking-modules.mdx Updates preview filename references for automocking guidance.
docs/writing-stories/decorators.mdx Updates preview filename reference for global decorators.
docs/writing-stories/args.mdx Updates preview filename reference for global args.
docs/writing-docs/code-panel.mdx Updates preview filename reference for enabling Code panel.
docs/writing-docs/autodocs.mdx Updates preview filename references in autodocs configuration guidance.
docs/get-started/setup.mdx Updates preview filename reference in initial setup guidance.
docs/get-started/frameworks/vue3-vite.mdx Updates preview filename references in Vue 3 + Vite setup docs.
docs/get-started/frameworks/nextjs.mdx Updates preview filename references in Next.js setup docs.
docs/get-started/frameworks/nextjs-vite.mdx Updates preview filename references in Next.js (Vite) setup docs.
docs/get-started/frameworks/angular.mdx Updates preview filename references in Angular setup docs.
docs/essentials/viewport.mdx Updates preview filename reference for viewport configuration.
docs/essentials/toolbars-and-globals.mdx Updates preview filename references for globals/globalTypes guidance.
docs/essentials/controls.mdx Updates preview filename references across Controls configuration docs.
docs/essentials/backgrounds.mdx Updates preview filename reference for backgrounds configuration.
docs/contribute/documentation/new-snippets.mdx Updates snippet contribution example filename to preview.tsx.
docs/configure/styling-and-css.mdx Updates preview filename references for global styling instructions.
docs/configure/story-rendering.mdx Updates preview filename reference in “running code for every story”.
docs/api/portable-stories/portable-stories-vitest.mdx Updates preview filename references in Vitest portable stories docs.
docs/api/portable-stories/portable-stories-playwright.mdx Updates preview filename references in Playwright portable stories docs.
docs/api/portable-stories/portable-stories-jest.mdx Updates preview filename references in Jest portable stories docs.
docs/api/parameters.mdx Updates preview filename references for project-level parameters.
docs/api/csf/csf-next.mdx Updates preview filename references in CSF Next docs.
docs/api/arg-types.mdx Updates preview filename references for global argTypes.
docs/_snippets/tags-in-preview.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/tags-autodocs-in-preview.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-with-styled-components-decorator.md Updates snippet filenames to preview.tsx/preview.jsx across renderers.
docs/_snippets/storybook-preview-with-ordered-pages.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-with-ordered-pages-and-wildcard.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-with-library-decorator.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-use-global-type.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-sort-function.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-register-language-globally.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-parameters-color-swatches.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-optout-inline.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-matching-argtypes.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-locales-globaltype.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-layout-param.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-import-global-styles.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-global-parameters.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-global-loader.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-global-decorator.md Updates snippet filenames to preview.tsx/preview.jsx in some sections.
docs/_snippets/storybook-preview-expanded-controls.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-enable-toc.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-empty-sort-object.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-docs-dark-theme.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-doc-blocks-controls-exclude-prop.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-custom-toc.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-custom-params.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-custom-elements-config.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-custom-code-renderer.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-custom-canvas.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-configure-globaltypes.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-compodoc-config.md Updates Angular snippet filename to preview.tsx.
docs/_snippets/storybook-preview-auto-docs-override-theme.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-auto-docs-override-mdx-container.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-auto-docs-custom-template-function.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-preview-auto-docs-custom-mdx-template.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-addons-preset-preview.md Updates addon preview snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-addon-themes-jsx-provider-decorator.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-addon-themes-data-attribute-decorator.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-addon-themes-classname-decorator.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/storybook-addon-controls-custom-matchers.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/shadow-dom-testing-library-in-preview.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/parameters-in-preview.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/parameters-docs-source-transform-in-preview.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/nextjs-styling-tailwind.md Updates Next.js styling snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/nextjs-styling-sass-preview.md Updates Next.js styling snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/nextjs-router-override-in-preview.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/nextjs-navigation-override-in-preview.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/nextjs-app-directory-in-preview.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/msw-addon-initialize.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/mock-context-container-global.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/initialize-library-in-preview.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/decorator-with-updateArgs.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/decorator-with-reactive-globals.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/decorator-parameterized-in-preview.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/code-panel-enable-in-preview.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/before-each-in-preview.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/before-all-in-preview.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/automock-register-spy.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/automock-register-mock-file.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/automock-register-full.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/args-in-preview.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/arg-types-in-preview.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/angular-add-compodoc.md Updates Angular snippet filename to preview.tsx.
docs/_snippets/addon-viewport-options-in-preview.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/addon-viewport-add-viewport-in-preview.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/addon-backgrounds-options-in-preview.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/addon-a11y-parameter-error-in-preview.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/addon-a11y-config-rulesets-in-preview.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/addon-a11y-config-in-preview.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/actions-spyon-basic-example.md Updates snippet filenames to preview.tsx/preview.jsx.
docs/_snippets/actions-filtering-example.md Updates snippet filenames to preview.tsx/preview.jsx.
code/lib/create-storybook/src/generators/configure.ts Changes generated preview config filename to .tsx/.jsx.
code/frameworks/angular/src/client/preview.ts Updates embedded example comment to reference preview.tsx.
code/e2e-tests/storybook-hooks.spec.ts Updates e2e test path to preview.tsx.
code/core/src/core-server/utils/get-new-story-file.test.ts Updates test fixture preview path to preview.tsx.
AGENTS.md Updates agent-facing architecture note to reference preview.tsx.
Comments suppressed due to low confidence (1)

code/lib/create-storybook/src/generators/configure.ts:118

  • configurePreview() now always targets preview.tsx/preview.jsx and only checks for an existing file at that exact path. This can create a duplicate preview file when a template or existing project already has preview.ts/preview.js (which findConfigFile() will prefer, since it searches ts/js before tsx/jsx). Consider detecting an existing preview config across all supported extensions (ts/js/tsx/jsx/mjs/cjs) and reusing that path, or only switching to tsx/jsx when generating a new file. Also ensure any templates/tsconfigs that explicitly include ./preview.ts are updated to match the generated filename.
  const previewConfigPath = `./${options.storybookConfigFolder}/preview.${isTypescript ? 'tsx' : 'jsx'}`;

  // If the framework template included a preview then we have nothing to do
  if (await pathExists(previewConfigPath)) {
    return { previewConfigPath };
  }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread docs/configure/story-rendering.mdx Outdated
Comment thread docs/_snippets/parameters-in-preview.md Outdated
Comment thread docs/_snippets/storybook-preview-use-global-type.md Outdated
Comment thread docs/_snippets/storybook-preview-with-library-decorator.md Outdated
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 30, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Updated Storybook preview entrypoint extensions across repo: generator now emits .storybook/preview.tsx/.jsx; docs, snippets, tests, and examples updated to reference the .tsx/.jsx preview filenames. No runtime API, exported signatures, or behavior changed.

Changes

Cohort / File(s) Summary
Generator & Tests
code/lib/create-storybook/src/generators/configure.ts, code/lib/create-storybook/src/generators/configure.test.ts
Generator now writes preview.tsx for TypeScript and preview.jsx for JavaScript; unit tests updated to expect the new output paths.
Core & E2E Tests
code/core/src/core-server/utils/get-new-story-file.test.ts, code/e2e-tests/storybook-hooks.spec.ts
Test fixtures/mocks and sandbox paths switched from .storybook/preview.ts to .storybook/preview.tsx to match preview entrypoint changes.
Framework Example
code/frameworks/angular/src/client/preview.ts
In-code documentation comment updated to reference .storybook/preview.tsx (no functional change).
Docs: Snippets (many)
docs/_snippets/*
All snippet code-fence filename metadata changed from .storybook/preview.ts/.js to .storybook/preview.tsx/.jsx; snippet bodies unchanged.
Docs: Prose & Guides
docs/api/*, docs/configure/*, docs/essentials/*, docs/get-started/*, docs/writing-*/*
Inline prose and example titles updated from `.storybook/preview.js
Misc Docs
AGENTS.md
Text updated to reference .storybook/preview.tsx as the Storybook preview entrypoint.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs


Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (4)
code/lib/create-storybook/src/generators/configure.ts (1)

113-118: ⚠️ Potential issue | 🟠 Major

Prevent duplicate preview configs when legacy preview.ts/js already exists.

Line 113 + Line 116 now only check preview.tsx/preview.jsx. In existing projects with preview.ts or preview.js, this will generate a second preview file instead of reusing the existing one, and resolution can still prefer the legacy file.

Proposed fix
-  const previewConfigPath = `./${options.storybookConfigFolder}/preview.${isTypescript ? 'tsx' : 'jsx'}`;
-
-  // If the framework template included a preview then we have nothing to do
-  if (await pathExists(previewConfigPath)) {
-    return { previewConfigPath };
-  }
+  const previewBasePath = `./${options.storybookConfigFolder}/preview`;
+  const preferredPreviewConfigPath = `${previewBasePath}.${isTypescript ? 'tsx' : 'jsx'}`;
+  const fallbackPreviewConfigPath = `${previewBasePath}.${isTypescript ? 'ts' : 'js'}`;
+
+  // If a preview file already exists (new or legacy extension), keep using it
+  if (await pathExists(preferredPreviewConfigPath)) {
+    return { previewConfigPath: preferredPreviewConfigPath };
+  }
+  if (await pathExists(fallbackPreviewConfigPath)) {
+    return { previewConfigPath: fallbackPreviewConfigPath };
+  }
-  await writeFile(previewConfigPath, preview, { encoding: 'utf8' });
-
-  return { previewConfigPath };
+  await writeFile(preferredPreviewConfigPath, preview, { encoding: 'utf8' });
+
+  return { previewConfigPath: preferredPreviewConfigPath };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@code/lib/create-storybook/src/generators/configure.ts` around lines 113 -
118, The current check only looks for preview.tsx/preview.jsx and can create
duplicates when a legacy preview.ts or preview.js already exists; update the
existence check in the configure generator to also look for legacy preview files
(preview.ts and preview.js) inside options.storybookConfigFolder and prefer an
existing legacy file by returning its path instead of creating a new
previewConfigPath; use the existing pathExists utility and the isTypescript flag
to build and check all four candidate filenames (preview.tsx, preview.jsx,
preview.ts, preview.js) and return the first one that exists (or keep
previewConfigPath if none exist).
docs/_snippets/nextjs-router-override-in-preview.md (1)

23-30: ⚠️ Potential issue | 🟠 Major

JS snippet contains TypeScript-only syntax.

The code fence is marked language="js" and filename=".storybook/preview.jsx" but includes import type (line 25) and type annotation const preview: Preview (line 30), which are TypeScript-only. Users copying this into a .jsx file will encounter syntax errors.

Fix
 ```js filename=".storybook/preview.jsx" renderer="react" language="js" tabTitle="CSF 3"
 // Replace your-framework with nextjs or nextjs-vite
-import type { Preview } from '@storybook/your-framework';
-
 // 👇 Must include the `.mock` portion of filename to have mocks typed correctly
 import { getRouter } from "@storybook/your-framework/router.mock";
 
-const preview: Preview = {
+const preview = {
   parameters: {
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/_snippets/nextjs-router-override-in-preview.md` around lines 23 - 30,
The snippet mixes TypeScript-only syntax into a JS example: remove the
TypeScript-specific import "import type { Preview } from
'@storybook/your-framework';" and drop the type annotation on the preview
variable ("const preview: Preview") so it becomes a plain JS declaration ("const
preview"). Keep the getRouter import ("import { getRouter } from
\"@storybook/your-framework/router.mock\"") and leave the code fence as JS/.jsx
so users can copy it into a .jsx file without syntax errors.
docs/_snippets/tags-autodocs-in-preview.md (1)

20-25: ⚠️ Potential issue | 🟡 Minor

Remove duplicated addonDocs import in the TS snippet.

This snippet currently redeclares addonDocs, which breaks TypeScript parsing for users copy/pasting it.

✂️ Proposed fix
 import { definePreview } from '@storybook/your-framework';
 import addonDocs from '@storybook/addon-docs';
-import addonDocs from '@storybook/addon-docs';
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/_snippets/tags-autodocs-in-preview.md` around lines 20 - 25, The snippet
contains a duplicated import of addonDocs which breaks TypeScript parsing;
remove the second duplicate import so addonDocs is only imported once in the
preview snippet (the lines importing addonDocs in the .storybook preview
example), leaving the other imports (e.g., definePreview) intact and ensuring
there is a single import statement for addonDocs.
docs/_snippets/nextjs-navigation-override-in-preview.md (1)

23-47: ⚠️ Potential issue | 🟠 Major

JS snippet uses TypeScript-only syntax and will fail as JavaScript.

In this language="js" block, import type and const preview: Preview are invalid JS. Please convert this block to plain JavaScript.

🛠️ Proposed fix
 ```js filename=".storybook/preview.jsx" renderer="react" language="js" tabTitle="CSF 3"
 // Replace your-framework with nextjs or nextjs-vite
-import type { Preview } from '@storybook/your-framework';
-
 // 👇 Must include the `.mock` portion of filename to have mocks typed correctly
 import { getRouter } from "@storybook/your-framework/navigation.mock";
 
-const preview: Preview = {
+const preview = {
   parameters: {
     nextjs: {
       // 👇 Override the default navigation properties
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/_snippets/nextjs-navigation-override-in-preview.md` around lines 23 -
47, The JS snippet contains TypeScript-only syntax; remove the type-only import
and the type annotation on the preview constant: delete "import type { Preview }
from '@storybook/your-framework';" and change "const preview: Preview = {" to
"const preview = {" while keeping the existing getRouter import from
"@storybook/your-framework/navigation.mock" and all parameter/navigation and
beforeEach code intact so the mocked router usage
(getRouter().push.mockImplementation) still works.
🧹 Nitpick comments (3)
docs/configure/styling-and-css.mdx (1)

19-19: Consider using the flexible extension pattern for consistency.

This line uses .storybook/preview.tsx while other documentation pages in this PR use .storybook/preview.jsx|tsx to accommodate both JavaScript and TypeScript projects. Consider updating to maintain consistency across the docs.

🔧 Suggested change for consistency
-  All Storybooks are pre-configured to recognize imports for CSS files. To add global CSS for all your stories, import it in [`.storybook/preview.tsx`](./index.mdx#configure-story-rendering). These files will be subject to HMR, so you can see your changes without restarting your Storybook server.
+  All Storybooks are pre-configured to recognize imports for CSS files. To add global CSS for all your stories, import it in [`.storybook/preview.jsx|tsx`](./index.mdx#configure-story-rendering). These files will be subject to HMR, so you can see your changes without restarting your Storybook server.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/configure/styling-and-css.mdx` at line 19, Update the documentation text
that currently references ".storybook/preview.tsx" to use the flexible extension
pattern ".storybook/preview.jsx|tsx" for consistency with other docs; locate the
occurrence of the literal string ".storybook/preview.tsx" in the
"styling-and-css.mdx" content and replace it with ".storybook/preview.jsx|tsx"
so the guidance covers both JavaScript and TypeScript projects.
docs/_snippets/parameters-in-preview.md (1)

1-1: Align JS snippet fence types with declared language.

Line 1 and Line 50 declare language="js" but use a ts fence. Using js fences here would keep rendering behavior consistent with the other JS snippets in this file.

Suggested doc-fence cleanup
-```ts filename=".storybook/preview.tsx" renderer="common" language="js" tabTitle="CSF 3"
+```js filename=".storybook/preview.jsx" renderer="common" language="js" tabTitle="CSF 3"
-```ts filename=".storybook/preview.tsx" renderer="react" language="js" tabTitle="CSF Next 🧪"
+```js filename=".storybook/preview.jsx" renderer="react" language="js" tabTitle="CSF Next 🧪"

Also applies to: 50-50

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/_snippets/parameters-in-preview.md` at line 1, Update the mismatched
code-fence metadata: change the opening triple-backtick fences that currently
use "ts filename='.storybook/preview.tsx' ... language='js' ..." to use a JS
fence and matching filename (e.g., "```js filename='.storybook/preview.jsx'
renderer='common' language='js' tabTitle='CSF 3'") and likewise for the second
block (replace the "ts" fence with "js" and .tsx filename with .jsx for the CSF
Next block). Ensure both occurrences (the CSF 3 and CSF Next blocks) have the
fence language set to js and the filename updated to .preview.jsx so the fence
type aligns with language="js".
docs/_snippets/storybook-preview-with-styled-components-decorator.md (1)

326-340: Duplicate CSF Next web-components TypeScript snippet appears twice.

This block duplicates the one at Line 310–324 with the same renderer, language, and content. Consider removing one copy to avoid duplicate docs output.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/_snippets/storybook-preview-with-styled-components-decorator.md` around
lines 326 - 340, Remove the duplicated CSF Next web-components TypeScript
snippet by keeping a single instance of the definePreview snippet (the block
that imports html from 'lit' and calls definePreview with decorators that use
story and globals to wrap story() in <theme-provider theme=${theme}>). Delete
the redundant identical code fence so only one snippet defining the
decorators/theme-provider behavior remains in the docs.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@code/frameworks/angular/src/client/preview.ts`:
- Line 36: Update the example comment to use the .ts extension and include the
missing default export: change the file reference to ".storybook/preview.ts",
keep the use of definePreview and the named export preview, and add an export
default preview; so that the module exports both the named const preview and a
default export (preview) to match consumers that import projectAnnotations as
the default; locate the example around the preview constant/definePreview usage.

In `@docs/api/portable-stories/portable-stories-jest.mdx`:
- Line 221: Update the project-level preview annotation reference to be
extension-agnostic by replacing the hardcoded `.storybook/preview.jsx` text with
`.storybook/preview.jsx|tsx` in the sentence that explains where project-level
annotations are defined (the sentence mentioning project-level annotations
coming from your .storybook preview file and addons); ensure this matches the
wording used earlier (around the examples on Line 205) so the docs cover both
JSX and TSX setups consistently.

In `@docs/api/portable-stories/portable-stories-playwright.mdx`:
- Line 168: The documentation line that currently mentions only
".storybook/preview.jsx" should be updated to consistently reference
".storybook/preview.jsx|tsx" to match earlier mentions; find the string
".storybook/preview.jsx" in portable-stories-playwright.mdx (the sentence about
project-level annotations) and replace it with ".storybook/preview.jsx|tsx" so
TypeScript projects are covered consistently alongside the other occurrences.

In `@docs/api/portable-stories/portable-stories-vitest.mdx`:
- Line 233: Update the documentation sentence that references the preview
filename so it reflects mixed JS/TS support: replace the lone
`.storybook/preview.jsx` mention with `.storybook/preview.jsx|tsx` so it matches
the rest of the page's convention and avoids implying JavaScript-only
configuration; edit the paragraph containing "project-level annotations are
those defined in your `.storybook/preview.jsx` file" to use the new
`.storybook/preview.jsx|tsx` text.

---

Outside diff comments:
In `@code/lib/create-storybook/src/generators/configure.ts`:
- Around line 113-118: The current check only looks for preview.tsx/preview.jsx
and can create duplicates when a legacy preview.ts or preview.js already exists;
update the existence check in the configure generator to also look for legacy
preview files (preview.ts and preview.js) inside options.storybookConfigFolder
and prefer an existing legacy file by returning its path instead of creating a
new previewConfigPath; use the existing pathExists utility and the isTypescript
flag to build and check all four candidate filenames (preview.tsx, preview.jsx,
preview.ts, preview.js) and return the first one that exists (or keep
previewConfigPath if none exist).

In `@docs/_snippets/nextjs-navigation-override-in-preview.md`:
- Around line 23-47: The JS snippet contains TypeScript-only syntax; remove the
type-only import and the type annotation on the preview constant: delete "import
type { Preview } from '@storybook/your-framework';" and change "const preview:
Preview = {" to "const preview = {" while keeping the existing getRouter import
from "@storybook/your-framework/navigation.mock" and all parameter/navigation
and beforeEach code intact so the mocked router usage
(getRouter().push.mockImplementation) still works.

In `@docs/_snippets/nextjs-router-override-in-preview.md`:
- Around line 23-30: The snippet mixes TypeScript-only syntax into a JS example:
remove the TypeScript-specific import "import type { Preview } from
'@storybook/your-framework';" and drop the type annotation on the preview
variable ("const preview: Preview") so it becomes a plain JS declaration ("const
preview"). Keep the getRouter import ("import { getRouter } from
\"@storybook/your-framework/router.mock\"") and leave the code fence as JS/.jsx
so users can copy it into a .jsx file without syntax errors.

In `@docs/_snippets/tags-autodocs-in-preview.md`:
- Around line 20-25: The snippet contains a duplicated import of addonDocs which
breaks TypeScript parsing; remove the second duplicate import so addonDocs is
only imported once in the preview snippet (the lines importing addonDocs in the
.storybook preview example), leaving the other imports (e.g., definePreview)
intact and ensuring there is a single import statement for addonDocs.

---

Nitpick comments:
In `@docs/_snippets/parameters-in-preview.md`:
- Line 1: Update the mismatched code-fence metadata: change the opening
triple-backtick fences that currently use "ts filename='.storybook/preview.tsx'
... language='js' ..." to use a JS fence and matching filename (e.g., "```js
filename='.storybook/preview.jsx' renderer='common' language='js' tabTitle='CSF
3'") and likewise for the second block (replace the "ts" fence with "js" and
.tsx filename with .jsx for the CSF Next block). Ensure both occurrences (the
CSF 3 and CSF Next blocks) have the fence language set to js and the filename
updated to .preview.jsx so the fence type aligns with language="js".

In `@docs/_snippets/storybook-preview-with-styled-components-decorator.md`:
- Around line 326-340: Remove the duplicated CSF Next web-components TypeScript
snippet by keeping a single instance of the definePreview snippet (the block
that imports html from 'lit' and calls definePreview with decorators that use
story and globals to wrap story() in <theme-provider theme=${theme}>). Delete
the redundant identical code fence so only one snippet defining the
decorators/theme-provider behavior remains in the docs.

In `@docs/configure/styling-and-css.mdx`:
- Line 19: Update the documentation text that currently references
".storybook/preview.tsx" to use the flexible extension pattern
".storybook/preview.jsx|tsx" for consistency with other docs; locate the
occurrence of the literal string ".storybook/preview.tsx" in the
"styling-and-css.mdx" content and replace it with ".storybook/preview.jsx|tsx"
so the guidance covers both JavaScript and TypeScript projects.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b16cc2d1-8672-4827-91b5-6e69056425a0

📥 Commits

Reviewing files that changed from the base of the PR and between 039eb6c and c78065d.

📒 Files selected for processing (103)
  • AGENTS.md
  • code/core/src/core-server/utils/get-new-story-file.test.ts
  • code/e2e-tests/storybook-hooks.spec.ts
  • code/frameworks/angular/src/client/preview.ts
  • code/lib/create-storybook/src/generators/configure.ts
  • docs/_snippets/actions-filtering-example.md
  • docs/_snippets/actions-spyon-basic-example.md
  • docs/_snippets/addon-a11y-config-in-preview.md
  • docs/_snippets/addon-a11y-config-rulesets-in-preview.md
  • docs/_snippets/addon-a11y-parameter-error-in-preview.md
  • docs/_snippets/addon-backgrounds-options-in-preview.md
  • docs/_snippets/addon-viewport-add-viewport-in-preview.md
  • docs/_snippets/addon-viewport-options-in-preview.md
  • docs/_snippets/angular-add-compodoc.md
  • docs/_snippets/arg-types-in-preview.md
  • docs/_snippets/args-in-preview.md
  • docs/_snippets/automock-register-full.md
  • docs/_snippets/automock-register-mock-file.md
  • docs/_snippets/automock-register-spy.md
  • docs/_snippets/before-all-in-preview.md
  • docs/_snippets/before-each-in-preview.md
  • docs/_snippets/code-panel-enable-in-preview.md
  • docs/_snippets/decorator-parameterized-in-preview.md
  • docs/_snippets/decorator-with-reactive-globals.md
  • docs/_snippets/decorator-with-updateArgs.md
  • docs/_snippets/initialize-library-in-preview.md
  • docs/_snippets/mock-context-container-global.md
  • docs/_snippets/msw-addon-initialize.md
  • docs/_snippets/nextjs-app-directory-in-preview.md
  • docs/_snippets/nextjs-navigation-override-in-preview.md
  • docs/_snippets/nextjs-router-override-in-preview.md
  • docs/_snippets/nextjs-styling-sass-preview.md
  • docs/_snippets/nextjs-styling-tailwind.md
  • docs/_snippets/parameters-docs-source-transform-in-preview.md
  • docs/_snippets/parameters-in-preview.md
  • docs/_snippets/shadow-dom-testing-library-in-preview.md
  • docs/_snippets/storybook-addon-controls-custom-matchers.md
  • docs/_snippets/storybook-addon-themes-classname-decorator.md
  • docs/_snippets/storybook-addon-themes-data-attribute-decorator.md
  • docs/_snippets/storybook-addon-themes-jsx-provider-decorator.md
  • docs/_snippets/storybook-addons-preset-preview.md
  • docs/_snippets/storybook-preview-auto-docs-custom-mdx-template.md
  • docs/_snippets/storybook-preview-auto-docs-custom-template-function.md
  • docs/_snippets/storybook-preview-auto-docs-override-mdx-container.md
  • docs/_snippets/storybook-preview-auto-docs-override-theme.md
  • docs/_snippets/storybook-preview-compodoc-config.md
  • docs/_snippets/storybook-preview-configure-globaltypes.md
  • docs/_snippets/storybook-preview-custom-canvas.md
  • docs/_snippets/storybook-preview-custom-code-renderer.md
  • docs/_snippets/storybook-preview-custom-elements-config.md
  • docs/_snippets/storybook-preview-custom-params.md
  • docs/_snippets/storybook-preview-custom-toc.md
  • docs/_snippets/storybook-preview-doc-blocks-controls-exclude-prop.md
  • docs/_snippets/storybook-preview-docs-dark-theme.md
  • docs/_snippets/storybook-preview-empty-sort-object.md
  • docs/_snippets/storybook-preview-enable-toc.md
  • docs/_snippets/storybook-preview-expanded-controls.md
  • docs/_snippets/storybook-preview-global-decorator.md
  • docs/_snippets/storybook-preview-global-loader.md
  • docs/_snippets/storybook-preview-global-parameters.md
  • docs/_snippets/storybook-preview-import-global-styles.md
  • docs/_snippets/storybook-preview-layout-param.md
  • docs/_snippets/storybook-preview-locales-globaltype.md
  • docs/_snippets/storybook-preview-matching-argtypes.md
  • docs/_snippets/storybook-preview-optout-inline.md
  • docs/_snippets/storybook-preview-parameters-color-swatches.md
  • docs/_snippets/storybook-preview-register-language-globally.md
  • docs/_snippets/storybook-preview-sort-function.md
  • docs/_snippets/storybook-preview-use-global-type.md
  • docs/_snippets/storybook-preview-with-library-decorator.md
  • docs/_snippets/storybook-preview-with-ordered-pages-and-wildcard.md
  • docs/_snippets/storybook-preview-with-ordered-pages.md
  • docs/_snippets/storybook-preview-with-styled-components-decorator.md
  • docs/_snippets/tags-autodocs-in-preview.md
  • docs/_snippets/tags-in-preview.md
  • docs/api/arg-types.mdx
  • docs/api/csf/csf-next.mdx
  • docs/api/parameters.mdx
  • docs/api/portable-stories/portable-stories-jest.mdx
  • docs/api/portable-stories/portable-stories-playwright.mdx
  • docs/api/portable-stories/portable-stories-vitest.mdx
  • docs/configure/story-rendering.mdx
  • docs/configure/styling-and-css.mdx
  • docs/contribute/documentation/new-snippets.mdx
  • docs/essentials/backgrounds.mdx
  • docs/essentials/controls.mdx
  • docs/essentials/toolbars-and-globals.mdx
  • docs/essentials/viewport.mdx
  • docs/get-started/frameworks/angular.mdx
  • docs/get-started/frameworks/nextjs-vite.mdx
  • docs/get-started/frameworks/nextjs.mdx
  • docs/get-started/frameworks/vue3-vite.mdx
  • docs/get-started/setup.mdx
  • docs/writing-docs/autodocs.mdx
  • docs/writing-docs/code-panel.mdx
  • docs/writing-stories/args.mdx
  • docs/writing-stories/decorators.mdx
  • docs/writing-stories/mocking-data-and-modules/mocking-modules.mdx
  • docs/writing-stories/parameters.mdx
  • docs/writing-stories/tags.mdx
  • docs/writing-tests/accessibility-testing.mdx
  • docs/writing-tests/integrations/stories-in-unit-tests.mdx
  • docs/writing-tests/interaction-testing.mdx

Comment thread code/frameworks/angular/src/client/preview.ts Outdated
Comment thread docs/api/portable-stories/portable-stories-jest.mdx Outdated
Comment thread docs/api/portable-stories/portable-stories-playwright.mdx Outdated
Comment thread docs/api/portable-stories/portable-stories-vitest.mdx Outdated
Copy link
Copy Markdown
Member

@yannbf yannbf left a comment

Choose a reason for hiding this comment

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

LGTM but I'd recommend making a canary and trying this out on an Angular project

@Sidnioulz Sidnioulz force-pushed the agentic/rename-preview-to-tsx branch from 2d8df40 to 3f711d0 Compare March 30, 2026 16:00
Copy link
Copy Markdown
Member Author

@Sidnioulz Sidnioulz left a comment

Choose a reason for hiding this comment

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

* [ ] Address main.* too

I realise we don't have main.tsx so there's much of a pressure to change main.ts patterns.

Comment thread docs/_snippets/decorator-parameterized-in-preview.md Outdated
Comment thread docs/api/portable-stories/portable-stories-vitest.mdx Outdated
Comment thread docs/api/parameters.mdx
Comment thread docs/api/portable-stories/portable-stories-jest.mdx
Comment thread docs/_snippets/decorator-parameterized-in-preview.md Outdated
Comment thread docs/_snippets/storybook-preview-global-decorator.md Outdated
Comment thread docs/_snippets/storybook-preview-with-styled-components-decorator.md Outdated
Comment thread docs/_snippets/storybook-preview-with-styled-components-decorator.md Outdated
@storybook-app-bot
Copy link
Copy Markdown

storybook-app-bot Bot commented Apr 3, 2026

Package Benchmarks

Commit: 15374c9, ran on 3 April 2026 at 15:37:43 UTC

No significant changes detected, all good. 👏

@Sidnioulz Sidnioulz force-pushed the agentic/rename-preview-to-tsx branch from 1ecec6c to 787bd14 Compare April 3, 2026 08:59
@Sidnioulz Sidnioulz assigned kylegach and unassigned yannbf Apr 3, 2026
@Sidnioulz Sidnioulz merged commit 75fa10a into next Apr 3, 2026
114 of 124 checks passed
@Sidnioulz Sidnioulz deleted the agentic/rename-preview-to-tsx branch April 3, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:normal maintenance User-facing maintenance tasks

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants