-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Angular: Support Angular 14 standalone components #18272
Angular: Support Angular 14 standalone components #18272
Conversation
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 41752fe. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this branch ✅ Successfully ran 1 targetSent with 💌 from NxCloud. |
Hey @leosvelperez thanks a lot for this PR and being on top of the Angular game! Could you please update the description PR? It's currently blank. @storybookjs/angular team could you please take a look? thank you so much! |
@yannbf you're right. I described things over Discord and forgot to add the description here. I'll update the PR description.
The change is backward compatible. In workspaces with an older version of Angular, The issue we have here is a typing issue. Since Storybook still depends on Angular 11, the I didn't do that from the start because I didn't know if you had a plan to upgrade the Angular deps or if we wanted to keep it at 11. Upgrading the Angular deps is a bigger change. |
@yannbf should I go ahead and add those casts to make the TS compiler happy? I previously tested it locally that way and it was building and testing successfully. |
Sounds good! That'd be the quickest path and we can follow up later to migrate to 14. Could you add a comment with a TODO there? 🙌 |
Will do! 👍🏻 |
640ebf3
to
eb960e6
Compare
I updated the PR and rebased the branch. The only check that's failing seems to be unrelated to the changes in this PR. |
eb960e6
to
41752fe
Compare
Codecov Report
@@ Coverage Diff @@
## next #18272 +/- ##
==========================================
- Coverage 32.05% 32.02% -0.04%
==========================================
Files 975 975
Lines 19211 19229 +18
Branches 4031 4033 +2
==========================================
Hits 6158 6158
- Misses 12489 12507 +18
Partials 564 564
Continue to review full report at Codecov.
|
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.
LGTM. I will try to chase down somebody from @storybookjs/angular to get a second opinion. Thanks so much @leosvelperez !!! 🙏
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.
Awesome 😎 👏
LGTM,
imports: [BrowserModule, ...(moduleMetadata.imports ?? [])], | ||
imports: [ | ||
BrowserModule, | ||
...(isStandalone ? [component] : []), |
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.
I you want test this you can add a test here : https://github.com/storybookjs/storybook/blob/41752fe5bc8ed2831a21b96bc5203b53c0e9b123/app/angular/src/client/preview/angular-beta/StorybookModule.test.ts
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.
I initially added a unit test there, but it fails because the current Angular version in this repo doesn't support importing components in an NgModule
, so it throws an error. I could still add a unit test but I won't be able to check the fixture (can't call configureTestingModule(ngModule)
because it errors). All I could check is that the right imports and declarations are present in the NgModule
resultant of calling getStorybookModuleMetadata
.
…ents Angular: Support Angular 14 standalone components
Issue:
What I did
Angular v14 introduces standalone components. These components can't be declared in
NgModule
s and instead, they can be imported by anNgModule
to make it available to the components declared by thatNgModule
.Currently, Storybook adds the specified
component
to thedeclarations
property of the storyNgModule
. As explained above, this doesn't work with standalone components.With the changes in this PR, we now identify if the specified component is standalone:
declarations
of the storyNgModule
and instead, we add it to theimports
of theNgModule
.declarations
of the storyNgModule
).How to test
If your answer is yes to any of these, please make sure to include it in your PR.