- 
          
- 
                Notifications
    You must be signed in to change notification settings 
- Fork 9.8k
Angular: Properly merge builder options and browserTarget options #32272
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 file reviewed, no comments
| View your CI Pipeline Execution ↗ for commit 3575e12 
 ☁️ Nx Cloud last updated this comment at  | 
| Package BenchmarksCommit:  No significant changes detected, all good. 👏 | 
|  | ||
| expect(mockedTargetFromTargetString).not.toHaveBeenCalled(); | ||
| expect(mockBuilderContext.getTargetOptions).not.toHaveBeenCalled(); | ||
| expect(mockBuilderContext.getTargetOptions).toHaveBeenCalledOnce(); | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fyi: since we now also use getTargetOptions for retrieving the builder options, it is always called once, and if theres a browserTarget, called twice
| @valentinpalkovic I fixed the failing tests and CI is now green 🙂 | 
| @valentinpalkovic I just merged next into this branch and now, for the second time, a test runs into a timeout... is this a flacky test on main? | 
| Seems to be flaky. Let's rerun it. | 
| Is there anything I can do to help getting this merged? We currently use a workaround in our Storybook and I would love to remove that | 
| @kroeder I somehow found this PR after several hours of debugging the same issue.. Can you share what the workaround was so I can test it in our workspace while this gets merged? | 
| 
 @angelnikolov copy over everything you need from the "browserTarget" to the actual target The problem this PR fixes is that if you don't set anything in the actual builder options, it initializes itself with an empty array/object. Therefore, you always overwrite what you would originally get from  Example: should be this  | 
| That was quick! Thanks! | 
…ge-bug Angular: Properly merge builder options and browserTarget options (cherry picked from commit f739234)
Closes #32105
What I did
Merging builder options and browser target options now properly only merges explicitly set properties.
Before, the code relied on an object that got populated by Angular and contained every property available.
If user-land has not defined, e.g.
styles: ["something"], then Angular has set the value tostyles: []This caused an auto-overwrite of the browser target options.
The new behavior only overwrites browser target options, if user-land explicitly has set builder options
Checklist for Contributors
Testing
For me, looking at the existing test cases, it was hard to write a test that provides actual confidence. However I tried it, I had to mock it in a way that would end up in a false confidence.
It would be nice if someone could help me out with that.
The changes in this PR are covered in the following automated tests:
Manual testing
This section is mandatory for all contributions. If you believe no manual test is necessary, please state so explicitly. Thanks!
Verify it does load styles from the browserTarget
angular.jsondoes not containstyles: []for the storybook targetbutton { display: none !important; }browserTarget, therefore the button is now invisibleVerify it's possible to overwrite the styles in the builder options
angular.jsoncontains e.g.styles: ["src/test.scss"]for the storybook targetbutton { display: none !important; }Documentation
MIGRATION.MD
Checklist for Maintainers
When this PR is ready for testing, make sure to add
ci:normal,ci:mergedorci:dailyGH label to it to run a specific set of sandboxes. The particular set of sandboxes can be found incode/lib/cli-storybook/src/sandbox-templates.tsMake 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/coreteam 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
This PR fixes a critical bug in the Angular framework integration where Storybook's builder options were incorrectly overriding browser target configurations. The issue occurred because Angular pre-populates
options.angularBuilderOptionswith default values for all possible properties (e.g.,styles: []even when users haven't explicitly set styles), causing unintended overwrites of browser target settings.The fix changes the merging logic in
framework-preset-angular-cli.tsto useexplicitAngularBuilderOptionsobtained directly frombuilderContext.getTargetOptions()instead of the pre-populatedoptions.angularBuilderOptions. This ensures that only explicitly user-defined options override browser target settings, preserving the expected inheritance behavior where Storybook configurations should inherit from the specifiedbrowserTargetunless explicitly overridden.This change is part of the Angular framework's webpack configuration setup, which is responsible for merging build options from different sources. The modification maintains backward compatibility while restoring the correct precedence order: browser target options serve as defaults, and only explicitly defined Storybook builder options override them. This addresses a regression that affected styles, assets, and stylePreprocessorOptions inheritance from browserTarget configurations.
Confidence score: 4/5