Skip to content

Conversation

@JReinhold
Copy link
Contributor

@JReinhold JReinhold commented Jun 16, 2025

Closes #31709

What I did

  1. Changed the global settings logic to only log a warning if it can't save the file, instead of throwing an error
  2. Don't run global settings logic in CI
  3. Added a utility to more resiliently check for optional, boolean environment variables, and a shortcut isCI that uses that.

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>

Greptile Summary

Improves error handling in read-only environments by replacing error throwing with warning logs and adding robust environment variable handling utilities.

  • Added new utilities isCI and optionalEnvToBoolean in code/core/src/common/utils/envs.ts for consistent environment detection
  • Modified code/core/src/telemetry/storybook-metadata.ts to skip global settings in CI environments
  • Updated code/lib/cli-storybook/src/bin/index.ts to use warning logs instead of throwing errors when saving fails
  • Fixed boolean logic in sandbox initiation to correctly disable dev mode in CI environments

@JReinhold JReinhold requested review from shilman and tmeasday June 16, 2025 08:33
@JReinhold JReinhold self-assigned this Jun 16, 2025
@JReinhold JReinhold added bug ci: do not merge cli telemetry ci:normal patch:yes Bugfix & documentation PR that need to be picked to main branch and removed ci: do not merge labels Jun 16, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

LGTM

4 files reviewed, no comments
Edit PR Review Bot Settings | Greptile

@nx-cloud
Copy link

nx-cloud bot commented Jun 16, 2025

View your CI Pipeline Execution ↗ for commit 0510d85

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

☁️ Nx Cloud last updated this comment at 2025-08-01 15:21:22 UTC

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.

Looks good with one minor nit

@storybook-app-bot
Copy link

storybook-app-bot bot commented Jun 18, 2025

Package Benchmarks

Commit: 0510d85, ran on 1 August 2025 at 15:09:17 UTC

The following packages have significant changes to their size or dependencies:

storybook

Before After Difference
Dependency count 51 51 0
Self size 41.75 MB 41.36 MB 🎉 -384 KB 🎉
Dependency size 18.13 MB 18.13 MB 🎉 -2 B 🎉
Bundle Size Analyzer Link Link

sb

Before After Difference
Dependency count 52 52 0
Self size 1 KB 1 KB 🎉 -2 B 🎉
Dependency size 59.88 MB 59.50 MB 🎉 -384 KB 🎉
Bundle Size Analyzer Link Link

@storybook/cli

Before After Difference
Dependency count 220 220 0
Self size 585 KB 585 KB 🚨 +145 B 🚨
Dependency size 104.34 MB 103.96 MB 🎉 -378 KB 🎉
Bundle Size Analyzer Link Link

@storybook/codemod

Before After Difference
Dependency count 189 189 0
Self size 31 KB 31 KB 🎉 -2 B 🎉
Dependency size 88.43 MB 88.05 MB 🎉 -384 KB 🎉
Bundle Size Analyzer Link Link

Copy link
Member

@tmeasday tmeasday left a comment

Choose a reason for hiding this comment

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

I have a couple questions but looks good otherwise, good improvement.

@github-actions github-actions bot added the Stale label Jul 2, 2025
@github-actions github-actions bot closed this Jul 9, 2025
@diagramatics
Copy link
Contributor

👋 Just wanna bring this back since it was automatically closed. We do need this fix for our CI use case same as #31709 and it would be nice to have this also released to v8 as well since globalSettings was introduced in v8.6.14.

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

19 files reviewed, 5 comments
Edit PR Review Bot Settings | Greptile

Comment on lines 358 to 360
const { hasEslint, isStorybookPluginInstalled, isFlatConfig, eslintConfigFile } =
// TODO: Investigate why packageManager type does not match on CI
await extractEslintInfo(packageManager as any);
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Type casting can hide potential issues. Consider fixing the packageManager type mismatch instead

Comment on lines +75 to +77
if (input.toUpperCase() === 'FALSE' || input === '0') {
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Potential issue with case sensitivity - 'FALSE' check is inconsistent (uses toUpperCase) while '0' check is case-sensitive. Consider normalizing both checks.

Suggested change
if (input.toUpperCase() === 'FALSE' || input === '0') {
return false;
}
if (input.toUpperCase() === 'FALSE' || input.toUpperCase() === '0') {
return false;
}

.action(async (options) => {
options.debug = options.debug ?? false;
options.dev = options.dev ?? (IS_NON_CI && IS_NON_STORYBOOK_SANDBOX);
options.dev = options.dev ?? (isCI && !optionalEnvToBoolean(process.env.IN_STORYBOOK_SANDBOX));
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Logic error: isCI && !optionalEnvToBoolean(process.env.IN_STORYBOOK_SANDBOX) will enable dev mode in CI, which is opposite of the previous behavior (IS_NON_CI). Should be !isCI && !optionalEnvToBoolean(process.env.IN_STORYBOOK_SANDBOX)

Suggested change
options.dev = options.dev ?? (isCI && !optionalEnvToBoolean(process.env.IN_STORYBOOK_SANDBOX));
options.dev = options.dev ?? (!isCI && !optionalEnvToBoolean(process.env.IN_STORYBOOK_SANDBOX));

const { initiate } = await import('create-storybook');
await initiate({
dev: process.env.CI !== 'true' && process.env.IN_STORYBOOK_SANDBOX !== 'true',
dev: isCI && !optionalEnvToBoolean(process.env.IN_STORYBOOK_SANDBOX),
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: The condition needs to be inverted - currently isCI && !optionalEnvToBoolean() enables dev mode when in CI, which is opposite of the intended behavior. Should be !isCI && !optionalEnvToBoolean()

Suggested change
dev: isCI && !optionalEnvToBoolean(process.env.IN_STORYBOOK_SANDBOX),
dev: !isCI && !optionalEnvToBoolean(process.env.IN_STORYBOOK_SANDBOX),

Comment on lines +13 to +15
let currentPromptLibrary: PromptLibrary = optionalEnvToBoolean(process.env.USE_CLACK)
? 'clack'
: 'prompts';
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Could the default value be extracted into a constant? This would make it easier to change the default prompt library in the future if needed.

@valentinpalkovic
Copy link
Contributor

@JReinhold Can you take another look and maybe resolve the conflicts?

shilman and others added 3 commits July 31, 2025 12:16
- Changed instances of `isCI` to `isCI()` in various files to ensure consistent function usage.
- Updated related logic in `postinstall-logger.ts`, `postinstall.ts`, `withTelemetry.ts`, and others to reflect this change.
- Enhanced test coverage for `isCI` behavior in `storybook-metadata.test.ts`.
@yannbf yannbf removed the Stale label Jul 31, 2025
yannbf and others added 6 commits July 31, 2025 12:02
- Replaced direct imports of `isCI` and `logger` from internal paths with imports from centralized utility modules.
- This change enhances maintainability and consistency across the codebase.
@yannbf yannbf merged commit d87db5c into next Aug 1, 2025
54 checks passed
@yannbf yannbf deleted the jeppe/fix-global-settings-readonly branch August 1, 2025 15:24
yannbf added a commit that referenced this pull request Aug 4, 2025
…readonly

CLI: Fix throwing in readonly environments
(cherry picked from commit d87db5c)
@github-actions github-actions bot added the patch:done Patch/release PRs already cherry-picked to main/release branch label Aug 4, 2025
@ndelangen ndelangen removed the patch:yes Bugfix & documentation PR that need to be picked to main branch label Oct 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug ci:normal cli needs triage patch:done Patch/release PRs already cherry-picked to main/release branch telemetry

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: SB_CORE-SERVER_0001 on read-only file system

8 participants