3319 Commits

Author SHA1 Message Date
Alex Castle 37bbc61cfe feat(common): Backport NgOptimizedImage to Angular 14.
Add files and tests from Angular 15 NgOptimizedImage to Angular 14 as a special project by Chrome Aurora
2023-03-08 17:31:31 +01:00
Andrew Kushnir 244a7d2d0c docs(core): add an error details page for unsafe <iframe> bindings (#48028)
PR Close #48028
2022-11-21 12:19:54 -08:00
Andrew Kushnir 54814c8e9b fix(core): hardening attribute and property binding rules for <iframe> elements (#48028)
This commit updates the logic related to the attribute and property binding rules for <iframe> elements. There is a set of <iframe> attributes that may affect the behavior of an iframe and this change enforces that these attributes are only applied as static attributes, making sure that they are taken into account while creating an <iframe>.

If Angular detects that some of the security-sensitive attributes are applied as an attribute or property binding, it throws an error message, which contains the name of an attribute that is causing the problem and the name of a Component where an iframe is located.

BREAKING CHANGE:

Existing iframe usages may have security-sensitive attributes applied as an attribute or property binding in a template or via host bindings in a directive. Such usages would require an update to ensure compliance with the new stricter rules around iframe bindings.

PR Close #48028
2022-11-21 12:19:54 -08:00
Alan Agius a4312e1be5 fix(core): add zone.js version 0.12.x as a valid peer dependency (#48002)
This commit adds `zone.js` version `0.12.x` as a valid peer dependency

PR Close #48002
2022-11-09 09:54:11 -08:00
Kristiyan Kostadinov c3bc035f5d refactor(core): remove duplicate createRenderer call (#47981)
Fixes that we were calling `createRenderer` even though we had one already. This likely wasn't a performance issue since the renderer factory caches the renderer, but it's still better to reuse it to avoid confusion in the future.

Fixes #47980.

PR Close #47981
2022-11-07 12:33:24 -08:00
Ciprian Sauliuc 60e758a837 docs: add oxford commas and rephrase sentences (#47540)
PR Close #47540
2022-09-29 16:41:32 -07:00
Alan Agius 2c46b5ab24 fix(core): correctly check for typeof of undefined in ngDevMode check (#47480)
Previously, this check was wrong as typeof returns a string.

PR Close #47480
2022-09-23 14:00:46 -07:00
dario-piotrowicz bba2dae812 fix(animations): make sure that the useAnimation function delay is applied (#47468)
make sure that when an animation is used via the `useAnimation` function
and a delay has been provided then that delay gets correctly applied

(this PR is a follow up for #47285)

PR Close #47468
2022-09-20 10:10:24 +02:00
Andrew Kushnir e21494a333 refactor(core): drop RootContext object (#47056)
In a previous refactor, the `RootContext` was update to only contain a reference to a component. This commit perform further refactoring to get rid of the `RootContext` altogether, while storing component reference directly on the root view (without the `RootContext` wrapper).

PR Close #47056
2022-09-13 09:21:35 -07:00
dario-piotrowicz 937e6c5b3d fix(animations): make sure that the animation function delay is applied (#47285)
make sure that when an animation is defined via the `animation` function
(and used via `useAnimation`) and a delay has been provided then that
delay gets correctly applied

resolves #47283

PR Close #47285
2022-09-13 09:20:45 -07:00
Sebastian 24e5c2a83f docs(core): fix viewProviders & providers typos in NodeInjectorFactory (#47408)
Fixes incorrect spellings for providers (provides) and viewProviders (viewProvides) in NodeInjectorFactory examples
PR Close #47408
2022-09-13 09:20:18 -07:00
Andrew Kushnir c9bdf9bab1 fix(common): rename rawSrc -> ngSrc in NgOptimizedImage directive (#47362) (#47396)
As an ongoing effort to stabilize the NgOptimizedImage API before existing the Developer Preview, this commit renames the `rawSrc` attribute used for the NgOptimizedImage selector matching to `ngSrc`. The `rawSrcset` is also renamed to `ngSrcset` for consistency.

The motivation for this change is to align the attribute name better with other built-in directives, such as `ngFor`, `ngIf`, `ngClass`, `ngStyle`, etc.

Note: this is technically a breaking change, but since the NgOptimizedImage directive is in the Developer Preview mode, we land the change in a patch branch.

PR Close #47362

PR Close #47396
2022-09-12 01:18:55 -07:00
Andrew Kushnir a61d553d73 refactor(common): drop unnecessary srcset sanitization (#47302)
This commit updates runtime and compiler to drop unnecessary `srcset` sanitization. The sanitization was needed previously for old browsers, but all modern browsers can handle `srcset` safely without any additional sanitization.

See prior discussion in https://github.com/angular/angular/pull/45182.

Resolves #45164.

PR Close #47302
2022-09-09 14:27:16 -07:00
Andrew Kushnir 403b970e78 refactor(common): create an NgFor alias for NgForOf directive (#47309)
This commit adds a re-export of the `NgForOf` class as `NgFor` to improve the DX for cases when the directive is used as standalone. Developers can import `NgFor` class, which better matches the `ngFor` attribute used in a template.

PR Close #47309
2022-09-09 14:04:55 -07:00
Pawel Kozlowski a3e1303f04 fix(core): imply @Optional flag when a default value is provided (#47242)
Unify default value handling across injector and node injector: as long
as a default value is provided it has the same effect as specifying the
@Optional() flag.

Fixes #47109

PR Close #47242
2022-09-08 09:34:18 -07:00
Kara Erickson c0d7ac9ec2 fix(common): improve formatting of image warnings (#47299)
This is a tiny fix to add paragraph breaks in
image distortion warnings to make them a bit
easier to read. With this change, the intrinsic
and rendered image sizes are printed on their
own lines instead of mid-paragraph.

PR Close #47299
2022-09-06 09:55:57 -07:00
Kristiyan Kostadinov 20e1a2470b build: update to TypeScript 4.8 final (#47270) (#47278)
Bumps up to the final version of TS 4.8 and removes some workarounds.

PR Close #47270

PR Close #47278
2022-08-26 10:27:55 -07:00
Alex Rickabaugh e9ac16ad02 Revert "fix(animations): fix stagger timing not handling params (#47208)" (#47222)
This reverts commit 05f5e8ad86.

Reason: breaks internal g3 tests

PR Close #47222
2022-08-22 14:53:21 -07:00
dario-piotrowicz b96e571897 fix(animations): fix stagger timing not handling params (#47208)
prior to this change the stagger timing was being built during the
ast building instead of dynamically when visiting the stagger animation,
thus it could not handle params correctly, this change makes it so that
during ast building a timing ast is built instead and that ast is used
dynammically to build animations which can handle params correctly

resolves #19786

PR Close #47208
2022-08-22 10:51:30 -07:00
Jeremy Elbourn d14603fdb5 refactor(core): remove obsolete data: url validation (#45860)
Validation for `data:` urls is obsolete now that modern browsers ([Firefox as of v57+](https://blog.mozilla.org/security/2017/10/04/treating-data-urls-unique-origins-firefox-57)) don't treat `data:` urls as same-origin resources.

Googlers can see  internal change cl/363609175 for additional context.

PR Close #45860
2022-08-18 13:41:44 -07:00
Andrew Kushnir 0ca5eb3088 refactor(common): minor NgOptimizedImage directive updates (#47082)
This commit contains a set of small changes based on the feedback received in #47082.

PR Close #47082
2022-08-16 17:36:54 +00:00
Kara Erickson f81765b333 feat(common): warn if rendered size is much smaller than intrinsic (#47082)
This commit adds a console warning in development mode
if the ultimate rendered size of the image is much
smaller than the dimensions of the requested image.
In this case, the warning recommends adjusting the
size of the source image or using the `rawSrcset`
attribute to implement responsive sizing.

PR Close #47082
2022-08-16 17:36:54 +00:00
Andrew Kushnir a1bcfd029b docs: add description and usage notes to the NgOptimizedImage directive (#47082)
This commit adds the docs for the NgOptimizedImage directive.
As a part of this commit, we also remove an export of directive-related symbols previously exposed as public APIs (i.e. APIs can not be used directly).

PR Close #47082
2022-08-16 17:36:54 +00:00
Andrew Kushnir d3c6c37a12 refactor(common): make NgOptimizedImage directive standalone (#47082)
This commit updates the NgOptimizedImage directive to become standalone and removes no longer needed NgOptimizedImageModule class.

PR Close #47082
2022-08-16 17:36:54 +00:00
Andrew Kushnir f995f9fad1 refactor(common): update error messages of NgOptimizedImage directive (#47082)
This commit updates error messages that the NgOptimizedImage directive throws or logs into a console.

PR Close #47082
2022-08-16 17:36:54 +00:00
Katie Hempenius 8d3701cb4c feat(common): add warnings re: image distortion (#47082)
Checks whether image is visually distorted. Also adds a check to verify that width and height are set to a non-zero number.

PR Close #47082
2022-08-16 17:36:53 +00:00
Andrew Kushnir 586274fe65 feat(common): provide an ability to exclude origins from preconnect checks in NgOptimizedImage (#47082)
This commit adds an extra logic to add an ability to exclude origins from preconnect checks in NgOptimizedImage by configuring the `PRECONNECT_CHECK_BLOCKLIST` multi-provider.

PR Close #47082
2022-08-16 17:36:53 +00:00
Andrew Kushnir 7baf9a46cd feat(common): verify that priority images have preconnect links (#47082)
This commit updates the `NgOptimizedImage` directive to add a logic to detect whether an image, marked with the "priority" attribute has a corresponding `<link rel="preconnect">` tag in the `document.head` for better performance.

PR Close #47082
2022-08-16 17:36:53 +00:00
Kara Erickson 7ce497e5bc feat(common): add built-in Imgix loader (#47082)
This commit adds a built-in Imgix loader for the
NgOptimizedImage directive. If you provide the
desired Imgix hostname, an ImageLoader will be
generated with the correct options.

Usage looks like this:

```ts
providers: [
  provideImgixLoader('https://some.imgix.net')
]
```

It sets the "auto=format" flag by default, which
ensures that the smallest image format supported
by the browser is served.

This change also moves the IMAGE_LOADER, ImageLoader,
and ImageLoaderConfig into a new directory that will
be shared by all built-in image loaders.

PR Close #47082
2022-08-16 17:36:52 +00:00
Kara Erickson 57f3386e5b feat(common): support custom srcset attributes in NgOptimizedImage (#47082)
This commit adds a `rawSrcset` attribute as a replacement for the
`srcset` attribute. The `srcset` attribute cannot be set statically
on the image directive because it would cause images to start
downloading before the "loading" attribute could be set to "lazy".

Changing the name to `rawSrcset` allows the directive to control
the timing of image loading. It also makes it possible to support
custom loaders for `srcset` file names. Rather than having to repeat
the image origin for each image, the existing `rawSrc` value and
image loader can be composed to generate each full URL string. The
developer must only provide the necessary widths for the `srcset`.

For example, the developer might write:

```markup
<img rawSrc="hermes.jpg" rawSrcset="100w, 200w" ... />
```

with a loader like:

```js
const loader = (config) => `path/${config.src}?w=${config.width}`;
```

and the img tag will ultimately be set up as something like:

```markup
<img src="path/hermes.jpg?w=100" srcset="path/hermes.jpg?w=100 100w, path/hermes.jpg?w=200 200w" .../>
```

PR Close #47082
2022-08-16 17:36:52 +00:00
Kara Erickson ae4405f0bf fix(common): throw if srcset is used with rawSrc (#47082)
Currently if you use a static `srcset` with the image directive,
lazy loading no longer works because the image would start to
load before the loading attribute could be set to "lazy". This
commit throws an error if you try to use `srcset` this way.

In a follow-up commit, a new attribute will be added to support
responsive images in a lazy-loading-friendly way.

PR Close #47082
2022-08-16 17:36:52 +00:00
Andrew Kushnir bde319e534 refactor(common): create an NgModule for the NgOptimizedImage directive (#47082)
This commit updates the `NgOptimizedImage` directive to drop the `standalone` flag and create a new NgModule which declares and exports it, so that the directive can be used in apps that use pre-v14 version of Angular.

PR Close #47082
2022-08-16 17:36:52 +00:00
Andrew Kushnir fa1ddda79c test(common): reorg e2e folders for the NgOptimizedImage directive tests (#47082)
This commit updates the e2e folder to separate e2e tests and playground scripts (so it's clear where files are used).

PR Close #47082
2022-08-16 17:36:52 +00:00
Kara Erickson 1ca2ce19ab fix(common): remove default for image width (#47082)
Previously NgOptimizedImage would default to requesting
an image at the width matching the width attribute in
the image HTML. While this works for width attrs that
match the intrinsic size of the image (e.g. responsive
images or images sized with CSS), this can be a sharp
edge for developers who use the width/height attributes
to set rendered size (i.e. instead of CSS, which one can
do for a fixed size image). In this case, defaulting to
the width attribute for the requested image would mean
requesting always at 1x quality, so screens with a DPR
 of 2+ get an image that is too small. Without a default
request width, the image served by the CDN would likely
be at intrinsic size, so 2x images would look correct.

This PR also updates the NgOptimizedImage sandbox and tests.

PR Close #47082
2022-08-16 17:36:52 +00:00
Andrew Kushnir 37e3a6050b test(common): add e2e tests for LCP check logic of the NgOptimizedImage directive (#47082)
This commit adds e2e tests for the LCP check logic. Those tests are needed to verify the behavior in a real browser (vs relying on a Node environment).

PR Close #47082
2022-08-16 17:36:52 +00:00
Andrew Kushnir d3c3426aa4 feat(common): detect LCP images in NgOptimizedImage and assert if priority is set (#47082)
This commit adds extra logic into the `NgOptimizedImage` experimental directive to detect an LCP image and assert whether the `priority` attribute is applied.

PR Close #47082
2022-08-16 17:36:52 +00:00
Andrew Kushnir 1c065403a2 test(common): configure e2e testing infrastructure for NgOptimizedImage test app (#47082)
This commit adds the necessary e2e testing infrastructure to the `NgOptimizedImage` test app, so that the test coverage can be extended and extra scenarios can be tested in a browser.

PR Close #47082
2022-08-16 17:36:52 +00:00
Andrew Kushnir c2854e8ef6 refactor(common): mark experimental NgOptimizedImage directive as standalone (#47082)
This commit updates the `NgOptimizedImage` directive as standalone, so it's easier to import it in
 an app (without importing any NgModules). The `NgOptimizedImageModule` is removed as no longer needed.

PR Close #47082
2022-08-16 17:36:52 +00:00
Andrew Kushnir b58454d129 refactor(common): rename NgOptimizedImage directive selector (#47082)
This commit changes the `NgOptimizedImage` directive selector from `raw-src` to `rawSrc` to better align with the styleguide.

PR Close #47082
2022-08-16 17:36:51 +00:00
Kara Erickson c0d407fccc refactor(common): change name of directive from NgImage => NgOptimizedImage (#47082)
We want it to be clear what benefits the image directive
confers over a normal <img> tag, and the `NgImage` name
didn't provide much information. `NgOptimizedImage` makes
it obvious that the new directive is intended to improve
performance.

PR Close #47082
2022-08-16 17:36:51 +00:00
Andrew Kushnir 1a05570fe6 test(common): add a test app for the NgImage directive (#47082)
This commit adds a simple app that uses the `NgImage` directive to simplify further investigation and tests.

PR Close #47082
2022-08-16 17:36:51 +00:00
Kristiyan Kostadinov 31429eaccc feat(core): support TypeScript 4.8 (#47038)
Adds support for TypeScript 4.8 and resolves some issues that came up as a result of the update.

Most of the issues came from some changes in TypeScript where the `decorators` and `modifiers` properties were removed from most node types, and were combined into a single `modifiers` array. Since we need to continue supporting TS 4.6 and 4.7 until v15, I ended up creating a new `ngtsc/ts_compatibility` directory to make it easier to reuse the new backwards-compatible code.

PR Close #47038
2022-08-16 16:02:47 +00:00
Andrew Scott 75df404467 feat(router): Create APIs for using Router without RouterModule (#47010)
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

PR Close #47010
2022-08-15 15:58:00 -07:00
AlirezaEbrahimkhani 5509e3512f docs: fix embedded view description issue (#46957)
createEmbeddedView method instantiates an embedded view based on this template and take your templateRef as argument and would render the passed templateRef in your ViewContainerRef.

resolves angular#46955

PR Close #46957
2022-08-11 18:07:39 +00:00
Andrew Scott 2a43beec15 fix(router): Fix route recognition behavior with some versions of rxjs (#47098)
Some versions of rxjs cause the algorithm used in the Router to not recognize Route configs correctly.
This commit updates the algorithm to be compatible in the same way as other code locations internally.

Context:
https://github.com/angular/angular/commit/1160b8194f78141b40d1d4885ec182d033ff2659

fixes #47089

Note: This does not have a test because I was unable to identify the
version of rxjs that would cause a failure here.

PR Close #47098
2022-08-10 09:25:06 -07:00
Eduardo Speroni dbed2cf079 fix(core): check if transplanted views are attached to change detector (#46974)
Prevents change detection on views transplanted in OnPush components that have been detached from change detection.

PR Close #46974
2022-08-08 11:33:29 -07:00
Kristiyan Kostadinov 7343ec7913 refactor(core): remove unused module tracking (#47066)
We used to track all modules in a top-level constant called `autoRegisterModuleById` which was used by `getRegisteredNgModuleType`. As of #45024 the constant isn't being used anymore so we can remove it.

PR Close #47066
2022-08-08 11:32:16 -07:00
Andrew Kushnir 3ef4d8a690 refactor(core): drop unused animation-related types (#47054)
This commit removes animation-related types that are no longer used after the `RootContext` cleanup.

PR Close #47054
2022-08-08 09:23:30 -07:00
Andrew Scott 0abb67af59 feat(router): allow guards and resolvers to be plain functions (#46684)
The current Router APIs require guards/resolvers to be present in the DI tree. This is because we want to treat all guards/resolvers equally and some may require dependencies. This requirement results in quite a lot of boilerplate for guards. Here are two examples:

```
const MY_GUARD = new InjectionToken<any>('my_guard');
…
providers: {provide: MY_GUARD, useValue: () => window.someGlobalState}
…
const route = {path: 'somePath', canActivate: [MY_GUARD]}
```

```
@Injectable({providedIn: 'root'})
export class MyGuardWithDependency {
  constructor(private myDep: MyDependency) {}

  canActivate() {
    return myDep.canActivate();
  }
}
…
const route = {path: 'somePath', canActivate: [MyGuardWithDependency]}
```

Notice that even when we want to write a simple guard that has no dependencies as in the first example, we still have to write either an InjectionToken or an Injectable class.

With this commit router guards and resolvers can be plain old functions.
 For example:

```
const route = {path: 'somePath', component: EditCmp, canDeactivate: [(component: EditCmp) => !component.hasUnsavedChanges]}
```

Additionally, these functions can still use Angular DI with `inject` from `@angular/core`.

```
const route = {path: 'somePath', canActivate: [() => inject(MyDependency).canActivate()]}
```

PR Close #46684
2022-08-05 10:36:46 -07:00
Andrew Kushnir c1ad37d161 refactor(core): drop unused fields from the RootContext (#46806)
The `RootContext` implementation contained a number of fields that were needed to support an experimental `renderComponent` function. The `renderComponent` function was removed, which allows us to cleanup the `RootContext` further.

The only field that remains on the `RootContext` is the list of bootstrapped components. This list is presumably mostly unused right now (it just contains the current component) and further refactoring can happen in a followup PR.

PR Close #46806
2022-08-05 09:58:06 -07:00