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

feat(angular): use standalone components with routing #25589

Merged
merged 12 commits into from
Aug 30, 2022

Conversation

sean-perkins
Copy link
Contributor

@sean-perkins sean-perkins commented Jul 7, 2022

Pull request checklist

Please check if your PR fulfills the following requirements:

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
    • Some docs updates need to be made in the ionic-docs repo, in a separate PR. See the contributing guide for details.
  • Build (npm run build) was run locally and any changes were pushed
  • Lint (npm run lint) has passed locally and any fixes were made for failures

Pull request type

Please check the type of change your PR introduces:

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

What is the current behavior?

Standalone components do not work within Ionic's routing implementation.

Issue URL: #25404

What is the new behavior?

  • Introduces an environmentInjector property to ion-router-outlet and ion-tabs to enable developers to make use of standalone components with routing in Angular 14.
  • Developer warning to guide developers trying to use standalone components with routing without our required syntax.

Screen Shot 2022-07-07 at 3 13 28 PM

Does this introduce a breaking change?

  • Yes
  • No

Other information

Dev-build: 6.1.14-dev.11657224247.185f8192

In your Angular 14 application, you will need to expose the new EnvironmentInjector to Ionic routing components (ion-router-outlet and ion-tabs).

For example:

import { EnvironmentInjector } from '@angular/core';

@Component({
  selector: 'app-root',
  template: `<ion-router-outlet [environmentInjector]="environmentInjector"></ion-router-outlet>`
})
export class AppComponent {
  constructor(public environmentInjector: EnvironmentInjector) {}
}

@github-actions github-actions bot added the package: angular @ionic/angular package label Jul 7, 2022
@sean-perkins sean-perkins changed the title feat(angular): use standalone components with routing feat(angular): use standalone components with routing (DO NOT REVIEW) Jul 7, 2022
@sean-perkins sean-perkins changed the title feat(angular): use standalone components with routing (DO NOT REVIEW) feat(angular): use standalone components with routing Jul 7, 2022
@sean-perkins sean-perkins changed the base branch from feature-6.2 to feature-6.3 August 17, 2022 20:36
@sean-perkins
Copy link
Contributor Author

TODO: Need to rebase 6.3 against main, to get the updated multi-framework version testing. Then need to write a specific test in the Angular 14 test app that verifies standalone components with routing.

@sean-perkins sean-perkins marked this pull request as ready for review August 24, 2022 20:51
@sean-perkins sean-perkins requested a review from a team as a code owner August 24, 2022 20:51
@@ -30,5 +30,5 @@ export abstract class EnvironmentInjector implements Injector {
/**
* @internal
*/
abstract onDestroy(callback: () => void): void;
abstract onDestroy?(callback: () => void): void;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why was this change needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was to align with the type signature of the EnvironmentInjector type from @angular/core. We are maintaining our own "version" of the types, since we cannot update our library dependencies to target Angular 14. When I originally ported this, I forgot to make the onDestroy callback optional.

Without this change, developers would receive a typescript language server warning in their IDE that the type of their environmentInjector does not match the type signature of what we are expecting to be passed in.

* The `EnvironmentInjector` provider instance from the parent component.
* Required for using standalone components with `ion-router-outlet`.
*
* Will be deprecated and removed when Angular 13 support is dropped.
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need a tech debt ticket for this? (Ditto for ion-tabs)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm indifferent since this is an experimental API that could be ripped out completely if either Angular doesn't proceed with standalone as part of the official public API or if don't think it is a good architectural fit with Ionic.

I think once we consider it public API, having tech debt to maintain it could make sense.

But we also don't have many experimental features, so if we want to follow our existing process like everything else, I'm happy to create tickets 👍

Copy link
Contributor

@liamdebeasi liamdebeasi left a comment

Choose a reason for hiding this comment

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

Changes look good. Are these test app config changes intentional or do we just need to resync feature-6.3 with main?

@sean-perkins
Copy link
Contributor Author

The changes to the test apps are intentional. Removed the non-applicable README, added a missing tsconfig and created a script to sync only the e2e content changes (faster than syncing all of the node modules and app files when trying to modify a cypress test file in the base app).

The ng14 test app changes are required to validate the standalone routing behavior works.

@sean-perkins sean-perkins merged commit 3c84d48 into feature-6.3 Aug 30, 2022
@sean-perkins sean-perkins deleted the feat/standalone-components-api branch August 30, 2022 14:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: angular @ionic/angular package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants