Skip to content

Conversation

@ndelangen
Copy link
Member

@ndelangen ndelangen commented Sep 19, 2025

What I did

I removed the core package exports that have been renamed.

storybook/internal/theming should not be used, please use storybook/theming.
storybook/internal/theming/create should not be used, please use storybook/theming/create.
storybook/internal/manager-api should not be used, please use storybook/manager-api.
storybook/internal/preview-api should not be used, please use storybook/preview-api.
storybook/internal/actions should not be used, please use storybook/actions.
storybook/internal/actions/decorator should not be used, please use storybook/actions/decorator.
storybook/internal/internal/highlight should not be used, please use storybook/highlight.
storybook/internal/internal/test should not be used, please use storybook/test.
storybook/internal/internal/viewport should not be used, please use storybook/viewport.

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

This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!

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 PR does not have a canary release associated. You can request a canary release of this pull request by mentioning the @storybookjs/core team here.

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

Summary by CodeRabbit

  • Refactor

    • Browser build now exposes only public modules; internal export entries removed.
    • Global module mappings adjusted to prefer public module keys.
  • Chores

    • Package exports cleaned to hide internal paths and reduce the public surface.
    • Import references updated across stories and addons to use public module packages.
    • Migration tooling updated to rewrite internal → public module imports.
  • Impact

    • Existing imports from internal module paths may break; switch to public exports. Public APIs and runtime behavior unchanged.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 19, 2025

Walkthrough

Prunes exports of internal entrypoints under storybook/internal/* from core package exports and browser export entries, removes the internal preview-api global mapping and its inclusion candidate, and updates source imports across core, addons, builders, and renderers to reference public packages (e.g., storybook/theming, storybook/preview-api, storybook/manager-api). No runtime API signatures or control flow changes were introduced.

Sequence Diagram(s)

No sequence diagram provided — these changes are import/export and global-mapping adjustments without modifications to runtime control flow or new interaction sequences.

Possibly related PRs

Suggested labels

cleanup

Suggested reviewers

  • kasperpeulen
  • yannbf

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title "Cleanup: Remove duplicated entrypoints in core" succinctly and accurately summarizes the primary change: removing duplicated/renamed internal core entrypoints in favor of public entrypoints, which matches the PR objectives and the file-level changes (e.g., updates to code/core/package.json and build-config.ts). It is a short, single sentence that clearly communicates the intent and scope to a reviewer scanning history. The phrasing is specific enough to understand the primary change without unnecessary detail.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch norbert/cleanup-entrypoints-core

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

@ndelangen ndelangen self-assigned this Sep 19, 2025
@ndelangen ndelangen requested a review from JReinhold September 19, 2025 12:42
@ndelangen ndelangen added maintenance User-facing maintenance tasks core ci:normal labels Sep 19, 2025
@nx-cloud
Copy link

nx-cloud bot commented Sep 19, 2025

View your CI Pipeline Execution ↗ for commit 4fac215

Command Status Duration Result
nx run-many -t build --parallel=3 ✅ Succeeded 58s View ↗

☁️ Nx Cloud last updated this comment at 2025-09-23 10:36:23 UTC

Copy link
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: 0

🧹 Nitpick comments (1)
code/core/build-config.ts (1)

100-161: Ensure type declarations are emitted for these public subpaths

If BuildEntries doesn’t default to DTS for browser entries, explicitly enable it to avoid missing .d.ts in consumers.

Example (repeat where needed):

   {
     exportEntries: ['./actions'],
     entryPoint: './src/actions/index.ts',
+    dts: true,
   },
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 795e05c and bfccde4.

📒 Files selected for processing (2)
  • code/core/build-config.ts (2 hunks)
  • code/core/package.json (0 hunks)
💤 Files with no reviewable changes (1)
  • code/core/package.json
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-09-17T08:11:47.184Z
Learnt from: CR
PR: storybookjs/storybook#0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-09-17T08:11:47.184Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Group related mocks together

Applied to files:

  • code/core/build-config.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: normal
  • GitHub Check: Danger JS
  • GitHub Check: Core Unit Tests, windows-latest
🔇 Additional comments (2)
code/core/build-config.ts (2)

100-102: Confirm ‘test’ belongs under browser exports

If ./src/test includes any Node‑only deps, consider moving it to entries.node instead. Otherwise ensure it’s tree‑shaken so it doesn’t bloat runtime bundles.


100-123: No internal imports found in repo — add MIGRATION.md for external consumers

Repo-wide git/ripgrep searches for '@storybook/core/internal/*' and the listed subpaths returned no matches; removal appears safe inside this repo, but this is a breaking public change — add a MIGRATION.md mapping old→new subpaths and update docs/examples before publishing.

…book/internal/theming' across multiple components
Copy link
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: 1

🧹 Nitpick comments (4)
code/addons/pseudo-states/src/manager/PseudoStateTool.tsx (2)

41-47: Guard against undefined pseudo in toggleOption (prevents runtime crash).
Destructuring from possibly undefined throws; default to an empty object.

Apply:

-      const { [option]: value, ...rest } = pseudo;
+      const { [option]: value, ...rest } = (pseudo ?? {}) as Record<string, boolean>;

3-3: Consider switching to public components entrypoint.
If available, prefer storybook/components to avoid internal imports.

-import { Form, IconButton, TooltipLinkList, WithTooltip } from 'storybook/internal/components';
+import { Form, IconButton, TooltipLinkList, WithTooltip } from 'storybook/components';
code/addons/pseudo-states/src/stories/CSSAtRules.stories.tsx (1)

3-3: Verify core-events import; migrate to public path if supported.
Align with cleanup by avoiding internal.

-import { FORCE_REMOUNT } from 'storybook/internal/core-events';
+import { FORCE_REMOUNT } from 'storybook/core-events';
code/core/src/manager/components/layout/Layout.stories.tsx (1)

4-4: Verify router import; prefer public entrypoint if available.
If storybook/router is public here, switch to it.

-import { LocationProvider } from 'storybook/internal/router';
+import { LocationProvider } from 'storybook/router';
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bfccde4 and 61ee450.

📒 Files selected for processing (13)
  • code/addons/docs/src/blocks/components/TableOfContents.stories.tsx (1 hunks)
  • code/addons/pseudo-states/src/manager/PseudoStateTool.tsx (1 hunks)
  • code/addons/pseudo-states/src/stories/CSSAtRules.stories.tsx (1 hunks)
  • code/addons/vitest/src/components/SidebarContextMenu.tsx (1 hunks)
  • code/builders/builder-vite/src/constants.ts (0 hunks)
  • code/core/src/components/components/Button/Button.stories.tsx (1 hunks)
  • code/core/src/components/components/Form/Checkbox.tsx (1 hunks)
  • code/core/src/components/components/Form/Radio.tsx (1 hunks)
  • code/core/src/highlight/useHighlights.stories.tsx (1 hunks)
  • code/core/src/manager/components/layout/Layout.stories.tsx (1 hunks)
  • code/core/src/preview/globals/globals.ts (0 hunks)
  • code/core/src/preview/globals/runtime.ts (0 hunks)
  • code/renderers/react/template/stories/decorators.stories.tsx (1 hunks)
💤 Files with no reviewable changes (3)
  • code/core/src/preview/globals/globals.ts
  • code/builders/builder-vite/src/constants.ts
  • code/core/src/preview/globals/runtime.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: normal
  • GitHub Check: Core Unit Tests, windows-latest
🔇 Additional comments (11)
code/addons/pseudo-states/src/manager/PseudoStateTool.tsx (1)

8-8: LGTM: moved to public theming API.

code/addons/pseudo-states/src/stories/CSSAtRules.stories.tsx (1)

7-8: LGTM: preview API import updated to public entrypoint.

code/core/src/components/components/Form/Radio.tsx (1)

3-3: LGTM: theming import now from public path.

code/core/src/highlight/useHighlights.stories.tsx (1)

3-3: LGTM: useChannel moved to public preview-api.

code/core/src/components/components/Button/Button.stories.tsx (1)

5-6: LGTM: styled now from public theming.

code/addons/docs/src/blocks/components/TableOfContents.stories.tsx (1)

6-6: LGTM: styled import updated to public theming.

code/core/src/components/components/Form/Checkbox.tsx (1)

3-3: LGTM: theming import updated to public path.

code/core/src/manager/components/layout/Layout.stories.tsx (2)

9-9: LGTM: ManagerContext now from public manager-api.


1-1: Only intended internal entrypoints remain. Verified that imports for deprecated patterns—storybook/internal/theming, manager-api, preview-api, actions, highlight, test, and viewport—no longer appear, and the only storybook/internal/* entrypoints in use are core-events, components, and router as intentionally kept.

code/renderers/react/template/stories/decorators.stories.tsx (1)

6-6: LGTM! Import updated to public API.

The import has been correctly updated from the internal storybook/internal/preview-api to the public storybook/preview-api entrypoint, aligning with the PR's objective to remove internal API usage.

code/addons/vitest/src/components/SidebarContextMenu.tsx (1)

6-6: LGTM! Import updated to public API.

The API type import has been correctly updated from the internal storybook/internal/manager-api to the public storybook/manager-api entrypoint, consistent with the broader migration effort across the codebase.

import React from 'react';

import { type API } from 'storybook/internal/manager-api';
import type { API_HashEntry } from 'storybook/internal/types';
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

🧩 Analysis chain

Consider migrating API_HashEntry import to public API.

The API_HashEntry type is still being imported from storybook/internal/types. For consistency with the PR's goal to eliminate internal API usage, verify if this type is available through a public entrypoint.


🏁 Script executed:

#!/bin/bash
# Description: Check if API_HashEntry is available in public APIs

# Search for API_HashEntry export in public entrypoints
echo "Searching for API_HashEntry in public manager-api..."
rg -n "export.*API_HashEntry" --type=ts -g "!**/internal/**"

echo "Searching for API_HashEntry type definition..."
ast-grep --pattern 'export type API_HashEntry = $$$' 

echo "Checking current usage of API_HashEntry..."
rg -n "API_HashEntry" --type=ts -C2

Length of output: 12059


Replace internal API_HashEntry imports with the public manager-api type

API_HashEntry is defined in code/core/src/types/modules/api-stories.ts and is re‑exported by manager-api as HashEntry — replace imports from 'storybook/internal/types' with a public import (e.g. import type { HashEntry as API_HashEntry } from 'storybook/manager-api') in:

  • code/addons/vitest/src/components/SidebarContextMenu.tsx
  • code/addons/vitest/src/types.ts
  • code/addons/vitest/src/components/TestProviderRender.tsx
🤖 Prompt for AI Agents
In code/addons/vitest/src/components/SidebarContextMenu.tsx (line 4) and the
other affected files code/addons/vitest/src/types.ts and
code/addons/vitest/src/components/TestProviderRender.tsx, replace the internal
import "import type { API_HashEntry } from 'storybook/internal/types';" with the
public manager-api re-export by importing HashEntry from 'storybook/manager-api'
and aliasing it to API_HashEntry (for example: import type { HashEntry as
API_HashEntry } from 'storybook/manager-api'), ensuring the type names remain
the same where used.

@storybook-app-bot
Copy link

storybook-app-bot bot commented Sep 23, 2025

Package Benchmarks

Commit: 4fac215, ran on 23 September 2025 at 12:09:32 UTC

No significant changes detected, all good. 👏

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

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

Awesome @ndelangen 🙌

It looks like you've mitigated the problem through a combination of automigration AND also swapping out the old imports dynamically using esbuild.

I am good to merge this provided that we thoroughly test it before release. There are currently no manual testing instructions in the PR. I would propose the following tests:

  1. Install a third-party addon that uses the old and API (e.g. storybook-addon-test-codegen) and verify that it does not break
  2. Create a local addon in main.js that uses the old API and:
  • verify that it doesn't break if not automigrated
  • verify that it gets automigrated
  1. Create a local addon in a separate file that uses the old API and gets imported into main.js and:
  • verify that it doesn't break if not automigrated
  • verify that it gets automigrated

In addition, I would propose as part of the release process that we reach out to the top 5 community addons that use the old API and try to get them to update. This way we can consider removing the compatibility completely in a future major release if we want.

@ndelangen ndelangen marked this pull request as ready for review September 24, 2025 08:40
Copy link
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: 2

🧹 Nitpick comments (1)
code/lib/cli-storybook/src/automigrate/fixes/consolidated-imports.ts (1)

90-132: Consider triggering this fix when only internal entrypoints are present

The current check only activates when consolidated packages are found in package.json. Repos that only import storybook/internal/* (and none of the consolidated packages) won’t get migrated.

Two options:

  • Split the internal-entrypoints migration into its own Fix that always scans sources.
  • Or extend this check to also scan source files for storybook/internal/ imports and return a non-null result to trigger run.

I can draft a follow-up patch if you prefer the second approach.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 61ee450 and 4fac215.

📒 Files selected for processing (7)
  • code/core/build-config.ts (2 hunks)
  • code/core/package.json (0 hunks)
  • code/core/src/manager/components/layout/Layout.stories.tsx (2 hunks)
  • code/core/src/manager/globals/globals-module-info.ts (2 hunks)
  • code/core/src/preview/globals/globals.ts (1 hunks)
  • code/core/src/preview/globals/runtime.ts (0 hunks)
  • code/lib/cli-storybook/src/automigrate/fixes/consolidated-imports.ts (1 hunks)
💤 Files with no reviewable changes (2)
  • code/core/src/preview/globals/runtime.ts
  • code/core/package.json
🚧 Files skipped from review as they are similar to previous changes (2)
  • code/core/src/preview/globals/globals.ts
  • code/core/build-config.ts
🧰 Additional context used
🧠 Learnings (3)
📚 Learning: 2025-09-18T20:51:06.618Z
Learnt from: Sidnioulz
PR: storybookjs/storybook#32458
File: code/core/src/viewport/components/Tool.tsx:38-39
Timestamp: 2025-09-18T20:51:06.618Z
Learning: The useGlobals hook from storybook/manager-api returns a tuple where the third element (storyGlobals) is typed as Globals, not Globals | undefined. This means TypeScript guarantees it's always defined, making the `in` operator safe to use without additional null checks.

Applied to files:

  • code/core/src/manager/globals/globals-module-info.ts
📚 Learning: 2025-09-18T20:51:06.618Z
Learnt from: Sidnioulz
PR: storybookjs/storybook#32458
File: code/core/src/viewport/components/Tool.tsx:38-39
Timestamp: 2025-09-18T20:51:06.618Z
Learning: In viewport tool code, when using the `useGlobals` hook from storybook/manager-api, the third returned value `storyGlobals` is guaranteed by TypeScript to be defined (not undefined/null), making the `in` operator safe to use without additional null checks.

Applied to files:

  • code/core/src/manager/globals/globals-module-info.ts
📚 Learning: 2025-09-17T08:11:47.197Z
Learnt from: CR
PR: storybookjs/storybook#0
File: .cursor/rules/spy-mocking.mdc:0-0
Timestamp: 2025-09-17T08:11:47.197Z
Learning: Applies to **/*.test.{ts,tsx,js,jsx} : Document complex mock behaviors

Applied to files:

  • code/core/src/manager/components/layout/Layout.stories.tsx
🧬 Code graph analysis (1)
code/core/src/manager/globals/globals-module-info.ts (1)
code/core/src/preview/globals/globals.ts (1)
  • globalsNameReferenceMap (3-18)
🔇 Additional comments (4)
code/core/src/manager/components/layout/Layout.stories.tsx (2)

66-74: Mock for getCurrentStoryData looks correct

The mock shape and nested renderLabel are fine for stories using ManagerContext.

Please confirm Layout only relies on { id, name, renderLabel } from getCurrentStoryData; if it reads more fields, expand the mock accordingly.


4-4: Import from @storybook/router (public) — not storybook/router

No storybook/router entrypoint was found; MIGRATION.md maps @storybook/routerstorybook/internal/router. The repo currently imports storybook/internal/router in multiple places (e.g. code/core/src/manager/index.tsx, code/core/src/manager/components/layout/Layout.stories.tsx). If you want to migrate, change imports to @storybook/router and ensure the package/exports are available and update all usages accordingly.

Likely an incorrect or invalid review comment.

code/lib/cli-storybook/src/automigrate/fixes/consolidated-imports.ts (1)

150-161: Fix mappings to public entrypoints; several are no-ops and contradict the PR’s intent

Entries for actions/highlight/test/viewport currently map to internal paths (no-ops); map them to public entrypoints and add the internal/internal/* variants.

       {
         ...consolidatedPackages,
         'storybook/internal/manager-api': 'storybook/manager-api',
         'storybook/internal/preview-api': 'storybook/preview-api',
         'storybook/internal/theming': 'storybook/theming',
         'storybook/internal/theming/create': 'storybook/theming/create',
-        'storybook/internal/test': 'storybook/test',
-        'storybook/internal/actions': 'storybook/internal/actions',
-        'storybook/internal/actions/decorator': 'storybook/internal/actions/decorator',
-        'storybook/internal/highlight': 'storybook/internal/highlight',
-        'storybook/internal/viewport': 'storybook/internal/viewport',
+        'storybook/internal/test': 'storybook/test',
+        'storybook/internal/internal/test': 'storybook/test',
+        'storybook/internal/actions': 'storybook/actions',
+        'storybook/internal/actions/decorator': 'storybook/actions/decorator',
+        'storybook/internal/highlight': 'storybook/highlight',
+        'storybook/internal/internal/highlight': 'storybook/highlight',
+        'storybook/internal/viewport': 'storybook/viewport',
+        'storybook/internal/internal/viewport': 'storybook/viewport',
       },
code/core/src/manager/globals/globals-module-info.ts (1)

44-51: Add double-internal aliases for back-compat; consider avoiding the unsafe cast

A lot of legacy imports use storybook/internal/internal/* (see PR description). Currently only storybook/internal/* gets an alias; add the double-internal form too so manager externals still work. Also, casting the computed key to typeof key lies to the type system; consider widening the result type or merging in a separately typed alias map.

Apply this minimal addition for double-internal paths:

     if (duplicatedKeys.includes(key)) {
       acc[key.replace('storybook', 'storybook/internal') as typeof key] = {
         type: 'esm',
         varName: globalsNameReferenceMap[key],
         namedExports: Exports[key],
         defaultExport: true,
       };
+      // Back-compat for legacy "storybook/internal/internal/*" imports
+      acc[key.replace('storybook', 'storybook/internal/internal') as typeof key] = {
+        type: 'esm',
+        varName: globalsNameReferenceMap[key],
+        namedExports: Exports[key],
+        defaultExport: true,
+      };
     }

Optional, safer typing (outside the hunk): build base as the strict Record<keyof typeof globalsNameReferenceMap, ...>, then compute aliases in a separate Record<string, ModuleInfo> and spread them in; this avoids the cast on the index.

To confirm whether double-internal aliases are still needed in-repo or by addons:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants