Skip to content

feat(angular): ship Ionic components as Angular standalone components - #28311

Merged
liamdebeasi merged 36 commits into
feature-7.5from
FW-4612
Oct 10, 2023
Merged

feat(angular): ship Ionic components as Angular standalone components#28311
liamdebeasi merged 36 commits into
feature-7.5from
FW-4612

Conversation

@liamdebeasi

@liamdebeasi liamdebeasi commented Oct 9, 2023

Copy link
Copy Markdown
Contributor

Issue number: N/A


What is the current behavior?

1. Bundle Size Reductions

All Ionic UI components and Ionicons are added to the final bundle of an Ionic Angular application. This is because all components and icons are lazily loaded as needed. This prevents the compiler from properly tree shaking applications. This does not cause all components and icons to be loaded on application start, but it does increase the size of the final app output that all users need to download.

Related Issues

ionic-team/ionicons#910

ionic-team/ionicons#536

#27280

#24352

2. Standalone Component Support

Standalone Components are a stable API as of Angular 15. The Ionic starter apps on the CLI have NgModule and Standalone options, but all of the Ionic components are still lazily/dynamically loaded using IonicModule. Standalone components in Ionic also enable support for new Angular features such as bundling with ESBuild instead of Webpack. ESBuild does not work in Ionic Angular right now because components cannot be statically analyzed since they are dynamically imported.

We added preliminary support for standalone components in Ionic v6.3.0. This enabled developers to use their own custom standalone components when routing with ion-router-outlet. However, we did not ship standalone components for Ionic's UI components.

Related Issues

#25404

#27251

#27387

3. Faster Component Load Times

Since Ionic Angular components are lazily loaded, they also need to be hydrated. However, this hydration does not happen immediately which prevents components from being usable for multiple frames.

Related Issues

#24352

#26474

What is the new behavior?

  • Ionic components and directives are accessible as Angular standalone components/directives

Does this introduce a breaking change?

  • Yes
  • No

Other information

Associated documentation branch: https://github.com/ionic-team/ionic-docs/tree/feature-7.5

liamdebeasi and others added 30 commits July 27, 2023 13:37
Issue number: N/A

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

IDEs that perform type checking/include a language service will error on
the `@ionic/angular/common` import paths and not provide intelisense or
auto import detection.

![CleanShot 2023-08-15 at 09 49
34](https://github.com/ionic-team/ionic-framework/assets/13732623/2e9913b2-5b44-4dd7-8cf7-8fa0d6aaac69)


## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- `@ionic/angular/common` import paths are detected by IDEs such as
VSCode

![CleanShot 2023-08-15 at 09 48
40](https://github.com/ionic-team/ionic-framework/assets/13732623/cd502093-b095-47a8-b5f7-b28a0fc9fe27)


## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->
Issue number: N/A

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

Ionic Framework currently only generates the lazy/hydrated Angular
component wrappers for the web components.

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- Generates Angular standalone component wrappers for the web
components, using the CE build.
  - Adds manual component wrapper for `ion-icon` with the CE build.
- Migrates the `ion-back-button` and `ion-nav` to be manual component
wrappers
- Continues to generate the lazy/hydrated Angular component wrappers.
- Refactors "NavDelegate" etc. language to `IonNav` to avoid exporting
as and simplify navigating the code.

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->

Related output targets PR:
stenciljs/output-targets#367
Issue number: N/A

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?

Tabs cannot be used as a standalone component.

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- Added tabs as a standalone component.
- Added a quick test. I included the event checking from the lazy test
in the HTML as a smoke check, but didn't bring over the Cypress tests
for them since I noticed the other standalone tests have been quick,
stripped down affairs. I'm assuming I would just be duplicating effort.
Let me know if I should bring more tests over from the lazy version, or
even get rid of the event logging from the standalone HTML.

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->
chore: sync with main
)

Issue number: N/A

---------

<!-- Please do not submit updates to dependencies unless it fixes an
issue. -->

<!-- Please try to limit your pull request to one type (bugfix, feature,
etc). Submit multiple pull requests if needed. -->

## What is the current behavior?
<!-- Please describe the current behavior that you are modifying. -->

Ionic standalone form controls cannot participate in Angular forms.

## What is the new behavior?
<!-- Please describe the behavior or changes that are being added by
this PR. -->

- Ionic form controls can participate in Angular forms by importing the
standalone component
- Applies to: `ion-input`, `ion-textarea`, `ion-searchbar`,
`ion-toggle`, `ion-checkbox`, `ion-segment`, `ion-radio`,
`ion-radio-group`, `ion-datetime` and `ion-range`.
- Refactors `ValueAccessor` from `@ionic/angular` to
`@ionic/angular/common`
- Refactors `raf` utility from `@ionic/angular` to
`@ionic/angular/common`

## Does this introduce a breaking change?

- [ ] Yes
- [x] No

<!-- If this introduces a breaking change, please describe the impact
and migration path for existing applications below. -->


## Other information

<!-- Any other information that is important to this PR such as
screenshots of how the component looks before and after the change. -->

---------
chore: sync with main
chore: sync with feature-7.5
@liamdebeasi liamdebeasi changed the title Fw 4612 feat(angular): ship Ionic components as Angular standalone components Oct 9, 2023
@github-actions github-actions Bot added package: core @ionic/core package package: angular @ionic/angular package package: vue @ionic/vue package package: react @ionic/react package labels Oct 9, 2023
@liamdebeasi
liamdebeasi marked this pull request as ready for review October 9, 2023 19:40
@liamdebeasi
liamdebeasi marked this pull request as draft October 9, 2023 19:41
@github-actions github-actions Bot removed package: vue @ionic/vue package package: react @ionic/react package labels Oct 9, 2023
@liamdebeasi
liamdebeasi marked this pull request as ready for review October 9, 2023 20:32
Comment thread packages/angular/test/apps/ng14/package.json Outdated
Comment thread packages/angular/test/apps/ng15/package.json Outdated
Comment thread packages/angular/test/apps/ng16/package.json Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this file be deleted since it's empty?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not sure what you mean - the file was deleted in the diff?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's showing as an empty file instead of a deleted one.
Screenshot 2023-10-10 at 8 18 58 AM

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The red means that it was deleted. The file that was deleted was empty though. The app.component.ts diff also shows that we removed a reference to the file: https://github.com/ionic-team/ionic-framework/pull/28311/files#diff-f489c71da69710fe7957173822f2d6e8dea4bb8660b6bd44ed2efa41ecd8accb

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Screenshot of the linked diff since GitHub didn't always load it on my end:
image

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah, that makes sense. Thank you!

@thetaPC thetaPC left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@liamdebeasi
liamdebeasi merged commit 57e2476 into feature-7.5 Oct 10, 2023
@liamdebeasi
liamdebeasi deleted the FW-4612 branch October 10, 2023 17:06
@liamdebeasi
liamdebeasi restored the FW-4612 branch November 8, 2023 19:09
@liamdebeasi
liamdebeasi deleted the FW-4612 branch November 15, 2023 17:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: angular @ionic/angular package package: core @ionic/core package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants