Skip to content

Conversation

@Sidnioulz
Copy link
Member

@Sidnioulz Sidnioulz commented Dec 8, 2025

What I did

I noticed that the /project.json route has started serving our new NX monorepo project.json file. Jeppe correctly identified that this is caused by Vite Dev Server's serving of local files. The route handler was set up after Vite's server was started, allowing the route to be intercepted.

Switching up the route order fixes the issue.

Manual testing

Visit http://localhost:6006/project.json and inspect the content on the monorepo next vs on this branch.

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 publish.yml --field pr=<PR_NUMBER>

Summary by CodeRabbit

  • Refactor
    • Optimized server initialization by reorganizing when project metadata is loaded. Project information endpoints now initialize earlier during the startup sequence, enhancing initialization timing. This optimization can be disabled through configuration settings if needed.

✏️ Tip: You can customize this high-level summary in your review settings.

@Sidnioulz Sidnioulz requested a review from JReinhold December 8, 2025 15:43
@Sidnioulz Sidnioulz added bug maintenance User-facing maintenance tasks ci:normal and removed maintenance User-facing maintenance tasks labels Dec 8, 2025
@nx-cloud
Copy link

nx-cloud bot commented Dec 8, 2025

View your CI Pipeline Execution ↗ for commit fada00e

Command Status Duration Result
nx run-many -t compile,check,knip,test,pretty-d... ✅ Succeeded 11m 41s View ↗

☁️ Nx Cloud last updated this comment at 2025-12-09 08:54:01 UTC

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 8, 2025

📝 Walkthrough

Walkthrough

The changes relocate the metadata initialization logic from the doTelemetry phase to an earlier bootstrap stage in the dev server. The useStorybookMetadata function is now called before the Vite Dev Server starts, ensuring the /project.json route is available immediately unless explicitly disabled via core.disableProjectJson.

Changes

Cohort / File(s) Summary
Metadata initialization relocation
code/core/src/core-server/dev-server.ts
Added import of useStorybookMetadata from ./utils/metadata and introduced an early bootstrap block that conditionally invokes useStorybookMetadata(app, options.configDir) prior to Vite Dev Server initialization, guarded by !core?.disableProjectJson check.
Metadata cleanup
code/core/src/core-server/utils/doTelemetry.ts
Removed import of useStorybookMetadata and deleted the corresponding conditional invocation that was previously executed within the doTelemetry phase.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

  • Straightforward code relocation with identical logic moved between two files
  • Consistent pattern of removal and addition with no functional logic changes
  • Single conditional guard maintained across the change
✨ Finishing touches
  • 📝 Generate docstrings

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

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/src/core-server/dev-server.ts (1)

84-88: Early /project.json bootstrap correctly precedes builder/Vite middleware; Biome “hook” error is a false positive

Registering useStorybookMetadata(app, options.configDir) before managerBuilder.start / previewBuilder.start should ensure the /project.json route is mounted before any Vite/local‑FS middleware, which aligns with the PR’s goal and preserves the core.disableProjectJson flag semantics. The Biome useHookAtTopLevel warning here is a false positive: this is server code and useStorybookMetadata is not a React hook constrained by render order. If that lint is blocking, consider either scoping the rule away from server files or adding an inline ignore just above this call.

Example (only if you decide to suppress locally):

// biome-ignore lint/correctness/useHookAtTopLevel: server-side util, not a React hook
if (!core?.disableProjectJson) {
  useStorybookMetadata(app, options.configDir);
}
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9548e92 and 16f2887.

📒 Files selected for processing (2)
  • code/core/src/core-server/dev-server.ts (2 hunks)
  • code/core/src/core-server/utils/doTelemetry.ts (0 hunks)
💤 Files with no reviewable changes (1)
  • code/core/src/core-server/utils/doTelemetry.ts
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{js,jsx,json,html,ts,tsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Use ESLint and Prettier configurations that are enforced in the codebase

Files:

  • code/core/src/core-server/dev-server.ts
**/*.{ts,tsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Enable TypeScript strict mode

Files:

  • code/core/src/core-server/dev-server.ts
code/**/*.{ts,tsx,js,jsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

code/**/*.{ts,tsx,js,jsx,mjs}: Use server-side logger from 'storybook/internal/node-logger' for Node.js code
Use client-side logger from 'storybook/internal/client-logger' for browser code
Do not use console.log, console.warn, or console.error directly unless in isolated files where importing loggers would significantly increase bundle size

Files:

  • code/core/src/core-server/dev-server.ts
code/**/*.{ts,tsx,js,jsx}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

Export functions that need to be tested from their modules

Files:

  • code/core/src/core-server/dev-server.ts
code/**/*.{js,jsx,json,html,ts,tsx,mjs}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

code/**/*.{js,jsx,json,html,ts,tsx,mjs}: Run Prettier with --write flag to format code before committing
Run ESLint with yarn lint:js:cmd to check for linting issues and fix errors before committing

Files:

  • code/core/src/core-server/dev-server.ts
🧠 Learnings (4)
📚 Learning: 2025-11-28T14:50:24.889Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-28T14:50:24.889Z
Learning: Applies to code/**/*.{ts,tsx,js,jsx,mjs} : Use server-side logger from 'storybook/internal/node-logger' for Node.js code

Applied to files:

  • code/core/src/core-server/dev-server.ts
📚 Learning: 2025-09-24T09:39:39.233Z
Learnt from: ndelangen
Repo: storybookjs/storybook PR: 32507
File: code/core/src/manager/globals/globals-module-info.ts:25-33
Timestamp: 2025-09-24T09:39:39.233Z
Learning: In Storybook, storybook/actions/decorator is a preview-only entrypoint and should not be included in manager globals configuration. The duplicatedKeys array in code/core/src/manager/globals/globals-module-info.ts is specifically for manager-side externalization, not preview entrypoints.

Applied to files:

  • code/core/src/core-server/dev-server.ts
📚 Learning: 2025-11-28T14:50:24.889Z
Learnt from: CR
Repo: storybookjs/storybook PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-28T14:50:24.889Z
Learning: Applies to code/**/*.{ts,tsx,js,jsx,mjs} : Use client-side logger from 'storybook/internal/client-logger' for browser code

Applied to files:

  • code/core/src/core-server/dev-server.ts
📚 Learning: 2025-11-05T09:38:47.712Z
Learnt from: Sidnioulz
Repo: storybookjs/storybook PR: 32458
File: code/core/src/components/components/Select/Select.tsx:200-204
Timestamp: 2025-11-05T09:38:47.712Z
Learning: Repo: storybookjs/storybook — Guidance: Until Storybook 11 is released, do not suggest using React.useId anywhere (e.g., in code/core/src/components/components/Select/Select.tsx) to maintain compatibility with React 17 runtimes. Prefer advising: accept a caller-provided props.id and, if needed, generate a client-only fallback id to minimize SSR hydration issues — but avoid useId. Resume prompting for useId after Storybook 11.

Applied to files:

  • code/core/src/core-server/dev-server.ts
🪛 Biome (2.1.2)
code/core/src/core-server/dev-server.ts

[error] 87-87: This hook is being called conditionally, but all hooks must be called in the exact same order in every component render.

For React to preserve state between calls, hooks needs to be called unconditionally and always in the same order.
See https://reactjs.org/docs/hooks-rules.html#only-call-hooks-at-the-top-level

(lint/correctness/useHookAtTopLevel)

⏰ 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: nx
  • GitHub Check: Core Unit Tests, windows-latest
🔇 Additional comments (1)
code/core/src/core-server/dev-server.ts (1)

20-20: Importing useStorybookMetadata here is consistent with the new bootstrap flow

The import from ./utils/metadata matches the new early usage in this module and the previous usage that was removed from doTelemetry, so the dependency wiring looks correct.

Copy link
Contributor

@JReinhold JReinhold left a comment

Choose a reason for hiding this comment

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

@Sidnioulz
Copy link
Member Author

Feel free to merge if CI passes, @JReinhold ! I don't have merge permission

@JReinhold JReinhold merged commit ac6d0a9 into next Dec 9, 2025
67 of 68 checks passed
@JReinhold JReinhold deleted the sidnioulz/fix-project-json-nx-monorepo-conflict branch December 9, 2025 15:54
@github-actions github-actions bot mentioned this pull request Dec 9, 2025
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants