Skip to content
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 v19.2 when @angular/animations is not installed #30611

Merged
merged 2 commits into from
Feb 21, 2025

Conversation

valentinpalkovic
Copy link
Contributor

@valentinpalkovic valentinpalkovic commented Feb 21, 2025

Closes #

What I did

In the current release candidate of Angular (v19.2.0-rc.0) it doesn't install @angular/animations per default when initializing Angular freshly. Storybook, though, had some imports on @angular/animations which started to fail.

Now, Storybook doesn't require having @angular/animations being present, but conditionally applies logic when it is.

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>

name before after diff z %
createSize 0 B 0 B 0 B - -
generateSize 80.5 MB 80.5 MB 0 B -0.7 0%
initSize 80.5 MB 80.5 MB 0 B -0.7 0%
diffSize 97 B 97 B 0 B - 0%
buildSize 7.31 MB 7.31 MB 0 B 1.57 0%
buildSbAddonsSize 1.9 MB 1.9 MB 0 B -0.86 0%
buildSbCommonSize 195 kB 195 kB 0 B - 0%
buildSbManagerSize 1.88 MB 1.88 MB 0 B 1.22 0%
buildSbPreviewSize 0 B 0 B 0 B - -
buildStaticSize 0 B 0 B 0 B - -
buildPrebuildSize 3.97 MB 3.97 MB 0 B 1.45 0%
buildPreviewSize 3.34 MB 3.34 MB 0 B 1.2 0%
testBuildSize 0 B 0 B 0 B - -
testBuildSbAddonsSize 0 B 0 B 0 B - -
testBuildSbCommonSize 0 B 0 B 0 B - -
testBuildSbManagerSize 0 B 0 B 0 B - -
testBuildSbPreviewSize 0 B 0 B 0 B - -
testBuildStaticSize 0 B 0 B 0 B - -
testBuildPrebuildSize 0 B 0 B 0 B - -
testBuildPreviewSize 0 B 0 B 0 B - -
name before after diff z %
createTime 7.6s 26.4s 18.8s 2.97 🔺71.2%
generateTime 19.6s 18s -1s -594ms -1.15 -8.8%
initTime 4.6s 4.4s -190ms -0.69 -4.2%
buildTime 9.2s 8.6s -564ms -0.93 -6.5%
testBuildTime 0ms 0ms 0ms - -
devPreviewResponsive 6.4s 5.4s -1s -38ms -0.21 -19%
devManagerResponsive 6.1s 5.2s -916ms 0.93 -17.5%
devManagerHeaderVisible 941ms 684ms -257ms -1.24 🔰-37.6%
devManagerIndexVisible 988ms 697ms -291ms -1.24 🔰-41.8%
devStoryVisibleUncached 2.4s 1.9s -486ms -1.27 🔰-25.1%
devStoryVisible 988ms 718ms -270ms -1.25 🔰-37.6%
devAutodocsVisible 941ms 692ms -249ms -1.11 -36%
devMDXVisible 826ms 640ms -186ms -1.71 🔰-29.1%
buildManagerHeaderVisible 1s 805ms -228ms -0.05 -28.3%
buildManagerIndexVisible 1.1s 981ms -124ms 1.01 -12.6%
buildStoryVisible 1s 781ms -230ms 0.01 -29.4%
buildAutodocsVisible 644ms 707ms 63ms 0.34 8.9%
buildMDXVisible 818ms 648ms -170ms -0.01 -26.2%

Greptile Summary

Here's my analysis of the pull request:

Makes Angular renderer compatible with Angular v19.2 by making @angular/animations optional, focusing on dynamic imports and conditional animation handling.

  • Added async/await pattern in AbstractRenderer.ts for PropertyExtractor.init() to handle conditional animation loading
  • Added try-catch block in framework-preset-angular-cli.ts to conditionally import animations and add WebpackIgnorePlugin when module is missing
  • Removed animation-dependent demo components and stories from template directory
  • Made @angular/animations an optional peer dependency in package.json with version range >=15.0.0 < 20.0.0
  • Added logic in PropertyExtractor.ts to handle standalone components defaulting to true in Angular 19+

@valentinpalkovic valentinpalkovic self-assigned this Feb 21, 2025
@valentinpalkovic valentinpalkovic added ci:daily Run the CI jobs that normally run in the daily job. bug angular labels Feb 21, 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.

10 file(s) reviewed, 4 comment(s)
Edit PR Review Bot Settings | Greptile

@@ -71,8 +63,8 @@ export class PropertyExtractor implements NgModuleMetadata {
}
}

private init() {
const analyzed = this.analyzeMetadata(this.metadata);
public async init() {
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: init() is now public and async but constructor no longer calls it - this could cause issues if callers forget to call init()

Copy link
Contributor

Choose a reason for hiding this comment

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

instead of requiring everyone to call PropertyExtractor.init() manually after constructing, maybe you can do:

  constructor(
    private metadata: NgModuleMetadata,
    private component?: any
  ) {
    return this.init().then(() => this);
  }

so you can do await new PropertyExtractor(), that will run init and return the instance.

);
return [true, provideNoopAnimations()];
if (ngModule === animations.NoopAnimationsModule) {
console.error(
Copy link
Contributor

Choose a reason for hiding this comment

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

style: console.error() used for NoopAnimationsModule warning while other similar warnings use console.warn() - should be consistent

Suggested change
console.error(
console.warn(

Comment on lines +43 to +51
try {
await import('@angular/platform-browser/animations');
} catch (e) {
webpackConfig.plugins.push(
new WebpackIgnorePlugin({
resourceRegExp: /@angular\/platform-browser\/animations$/,
})
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Consider catching a more specific error type than just 'e' to avoid accidentally catching unrelated errors

Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Removing this template file will break the OpenCloseComponent and its stories unless corresponding changes are made to move this template inline or provide an alternative.

@valentinpalkovic valentinpalkovic added the patch:yes Bugfix & documentation PR that need to be picked to main branch label Feb 21, 2025
Copy link

nx-cloud bot commented Feb 21, 2025

View your CI Pipeline Execution ↗ for commit 46eb952.

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

☁️ Nx Cloud last updated this comment at 2025-02-21 09:43:21 UTC

@valentinpalkovic valentinpalkovic force-pushed the valentin/support-angular-19.2 branch from 82faba9 to d0b1713 Compare February 21, 2025 09:04
@valentinpalkovic valentinpalkovic force-pushed the valentin/support-angular-19.2 branch from 854b7a6 to 46eb952 Compare February 21, 2025 09:37
@@ -71,8 +63,8 @@ export class PropertyExtractor implements NgModuleMetadata {
}
}

private init() {
const analyzed = this.analyzeMetadata(this.metadata);
public async init() {
Copy link
Contributor

Choose a reason for hiding this comment

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

instead of requiring everyone to call PropertyExtractor.init() manually after constructing, maybe you can do:

  constructor(
    private metadata: NgModuleMetadata,
    private component?: any
  ) {
    return this.init().then(() => this);
  }

so you can do await new PropertyExtractor(), that will run init and return the instance.

@valentinpalkovic
Copy link
Contributor Author

@JReinhold

That's correct. But I have decided against it after reading https://dev.to/somedood/the-proper-way-to-write-async-constructors-in-javascript-1o8c

@valentinpalkovic valentinpalkovic merged commit f10850b into next Feb 21, 2025
110 of 112 checks passed
@valentinpalkovic valentinpalkovic deleted the valentin/support-angular-19.2 branch February 21, 2025 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
angular bug ci:daily Run the CI jobs that normally run in the daily job. patch:yes Bugfix & documentation PR that need to be picked to main branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants