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(router): Create APIs for using Router without RouterModule #47010

Closed
wants to merge 1 commit into from

Conversation

atscott
Copy link
Contributor

@atscott atscott commented Aug 1, 2022

This commit creates and exposes the APIs required to use the Angular Router without importing RouterModule.

The newly added APIs are tree-shakable and you can add features using special functions rather than using ExtraOptions to control the providers via an internal switch in Router code.

const appRoutes: Routes = [];
bootstrapApplication(AppComponent,
  {
    providers: [
      provideRouter(appRoutes,
        withDebugTracing(),     // enables debug tracing feature
        withInMemoryScrolling() // enables scrolling feature
    ]
  }
);

This "features" pattern allows for router behavior to evolve in a backwards compatible and tree-shakable way in the future. This approach also makes features more discoverable.

The newly added APIs can be used in any application today (doesn't require an application to be bootstrapped using standalone-based APIs).

Note: APIs added in this commit are released in the "Developer Preview" mode, read more about this mode in Angular docs: https://angular.io/guide/releases#developer-preview

@atscott atscott force-pushed the standaloneRouterAPIs branch 2 times, most recently from fc15d93 to ab4fcbc Compare August 1, 2022 22:49
@ngbot ngbot bot added this to the Backlog milestone Aug 1, 2022
@atscott atscott force-pushed the standaloneRouterAPIs branch 3 times, most recently from f85589d to 30b165f Compare August 2, 2022 23:12
@atscott atscott added the target: minor This PR is targeted for the next minor release label Aug 2, 2022
@atscott
Copy link
Contributor Author

atscott commented Aug 2, 2022

Open question for reviewers: When updating the tests in the router package to use the new provideRouterForTesting API, I kept using withXFeature without putting it in an array. Should we use a rest parameter for the features or should we keep it as an array in the second argument?

@atscott atscott changed the title Draft: Create APIs for using Router without RouterModule feat(router): Create APIs for using Router without RouterModule Aug 2, 2022
@atscott atscott marked this pull request as ready for review August 2, 2022 23:21
@atscott atscott force-pushed the standaloneRouterAPIs branch 2 times, most recently from 3ea0fc3 to 80fbf37 Compare August 5, 2022 17:39
Copy link
Member

@pkozlowski-opensource pkozlowski-opensource left a comment

Choose a reason for hiding this comment

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

Did another pass today, things looks really good so far!

I've left a couple of comments around the public API surface - I guess I'm missing important bits of context but I would like to discuss and make sure that we are on the same page.

Other than this I can see that some public API docs and usage examples are missing, so leaving a comment review for now. Will do another pass after public API surface is clarified and the docs bits are done.

goldens/public-api/router/index.md Show resolved Hide resolved
packages/router/src/provide_router.ts Show resolved Hide resolved
packages/router/src/provide_router.ts Show resolved Hide resolved
Copy link
Contributor

@AndrewKushnir AndrewKushnir left a comment

Choose a reason for hiding this comment

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

Just publishing some comments. I will probably take care of most of them myself.

packages/router/src/provide_router.ts Show resolved Hide resolved
packages/router/src/provide_router.ts Outdated Show resolved Hide resolved
packages/router/src/router_module.ts Show resolved Hide resolved
packages/router/src/provide_router.ts Show resolved Hide resolved
packages/router/testing/src/router_testing_module.ts Outdated Show resolved Hide resolved
@atscott atscott force-pushed the standaloneRouterAPIs branch 4 times, most recently from 260130b to c3da7e1 Compare August 8, 2022 19:59
@AndrewKushnir AndrewKushnir force-pushed the standaloneRouterAPIs branch 3 times, most recently from a739550 to 954da58 Compare August 8, 2022 22:58
Copy link
Contributor

@jessicajaniuk jessicajaniuk left a comment

Choose a reason for hiding this comment

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

I don't have much to say other than I really like these APIs. Well done! 👏🏻

reviewed-for: public-api, fw-core, size-tracking, integration-tests, fw-testing

@brandonroberts
Copy link
Contributor

@atscott

I was thinking something more like

import { provideRouter } from '@angular/router';

  provideRouter([], {
    enabletTracing: true,
    preloading: true
  })

vs

import { provideRouter, withDebugTracing, withPreloading } from '@angular/router';

  provideRouter([], [
    withDebugTracing(),
    withPreloading()
  ])

Additional imports are needed also, but if it can't be tree-shaken out by the compiler, I get it.

@mary-poppins
Copy link

You can preview 7db44bd at https://pr47010-7db44bd.ngbuilds.io/.

@mary-poppins
Copy link

You can preview f8ab94e at https://pr47010-f8ab94e.ngbuilds.io/.

goldens/public-api/router/index.md Outdated Show resolved Hide resolved
@AndrewKushnir AndrewKushnir force-pushed the standaloneRouterAPIs branch 2 times, most recently from 1694a27 to a0b4a6b Compare August 12, 2022 00:09
@mary-poppins
Copy link

You can preview a0b4a6b at https://pr47010-a0b4a6b.ngbuilds.io/.

Copy link
Member

@alxhub alxhub left a comment

Choose a reason for hiding this comment

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

Reviewed-for: public-api

packages/router/src/provide_router.ts Outdated Show resolved Hide resolved
@AndrewKushnir AndrewKushnir added the action: presubmit The PR is in need of a google3 presubmit label Aug 12, 2022
Copy link
Member

@alxhub alxhub left a comment

Choose a reason for hiding this comment

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

(can't approve enough)

@mary-poppins
Copy link

You can preview df29701 at https://pr47010-df29701.ngbuilds.io/.

This commit creates and exposes the APIs required to use the Angular Router without importing `RouterModule`.

The newly added APIs are tree-shakable and you can add features using special functions rather than using `ExtraOptions` to control the providers via an internal switch in Router code.

```
const appRoutes: Routes = [];
bootstrapApplication(AppComponent,
  {
    providers: [
      provideRouter(appRoutes,
        withDebugTracing(),     // enables debug tracing feature
        withInMemoryScrolling() // enables scrolling feature
    ]
  }
);
```

This "features" pattern allows for router behavior to evolve in a backwards compatible and tree-shakable way in the future. This approach also makes features more discoverable.

The newly added APIs can be used in any application today (doesn't require an application to be bootstrapped using standalone-based APIs).

Note: APIs added in this commit are released in the "Developer Preview" mode, read more about this mode in Angular docs: https://angular.io/guide/releases#developer-preview
@mary-poppins
Copy link

You can preview 87b1b3e at https://pr47010-87b1b3e.ngbuilds.io/.

@AndrewKushnir
Copy link
Contributor

Presubmit (TGP).

@AndrewKushnir AndrewKushnir added action: merge The PR is ready for merge by the caretaker and removed action: presubmit The PR is in need of a google3 presubmit labels Aug 13, 2022
@AndrewKushnir
Copy link
Contributor

FYI, TGP is "green", the PR is now ready for merge 🎉

@alxhub
Copy link
Member

alxhub commented Aug 15, 2022

This PR was merged into the repository by commit 75df404.

@alxhub alxhub closed this in 75df404 Aug 15, 2022
crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request Sep 1, 2022
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@angular/animations](https://github.com/angular/angular) | dependencies | minor | [`14.1.3` -> `14.2.0`](https://renovatebot.com/diffs/npm/@angular%2fanimations/14.1.3/14.2.0) |
| [@angular/common](https://github.com/angular/angular) | dependencies | minor | [`14.1.3` -> `14.2.0`](https://renovatebot.com/diffs/npm/@angular%2fcommon/14.1.3/14.2.0) |
| [@angular/compiler](https://github.com/angular/angular) | dependencies | minor | [`14.1.3` -> `14.2.0`](https://renovatebot.com/diffs/npm/@angular%2fcompiler/14.1.3/14.2.0) |
| [@angular/compiler-cli](https://github.com/angular/angular/tree/main/packages/compiler-cli) ([source](https://github.com/angular/angular)) | devDependencies | minor | [`14.1.3` -> `14.2.0`](https://renovatebot.com/diffs/npm/@angular%2fcompiler-cli/14.1.3/14.2.0) |
| [@angular/core](https://github.com/angular/angular) | dependencies | minor | [`14.1.3` -> `14.2.0`](https://renovatebot.com/diffs/npm/@angular%2fcore/14.1.3/14.2.0) |
| [@angular/forms](https://github.com/angular/angular) | dependencies | minor | [`14.1.3` -> `14.2.0`](https://renovatebot.com/diffs/npm/@angular%2fforms/14.1.3/14.2.0) |
| [@angular/platform-browser](https://github.com/angular/angular) | dependencies | minor | [`14.1.3` -> `14.2.0`](https://renovatebot.com/diffs/npm/@angular%2fplatform-browser/14.1.3/14.2.0) |
| [@angular/platform-browser-dynamic](https://github.com/angular/angular) | dependencies | minor | [`14.1.3` -> `14.2.0`](https://renovatebot.com/diffs/npm/@angular%2fplatform-browser-dynamic/14.1.3/14.2.0) |

---

### Release Notes

<details>
<summary>angular/angular</summary>

### [`v14.2.0`](https://github.com/angular/angular/blob/HEAD/CHANGELOG.md#&#8203;1420-2022-08-25)

[Compare Source](angular/angular@14.1.3...14.2.0)

##### animations

| Commit | Type | Description |
| -- | -- | -- |
| [b96e571897](angular/angular@b96e571) | fix | fix stagger timing not handling params ([#&#8203;47208](angular/angular#47208)) |

##### common

| Commit | Type | Description |
| -- | -- | -- |
| [b380fdd59e](angular/angular@b380fdd) | feat | add a density cap for image srcsets ([#&#8203;47082](angular/angular#47082)) |
| [7ce497e5bc](angular/angular@7ce497e) | feat | add built-in Imgix loader ([#&#8203;47082](angular/angular#47082)) |
| [bff870db61](angular/angular@bff870d) | feat | add cloudflare loader ([#&#8203;47082](angular/angular#47082)) |
| [86e77a5d55](angular/angular@86e77a5) | feat | add Image directive skeleton ([#&#8203;45627](angular/angular#45627)) ([#&#8203;47082](angular/angular#47082)) |
| [0566205a02](angular/angular@0566205) | feat | Add image lazy loading and fetchpriority ([#&#8203;47082](angular/angular#47082)) |
| [4e952ba216](angular/angular@4e952ba) | feat | add loaders for cloudinary & imagekit ([#&#8203;47082](angular/angular#47082)) |
| [e854a8cdde](angular/angular@e854a8c) | feat | add loading attr to NgOptimizedImage ([#&#8203;47082](angular/angular#47082)) |
| [8d3701cb4c](angular/angular@8d3701c) | feat | add warnings re: image distortion ([#&#8203;47082](angular/angular#47082)) |
| [d5f7da2120](angular/angular@d5f7da2) | feat | define public API surface for NgOptimizedImage directive ([#&#8203;47082](angular/angular#47082)) |
| [d3c3426aa4](angular/angular@d3c3426) | feat | detect LCP images in `NgOptimizedImage` and assert if `priority` is set ([#&#8203;47082](angular/angular#47082)) |
| [451b85ca17](angular/angular@451b85c) | feat | explain why width/height is required ([#&#8203;47082](angular/angular#47082)) |
| [586274fe65](angular/angular@586274f) | feat | provide an ability to exclude origins from preconnect checks in NgOptimizedImage ([#&#8203;47082](angular/angular#47082)) |
| [57f3386e5b](angular/angular@57f3386) | feat | support custom srcset attributes in NgOptimizedImage ([#&#8203;47082](angular/angular#47082)) |
| [7baf9a46cd](angular/angular@7baf9a4) | feat | verify that priority images have preconnect links ([#&#8203;47082](angular/angular#47082)) |
| [f81765b333](angular/angular@f81765b) | feat | warn if rendered size is much smaller than intrinsic ([#&#8203;47082](angular/angular#47082)) |
| [e2ab99b95e](angular/angular@e2ab99b) | fix | allow null/undefined to be passed to ngClass input ([#&#8203;39280](angular/angular#39280)) ([#&#8203;46906](angular/angular#46906)) |
| [bedf537951](angular/angular@bedf537) | fix | allow null/undefined to be passed to ngStyle input ([#&#8203;47069](angular/angular#47069)) |
| [f9511bf6e8](angular/angular@f9511bf) | fix | avoid interacting with a destroyed injector ([#&#8203;47243](angular/angular#47243)) |
| [dc29e21b14](angular/angular@dc29e21) | fix | consider density descriptors with multiple digits as valid ([#&#8203;47230](angular/angular#47230)) |
| [801daf82d1](angular/angular@801daf8) | fix | detect `data:` and `blob:` inputs in `NgOptimizedImage` directive ([#&#8203;47082](angular/angular#47082)) |
| [fff8056e7f](angular/angular@fff8056) | fix | fix formatting on oversized image error ([#&#8203;47188](angular/angular#47188)) ([#&#8203;47232](angular/angular#47232)) |
| [1ca2ce19ab](angular/angular@1ca2ce1) | fix | remove default for image width ([#&#8203;47082](angular/angular#47082)) |
| [c5db867ddc](angular/angular@c5db867) | fix | remove duplicate deepForEach ([#&#8203;47189](angular/angular#47189)) |
| [1cf43deb18](angular/angular@1cf43de) | fix | sanitize `rawSrc` and `rawSrcset` values in NgOptimizedImage directive ([#&#8203;47082](angular/angular#47082)) |
| [d71dfe931f](angular/angular@d71dfe9) | fix | set bound width and height onto host element ([#&#8203;47082](angular/angular#47082)) |
| [32caa8b669](angular/angular@32caa8b) | fix | support density descriptors with 2+ decimals ([#&#8203;47197](angular/angular#47197)) ([#&#8203;47232](angular/angular#47232)) |
| [ae4405f0bf](angular/angular@ae4405f) | fix | throw if srcset is used with rawSrc ([#&#8203;47082](angular/angular#47082)) |
| [0c8eb8bc82](angular/angular@0c8eb8b) | perf | monitor LCP only for images without `priority` attribute ([#&#8203;47082](angular/angular#47082)) |

##### compiler-cli

| Commit | Type | Description |
| -- | -- | -- |
| [ea89677c12](angular/angular@ea89677) | feat | support more recent version of `tsickle` ([#&#8203;47018](angular/angular#47018)) |

##### core

| Commit | Type | Description |
| -- | -- | -- |
| [d1e83e1b30](angular/angular@d1e83e1) | feat | add `createComponent` function ([#&#8203;46685](angular/angular#46685)) |
| [10becab70e](angular/angular@10becab) | feat | add `reflectComponentType` function ([#&#8203;46685](angular/angular#46685)) |
| [4b377d3a6d](angular/angular@4b377d3) | feat | introduce createApplication API ([#&#8203;46475](angular/angular#46475)) |
| [31429eaccc](angular/angular@31429ea) | feat | support TypeScript 4.8 ([#&#8203;47038](angular/angular#47038)) |
| [796840209c](angular/angular@7968402) | fix | align TestBed interfaces and implementation ([#&#8203;46635](angular/angular#46635)) |

##### forms

| Commit | Type | Description |
| -- | -- | -- |
| [426af91a42](angular/angular@426af91) | feat | add `FormBuilder.record()` method ([#&#8203;46485](angular/angular#46485)) |
| [b302797de4](angular/angular@b302797) | fix | Correctly infer `FormBuilder` types involving `[value, validators]` shorthand in more cases. ([#&#8203;47034](angular/angular#47034)) |

##### language-service

| Commit | Type | Description |
| -- | -- | -- |
| [598b72bd05](angular/angular@598b72b) | feat | support fix the component missing member ([#&#8203;46764](angular/angular#46764)) |

##### platform-browser

| Commit | Type | Description |
| -- | -- | -- |
| [07606e3181](angular/angular@07606e3) | feat | add `isEmpty` method to the `TransferState` class ([#&#8203;46915](angular/angular#46915)) |

##### platform-server

| Commit | Type | Description |
| -- | -- | -- |
| [2b4d7f6733](angular/angular@2b4d7f6) | feat | support document reference in render functions ([#&#8203;47032](angular/angular#47032)) |

##### router

| Commit | Type | Description |
| -- | -- | -- |
| [0abb67af59](angular/angular@0abb67a) | feat | allow guards and resolvers to be plain functions ([#&#8203;46684](angular/angular#46684)) |
| [75df404467](angular/angular@75df404) | feat | Create APIs for using Router without RouterModule ([#&#8203;47010](angular/angular#47010)) |
| [10289f1f6e](angular/angular@10289f1) | feat | expose resolved route title ([#&#8203;46826](angular/angular#46826)) |
| [8600732b09](angular/angular@8600732) | feat | Expose the default matcher for `Routes` used by the `Router` ([#&#8203;46913](angular/angular#46913)) |
| [422323cee0](angular/angular@422323c) | feat | improve typings for RouterLink boolean inputs ([#&#8203;47101](angular/angular#47101)) |
| [26ea97688c](angular/angular@26ea976) | feat | Make router directives standalone ([#&#8203;46758](angular/angular#46758)) |
| [2a43beec15](angular/angular@2a43bee) | fix | Fix route recognition behavior with some versions of rxjs ([#&#8203;47098](angular/angular#47098)) |

##### service-worker

| Commit | Type | Description |
| -- | -- | -- |
| [383090858c](angular/angular@3830908) | feat | support `sendRequest` as a `notificationclick` action ([#&#8203;46912](angular/angular#46912)) |
| [3f548610dd](angular/angular@3f54861) | fix | export NoNewVersionDetectedEvent ([#&#8203;47044](angular/angular#47044)) |
| [482b6119c2](angular/angular@482b611) | fix | update golden `index.md` ([#&#8203;47044](angular/angular#47044)) |

#### Special Thanks

Alex Rickabaugh, Andrew Kushnir, Andrew Scott, Bob Watson, Cédric Exbrayat, Dylan Hunn, Emmanuel Roux, FatalMerlin, George Kalpakas, Ilia Mirkin, Jan Kuehle, Jeremy Elbourn, Jessica Janiuk, JiaLiPassion, Kalbarczyk, Kara Erickson, Katie Hempenius, Kristiyan Kostadinov, Merlin, Paul Gschwendtner, Pawel Kozlowski, Tristan Sprößer, Victor Porof, angular-robot\[bot], dario-piotrowicz, ivanwonder and vyom

<!-- CHANGELOG SPLIT MARKER -->

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, click this checkbox.

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzMi4xNzQuMiIsInVwZGF0ZWRJblZlciI6IjMyLjE3Ny4xIn0=-->

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1523
Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker aio: preview area: router target: minor This PR is targeted for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants