Skip to content

feat: migrate from Angular 20 to Angular 21#291

Merged
MaudeLaflamme merged 1 commit intoVilledeMontreal:masterfrom
francischabot:feature/angular-21
Mar 31, 2026
Merged

feat: migrate from Angular 20 to Angular 21#291
MaudeLaflamme merged 1 commit intoVilledeMontreal:masterfrom
francischabot:feature/angular-21

Conversation

@francischabot
Copy link
Copy Markdown
Contributor

Must be merged after #290

Upgrades the library from Angular 20 to Angular 21, fixes a pre-existing radio button bug uncovered during migration, and upgrades Storybook from v9 to v10.

Angular 21 migration

  • All @angular/* and @angular/cdk packages bumped to ~21.2.0
  • typescript~5.9.3, zone.js~0.16.1, @typescript-eslint8.56.1
  • tsconfig.json: moduleResolution: "bundler", module: "ES2022" (required by CDK 21 exports map)
  • Source components updated for breaking changes: EventEmitter no longer extends Subject (modal, snack-bar, tabs), detectChanges() replaced with markForCheck() (pagination, system-header, dropdown-menu)
  • 12 spec files: added provideZoneChangeDetection() to fix NG0100 errors in Angular 21 TestBed

Radio button fix

  • Corrected malformed @ContentChildren / @ViewChild decorators in radio-group.component.ts
  • Added null safety check on staticContainer before accessing children

Storybook v9 → v10

  • All @storybook/* packages upgraded to ^10.2.15 (v10 natively supports Angular 21)
  • Removed zone.js import from Storybook polyfills.ts (eliminates NG0914 warning)

Tests

TOTAL: 111 SUCCESS

@MaudeLaflamme MaudeLaflamme self-requested a review March 12, 2026 20:48
@francischabot francischabot force-pushed the feature/angular-21 branch 2 times, most recently from 4a1f552 to 0c91fb3 Compare March 13, 2026 14:57
@MaudeLaflamme
Copy link
Copy Markdown
Collaborator

@francischabot Peux-tu rebase ta branche sur master, puis squash tous tes commits en un seul et limiter le message à 1-2 phrases seulement, par exemple "chore: upgrade to angular v21" serait suffisant.

BREAKING CHANGES:
- Angular 21.2.0 (all @angular/* packages)
- Angular CDK 21.2.0 (flat package structure with exports map)
- TypeScript 5.9.3
- zone.js 0.16.1
- angular-eslint 21.2.0
- ng-packagr 21.2.0

Key changes:
- tsconfig: moduleResolution changed from 'node' to 'bundler', module from
  'esnext' to 'es2022' (required for CDK 21 flat package format)
- EventEmitter no longer extends RxJS Subject: modal-container uses Subject
  for internal _animationStateChanged, snack-bar wraps onMicrotaskEmpty
  with from(), tabs stores Subscription objects for proper cleanup
- Replace detectChanges() with markForCheck() in lifecycle hooks of
  pagination, system-header, and dropdown-menu components
- Remove unused ChangeDetectorRef from button component
- file-input: private to protected for _isDragOver (typeCheckHostBindings)
- modal-ref: typed KeyboardEvent for CDK 21 overlay keydown events
- Add provideZoneChangeDetection() to test modules (Angular 21 TestBed
  uses zoneless CD internally, requiring explicit zone CD for zone-based
  component tests)
- Add provideZoneChangeDetection to storybook AppModule
- Add .npmrc with legacy-peer-deps=true (Storybook 9 peer dep conflict)

fix(radio): correct ViewChild and ContentChildren decorators in radio button group

The radio button group component had incorrect decorator syntax that caused
'Cannot read properties of undefined (reading children)' errors in Storybook
and potentially in production apps.

Issues fixed:
- staticContainer was using malformed @ContentChildren with read: ViewChild()
  instead of proper @ViewChild decorator
- _radios QueryList was missing @ContentChildren decorator entirely
- Added null safety check in setAriaDescribedByToDescription() to handle
  cases where staticContainer might not be initialized yet

The fixes ensure that:
- staticContainer properly references the #container template element
- _radios properly queries all BaoRadioButtonComponent children
- No runtime errors occur during component initialization

feat(storybook): upgrade from v9 to v10

Storybook v10, unlike v9, natively supports Angular 21 (peer dep range
>=18.0.0 <22.0.0). This eliminates the need for npm overrides that were
forcing Angular peer dependency resolution for @storybook/angular.

Packages upgraded:
- storybook: ^9.1.16 → ^10.2.15
- @storybook/angular: ^9.1.16 → ^10.2.15
- @storybook/addon-docs: ^9.1.16 → ^10.2.15
- @storybook/addon-links: ^9.1.16 → ^10.2.15
- @storybook/addon-a11y: ^9.1.16 → ^10.2.15
- eslint-plugin-storybook: ^0.11.5 → ^10.2.15

Configuration changes:
- Removed npm overrides section from package.json (no longer needed)
- Removed zone.js from Storybook polyfills (Angular 21 uses zoneless CD)
- Removed provideZoneChangeDetection from app.module.ts (not needed)

fix: package-lock.json + lint

Signed-off-by: Francis Chabot <francis.chabot@montreal.ca>
@MaudeLaflamme MaudeLaflamme merged commit 08de332 into VilledeMontreal:master Mar 31, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants