Commit graph

255 commits

Author SHA1 Message Date
Alex Rickabaugh
de802f0c1a Revert "fix(http): Don't override the backend when using the InMemoryWebAPI (#52425)"
This reverts commit 49b037f811. Reason: it
breaks tests in aio-local.
2023-10-31 16:16:16 -07:00
Matthieu Riegler
08f4c5221a build: add missing entries for the api extraction (#52452)
Were missing :

* `@angular/common/http/testing`
* `@angular/platform-browser/animations/async`

PR Close #52452
2023-10-31 14:53:34 -07:00
Matthieu Riegler
49b037f811 fix(http): Don't override the backend when using the InMemoryWebAPI (#52425)
When using `withFetch`,  the `PRIMARY_HTTP_BACKEND` token is set.

The InMemory Backend services will also set that token.

This means that providers order will matter and the latest on the list will be the one instantiated

PR Close #52425
2023-10-31 13:17:19 -07:00
Andrea Canciani
fc9ba3978c refactor: fix a number of typos throughout the codebase (#52249)
Fix some typos such as `boostrap`, `propery` and more, both in
documentation and in code (comments, identifiers).

PR Close #52249
2023-10-25 16:51:24 -07:00
Jan Kuehle
ebbc7a27e8 refactor: change public const enums to enums (#51670)
Angular recently gained a local compilation mode (see commit
345dd6d81a). This is intended to be used
with the TypeScript compiler option isolatedModules, which bans imports
of const enums.

This changes all const enums tagged with @publicApi to regular enums.

Fixes #46240

PR Close #51670
2023-10-25 10:39:18 -07:00
Alan Agius
c5e30f1d79 perf(http): reduce data transfer when using HTTP caching (#52347)
This commit reduces the property size in the http transfer cache to reduce the page payload.

Before
```html
<script id="ng-state" type="application/json">
{
  "4155228514": {
    "body": "....",
    "headers": {},
    "status": 200,
    "statusText": "OK",
    "url": "http://foo.com/assets/media.json",
    "responseType": "json"
  },
}
</script>
```

Now
```html
<script id="ng-state" type="application/json">
{
  "4155228514": {
    "b": "....",
    "h": {},
    "s": 200,
    "st": "OK",
    "u": "http://foo.com/assets/media.json",
    "rt": "json"
  },
}
</script>
```

PR Close #52347
2023-10-24 14:33:26 -07:00
Alan Agius
405ec8c796 fix(platform-server): resolve relative requests URL (#52326)
Prior to this commit relative HTTP requests were not being resolved to absolute even thought the behaviour is documented in https://angular.io/guide/universal#using-absolute-urls-for-http-data-requests-on-the-server.

This caused relative HTTP requests to fail when done on the server because of missing request context. This change is also required to eventually support HTTP requests handled during prerendering (SSG).

Closes #51626

PR Close #52326
2023-10-23 12:02:21 -07:00
Andrew Kushnir
d10f2b29d7 refactor(core): use performance API for hydration-related features (#52288)
This commit adds a standard performance marker that can be viewed in Chrome dev tools and other tooling. See more info at https://developer.mozilla.org/en-US/docs/Web/API/Performance/mark

PR Close #52288
2023-10-23 09:29:36 -07:00
Kristiyan Kostadinov
c07805612f test(core): clean up unnecessary nesting in old tests (#52239)
A lot of our tests are wrapped in `{}` which serves no purpose, aside from increasing the nesting level and, in some cases, causing confusion. The braces appear to be a leftover from a time when all tests were wrapped in a `function main() {}`. The function declaration was removed in #21053, but the braces remained, presumably because it was easier to search&replace for `function main()`, but not to remove the braces at the same time.

PR Close #52239
2023-10-19 09:26:15 -07:00
Andrew Kushnir
eee5a5a1af docs: promote withFetch and FetchBackend to stable (#52197)
This commit removes the `@developerPreview` annotation from the `withFetch` and `FetchBackend` APIs, promoting them to stable.

PR Close #52197
2023-10-18 18:21:48 +02:00
Jeremy Elbourn
fcc000e803 build: add targets for api doc generation (#52034)
This adds `generate_api_docs` targets to all of the packages for which we publish api reference docs. One known issue here is that any type information that comes from another package (e.g. router depending on core) currently resolve to `any` because the other sources are not available in the program. This can be tackled in a follow-up commit.

This commit also updates the install patch for `@angular/build-tools` to use the local version of compiler-cli.

PR Close #52034
2023-10-10 16:18:50 -07:00
Matthieu Riegler
7dde42a5df feat(http): allow customization of the HttpTransferCache. (#52029)
`provideClientHydration()` accepts new `HydrationFeature` : `HttpTransferCacheOptions`.

`withHttpTransferCacheOptions` accepts an option object:
* `includeHeaders` : list of headers entries to keep in the cache with the request
* `filter` a callback to determine if a request should be cached
* `includePostRequests`: to include POST requests in the allowed methods

Implements some of the features requested in #50117

PR Close #52029
2023-10-06 12:12:47 -07:00
Andrew Kushnir
22fa9fe488 docs: recommend enabling fetch support in HttpClient when using SSR (#52056)
PR Close #52056
2023-10-05 16:54:58 -07:00
Andrew Kushnir
760bfdc4bf refactor(http): warn when HttpClient doesn't use fetch during SSR (#52037)
This commit adds a logic to produce a warning in case HttpClient doesn't use fetch during SSR.
It's recommended to use `fetch` for performance and compatibility reasons.

PR Close #52037
2023-10-05 16:52:41 -07:00
Matthieu Riegler
85e31465c9 refactor(http): create an InjectionToken for a global HttpBackend (#51999)
`withHttp` provides the new `PRIMARY_HTTP_BACKEND` token with `FetchBackend` to use it globally.

PR Close #51999
2023-10-04 07:26:18 -07:00
Alan Agius
8413b64a6b refactor(core): add whenStable private API (#51807)
Prior to this change `this.isStable.pipe(first((isStable) => isStable)).toPromise()` had to be done in multiple places across the framework and the Angular CLI see https://github.com/angular/angular-cli/pull/25856#discussion_r1328158846. In the majority of cases an Observable based `isStable` API is not needed. This also removes the need for RXJS operator imports.

PR Close #51807
2023-09-27 10:31:56 -07:00
Jeremy Mowery
635318fd61 refactor: add readonly to public InjectionToken types (#51407)
This fixes warnings caused by an internal lint rule

refactor: add readonly to public InjectionToken types

PR Close #51407
2023-09-12 12:55:14 -07:00
Joey Perrott
0907f396d5 build: migrate to node 18 (#51609)
Migrate to use node version 18

PR Close #51609
2023-09-01 15:12:43 +00:00
Matthieu Riegler
17c6ad7775 docs: Add usage information to HttpInterceptorFn (#51236)
Simple doc addendum

PR Close #51236
2023-08-15 10:02:43 -07:00
arturovt
57e8412e53 fix(http): check whether Zone is defined (#51119)
Accessing the `Zone` variable without checking if it's defined or not
leads to an error "Zone is not defined" if zone.js is not imported (nooped).
This commit adds an additional check before getting the current zone where
the `doRequest` is being called.

PR Close #51119
2023-07-21 16:45:26 +00:00
Matthieu Riegler
c5608e5ca9 fix(http): Run fetch request out the angular zone (#50981)
Having the request run in the angular zone has the consequence of triggering the CD for every read of the response stream.

This commit wraps the whole `doRequest` to run outside angular with every callback on the observer being called inside the zone.

Fixes #50979.

PR Close #50981
2023-07-17 14:53:52 +00:00
Alan Agius
232a78630e ci: re-enable RBE for http tests (#50741)
This commit enables RBE for common http tests which is now possible as the latest version of build-tooling supports Node.js 18.

PR Close #50741
2023-06-23 09:37:48 -07:00
mgechev
9f2fb7c6dc docs: update invalid links to the new http guides (#49456)
We don't have `guide/http` anymore, so this PR updates the invalid links

PR Close #49456
2023-06-22 17:06:59 -07:00
alkavats1
66824b7715 refactor: removed the unused declaration in the import statement (#50616)
ngmodule and httpclient modeule is removed from the provider.ts file from the import statement

PR Close #50616
2023-06-22 09:39:58 -07:00
Heo Sangmin
a126cbcf22 fix(http): use serializeBody to support JSON payload in FetchBackend (#50776)
`HttpRequest.serializeBody` was used in HttpXhrBackend. `fetch` also needs to serialize request body.

Close #50775

PR Close #50776
2023-06-20 13:31:25 -07:00
Matthieu Riegler
135167fe8e fix(http): Send query params on fetch request (#50740)
QueryParams were missing when using the `FetchBackend`.

Fixes #50728

PR Close #50740
2023-06-20 12:59:26 +02:00
Alan Agius
4550fe42f7 refactor: use queueMicrotask to schedule micro tasks instead of various helpers (#50485)
`queueMicrotask` is an API which is supported by all browser and Node.js versions.

PR Close #50485
2023-06-15 16:38:21 +02:00
Matthieu Riegler
85c5427582 feat(http): Introduction of the fetch Backend for the HttpClient (#50247)
This commit introduces a new `HttpBackend` implentation which makes requests using the fetch API

This feature is a developer preview and is opt-in.
It is enabled by setting the providers with `provideHttpClient(withFetch())`.

NB: The fetch API is experimental on Node but available without flags from Node 18 onwards.

PR Close #50247
2023-06-08 09:48:12 -07:00
Alan Agius
37d3664cf5 build: run //packages/common/http/test on Node.js 18 (#50247)
This commits adds configures `//packages/common/http/test` to use Node.js 18 toolchain which is needed to test the fetch implementation which use Node.js 18 APIs.

We also disable RBE for this target as it doesn't work with Node.js 18 right now. See https://github.com/angular/dev-infra/issues/1017

PR Close #50247
2023-06-08 09:48:11 -07:00
Alan Agius
0c80349cf6 refactor(http): replace zone.js macrotask creation with InitialRenderPendingTasks (#50425)
This commits refactors the HTTP client to use `InitialRenderPendingTasks` instead of Zone.js macrotask. This is another approach to https://github.com/angular/angular/pull/50406 which was revert due to a failure in G3.

PR Close #50425
2023-05-30 12:58:22 -07:00
Alan Agius
28c68f709c fix(core): update ApplicationRef.isStable to account for rendering pending tasks (#50425)
This commit updates the `ApplicationRef.isStable` API to account for
pending rendering task. This is needed as once a pending rendering task
is done, new macrotask and microtask could be created which previously caused these not
to be intercepted and thus ignored when doing SSR.

PR Close #50425
2023-05-30 12:58:22 -07:00
Dylan Hunn
6f5dabe0d2 Revert "fix(http): create macrotask during request handling instead of load start (#50406)" (#50475)
This reverts commit 2cdb4c5911.

PR Close #50475
2023-05-25 16:24:39 -04:00
Alan Agius
2cdb4c5911 fix(http): create macrotask during request handling instead of load start (#50406)
This commit schedules the macrotask creation to happen before the XHR `loadStart` event. This is needed as in some cases, Zone.js becomes stable too early.

With this commit, we also update the internal `createBackgroundMacroTask` method to use Zone.js `scheduleMacroTask` as otherwise the `setTimeout` would cause `fakeAsync` tests to fail due to pending timers.

Closes #50405

PR Close #50406
2023-05-24 15:33:43 +00:00
Matthieu Riegler
5fd4bf6651 refactor(http): tree-shakable error on JSONP request (#50376)
This commit provides a tree shakable error message (+doc) when JSONP request is made without loading the `HttpClientJsonpModule`.

PR Close #50376
2023-05-24 13:58:49 +00:00
Kristiyan Kostadinov
69dadd2502 feat(core): support TypeScript 5.1 (#50156)
Updates the project to support building with TypeScript 5.1.

PR Close #50156
2023-05-09 14:44:30 -07:00
Andrew Kushnir
59837f4749 refactor(platform-server): import xhr2 dynamically in the ServerXhr class (#50095)
This commit updates the `@angular/common/http` and `@angular/platform-server` packages to allow dynamic import of the `xhr2` dependency. The `xhr2` dependency has side-effects that rely on a global scope and as a result in some environments those side-effectful calls fail. With the changes from this PR, the import is delayed until it's actually needed, which gives a chance for the underlying platform to setup global scope (via shims) as needed.

Co-authored-by: alan-agius4 <17563226+alan-agius4@users.noreply.github.com>

PR Close #50095
2023-05-08 14:32:43 -07:00
Matthieu Riegler
8741670a2d docs: Make links out of @see tags (#50098)
This commit is part of the work for #50097 to improve the linking on the online documentation.

PR Close #50098
2023-05-02 13:14:25 +02:00
Alan Agius
ddf0d4eabe fix(http): HTTP cache was being disabled prematurely (#49826)
This commit fixes an issue were on the server the HTTP cache was being disabled prematurely which caused HTTP calls performed in `ngOnInit` life cycle hooks not to be cached.

PR Close #49826
2023-04-13 14:04:00 +00:00
Danilo Bassi
ab5e2d9387 fix(http): prevent headers from throwing an error when initializing numerical values (#49379)
Some libraries could use numbers in headers. this fix prevents Angular from
throwing an error by casting those numerical values into strings.

Fixes #49353

PR Close #49379
2023-04-13 14:00:16 +00:00
Alan Agius
f9b821f07d fix(http): delay accessing pendingTasks.whenAllTasksComplete (#49784)
Accessing `pendingTasks.whenAllTasksComplete` too early causes the `InitialRenderPendingTasks` to return a resolved promise too early. This commit changes the way we access `whenAllTasksComplete` to only happen when the application is stabilized.

PR Close #49784
2023-04-11 14:12:38 -07:00
Alan Agius
079f4bc1ef fix(http): wait for all XHR requests to finish before stabilizing application (#49776)
Previously, since the `HttpXhrBackend` is a singleton, the macrotask was created and completed only for the initial request since it was stored as in property in the class instance. This commit replaces this logic to create a macro task for every XHR request.

Closes #49730

PR Close #49776
2023-04-11 13:44:30 -07:00
Andrew Kushnir
7ee542d263 refactor(platform-server): include info about enabled features into ng-server-context (#49773)
This commit updates the logic that adds the "ng-server-context" attribute to the root elements to also include information about SSR feature enabled got an application.

PR Close #49773
2023-04-11 12:46:09 -07:00
Brandon Roberts
0b3677e149 fix(http): ensure new cache state is returned on each request (#49749)
The cache state is only used only the first server request. Restarting the server uses the cache on first request.

Subsequent requests skip the cache because the value is mutated.

This change ensures a new cache state is returned on every request.

PR Close #49749
2023-04-11 10:40:04 -07:00
Alan Agius
81e7d15ef6 feat(platform-browser): enable HTTP request caching when using provideClientHydration (#49699)
This commit adds support by default for HTTP caching when using `provideClientHydration`. Users can opt-out of this behaviour by using the `withoutHttpTransferCache` feature.

```ts
import {
  bootstrapApplication,
  provideClientHydration,
  withNoHttpTransferCache,
} from '@angular/platform-browser';
// ...
bootstrapApplication(RootCmp, {
  providers: [provideClientHydration(withNoHttpTransferCache())]
});
```

PR Close #49699
2023-04-04 15:04:03 -07:00
Alan Agius
aff1512950 feat(http): allow HttpClient to cache requests (#49509)
This commit adds a new option for `provideHttpClient` called
`withHttpTransferCache()`. When this option is passed, requests done on the server are cached and reused during the  bootstrapping of the application in the browser thus avoiding duplicate requests and reducing load time.

This is the same as `TransferHttpCacheModule` in https://github.com/angular/universal/blob/main/modules/common/src/transfer_http.ts

PR Close #49509
2023-04-03 19:13:45 -07:00
Alan Agius
45a6ac09fd fix(http): force macro task creation during HTTP request (#49546)
This commit adds a background macrotask when an XHR request is performed. The macrotask is started during `loadstart` and ended during `loadend` event.

The macrotask is needed so that the application is not stabilized during HTTP calls. This is important for server rendering, as the application is rendering when the application is stabilized.
The application is stabilized when there are no longer pending Macro and Micro tasks intercepted by Zone.js, Since an XHR request is none of these, we create a background macrotask so that Zone.js is
made aware that there is something pending.

Prior to this change, we patched the `HttpHandler` in `@angular/platform-server` but this is not enough, as there can be multiple `HttpHandler` in an application, example when importing `HttpClient` in a lazy loaded component/module.
Which causes a new unpatched instance of `HttpHandler` to be created in the child injector which is not intercepted by Zone.js and thus the application is stabalized and rendered before the XHR request is finalized.

NB: Zone.js is fundamental for SSR and currently, it's not possible to do SSR without it.

Closes: #49425

PR Close #49546
2023-03-29 09:13:41 -07:00
Alan Agius
c41a21658c refactor(common): remove deprecated XhrFactory export from http entrypoint (#49251)
The deprecated `XhrFactory` export from `@angular/common/http` has been removed.

BREAKING CHANGE:

Deprecated `XhrFactory` export from `@angular/common/http` has been removed. Use `XhrFactory` from `@angular/common` instead.

PR Close #49251
2023-03-01 12:33:03 -08:00
cexbrayat
8fb63dff94 refactor(http): simplify HttpClientModule XSRF configuration (#48957)
The current configuration of `HttpClientModule` explicitely enables the XSRF configuration,
but this XSRF configuration is the one used by default by `provideHttpClient`.

See https://github.com/angular/angular/blob/main/packages/common/http/src/provider.ts#L50-L98

PR Close #48957
2023-02-17 11:17:53 -08:00
Paul Gschwendtner
424035730a refactor: update packages/common tests to work with ESM pipeline (#48521)
We no longer have generated `.js` files as everything generated
is the ESM `.mjs` output. The tests need to be updated to reflect that.

PR Close #48521
2022-12-19 19:50:42 +00:00
Paul Gschwendtner
c9415e4d75 build: ensure bootstrap transitive runfiles are made available (#48521)
Since we generate a `.mjs` file as entry-point for jasmine tests,
a couple of issues prevented the transitive dependencies from
bootstrap targets to be brought in (causing resolution errors):

1. The `_files` (previously `_esm2015`) targets are no longer needed,
   and they also miss all the information on runfiles.
2. The aspect for computing linker mappings does not respect the
   `bootstrap` attribute from the `spec_entrypoint` so we manually
   add the extract ESM output targets (this rule works with the aspect
   and forwards linker mappings).

PR Close #48521
2022-12-19 19:50:41 +00:00