Commit graph

103 commits

Author SHA1 Message Date
Matthieu Riegler
6270bba056 ci: reformat files
This is after we've slightly changed a rule in #66056
2025-12-16 14:44:19 -08:00
cexbrayat
c137f1fe91 docs: ExperimentalIsolatedShadowDom mentions 2025-11-14 08:41:13 -08:00
Matthieu Riegler
21ca49cf62 refactor(core): rename ExperimentalIsolatedShadowDom to IsolatedShadowDom
This API is still experimental
2025-11-11 08:46:06 -08:00
Matthieu Riegler
29c397f883 fix(platform-browser): DomEventsPlugin should always be the last plugin to be called for supports(). (#50394)
This fixes the issues when `BrowserModule` is not the first module imported.

Fixes #37149 #37850

PR Close #50394
2025-10-15 21:12:46 +00:00
Andrew Scott
c3576506b3 refactor(core): Update tests for zoneless by default (#63668)
This updates tests and examples only to prepare for zoneless by default.

These changes were identified and made as part of #63382. Anything that
failed gets `provideZoneChangeDetection` unless the fixes were easily
and quickly determined.

It also adds the zoneless provider to the `initTestEnvironment` calls
for tests in this repo to prevent regressions before #63382 is merged.

PR Close #63668
2025-09-09 14:41:56 -07:00
Ryan Bendel
d24d5742db feat(platform-browser): Add IsolatedShadowDom encapsulation method (#62723)
IsolatedShadowDom encapsulation fixes style leakage in Shadowdom encapsulation by removing sharedstyleshost from dom-renderer IsolatedShadowdom class. Updates docs.

PR Close #62723
2025-08-06 16:48:37 +02:00
Joey Perrott
b84859073b build: migrate to use web test runner rules (#62292)
Migrate karma tests throughout the repo to use the new web test runner based rule instead

PR Close #62292
2025-06-26 17:19:10 +00:00
Joey Perrott
dfbdbbe882 refactor: use zone.js from npm instead of packages/zone.js throughout repo (#61977)
Use zone.js from npm isntead of from the repo going forward

PR Close #61977
2025-06-10 12:02:03 -07:00
Joey Perrott
4c72ce408e build: migrate platform-browser and platform-browser-dynamic package to use rules_js (#61623)
Use ts_project and ng_project to build platform-browser and platform-browser-dynamic package

PR Close #61623
2025-05-23 15:14:00 -07:00
Paul Gschwendtner
3a106a35bc build: move private testing helpers outside platform-browser/testing (#61472)
These helpers are often imported by various tests throughout the
repository, but the helpers aren't exported/exposed from the public
entry-point; even though they confusingly reside in there.

This commit fixes this, and moves the helpers into
`packages/private/testing`. This is a preparation for the `ts_project`
migration where we don't want to leverage deep imports between packages.

PR Close #61472
2025-05-20 10:00:43 +00:00
Andrew Kushnir
5c0335754a refactor(platform-browser): switching to relative imports within the platform-browser package (#60559)
This commit updates scripts within `packages/platform-browser` to relative imports as a prep work to the upcoming infra updates.

PR Close #60559
2025-03-27 18:31:52 +00:00
Kristiyan Kostadinov
5e209cb560 feat(core): remove TestBed.get (#60414)
`TestBed.get` isn't type safe and has been deprecated for several years now. These changes remove it from the public API and a follow-up change will add an automated migration to `TestBed.inject`.

BREAKING CHANGE:
* `TestBed.get` has been removed. Use `TestBed.inject` instead.

PR Close #60414
2025-03-19 15:52:26 +01:00
Alan Agius
6b09716754 fix(platform-browser): prepend baseHref to sourceMappingURL in CSS content (#59730)
Implemented functionality to prepend the baseHref to `sourceMappingURL` in CSS content. Added handling to ensure external sourcemaps are loaded relative to the baseHref. Corrected sourcemap URL behavior when accessing pages with multi-segment URLs (e.g., `/foo/bar`). Ensured that when the baseHref is set to `/`, maps are requested from the correct path (e.g., `http://localhost/comp.css.map` instead of `http://localhost/foo/bar/comp.css.map`).

Closes #59729

PR Close #59730
2025-01-29 08:44:19 -08:00
arturovt
17234213f6 refactor(platform-browser): remove Console from Hammer gestures (#59409)
Injecting the `Console` is redundant because it directly calls the global `console` object.
There is no reason to reference this class in Hammer gestures, as it is only used in development
mode. We can safely call the `console` object directly.

PR Close #59409
2025-01-09 13:09:51 -05:00
Charles Lyding
52be35118f fix(platform-browser): collect external component styles from server rendering (#59031)
SSR generated component styles used in development environments will add
external styles via link elements to the HTML. However, the runtime would
previously not collect these link elements for reuse with rendered components.
This would result in two copies of the link elements present in the DOM. In
isolation this is not problematic as it is only present in development mode.
Unfortunately, the Vite-based CSS HMR functionality used by the Angular CLI
only updates the first stylesheet it finds and leaves other instances of the
stylesheet in place. This behavior causes the styles to be left in an
inconsistent state. This could be considered a defect within Vite as it should
update all relevant styles to maintain consistency but ideally there should
not be two instances in the Angular SSR case. To avoid the Vite issue, the
runtime will now collect SSR generated external styles and reuse them.

PR Close #59031
2024-12-05 16:12:22 -08:00
Matthieu Riegler
09df589e31 refactor(core): Migrate all packages with the explicit-standalone-flag schematic. (#58160)
All components, directives and pipes will now use standalone as default.
Non-standalone decorators have now `standalone: false`.

PR Close #58160
2024-10-14 14:58:57 +00:00
Charles Lyding
2545743ad1 refactor(core): support external runtime styles via a component feature (#57922)
The shared style host now has the capability to add component styles as
link elements with external style references. This is currently unused
within the runtime but is an enabling feature for upcoming features such
as automatic component style HMR and development server deferred
stylesheet processing. Instead of inline style content that is then
added to a `style` element for each host node, a `link` element with a
stylesheet `rel` attribute and a `href` attribute can now be created.
The development server must be configured to provide the relevant
component stylesheet upon request. The Angular CLI development server
will provide this functionality once this capability is enabled.
Since the primary use of this capability is development mode and will
not be used for production code, server (SSR) style reuse is currently
not yet implemented but may be implemented in the future.

A component feature is used to provide the DOM renderer access to any
external styles that were emitted at compile time. When external styles
are present, the `getExternalStyles` function will be present on the
runtime component metadata object. The DOM render will use this function
to access and encapsulate the external style URLs as required by the
component.

PR Close #57922
2024-09-30 13:25:12 -07:00
Joey Perrott
9dbe6fc18b refactor: update license text to point to angular.dev (#57901)
Update license text to point to angular.dev instead of angular.io

PR Close #57901
2024-09-24 15:33:00 +02:00
Kristiyan Kostadinov
513a4fe05e refactor(core): replace usages of removeChild (#57203)
These changes replace most usages of `removeChild` with `remove`. The latter has the advantage of not having to look up the `parentNode` and ensure that the child being removed actually belongs to the specific parent.

The refactor should be fairly safe since all the browsers we cover support `remove`. [Something similar was done in Components](https://github.com/angular/components/pull/23592) some time ago and there haven't been any bug reports as a result.

PR Close #57203
2024-08-07 16:46:09 +00:00
Thomas Nguyen
40fb81fd0e refactor(core): Add global event delegation provider (#56247)
This replaces all addEventListener calls with a stashing function,
and installs an event listener on the document body to retrieve
the stashed function;

PR Close #56247
2024-06-27 14:24:47 +00:00
Matthieu Riegler
e5331107fd fix(platform-browser): Use the right namespace for mathML. (#55622)
Prior to this change, MathML element were created with the wrong namespace resulting in regular DOM `Element`.

This commit fixes this.

Related to #55608 (but doesn't fix it entirely).

PR Close #55622
2024-05-03 08:07:31 -07:00
Joey Perrott
b1dffa4abe refactor: migrate platform-* to prettier formatting (#55423)
Migrate formatting to prettier for platform-* from clang-format

PR Close #55423
2024-04-19 13:49:24 -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
Alan Agius
1640743b18 Revert "perf(platform-browser): disable styles of removed components instead of removing (#51808)" (#52238)
This reverts commit 65786b2b96 due to an oberved perf regression in Pantheon.

See: http://b/303667704

PR Close #52238
2023-10-18 11:34:21 +02:00
Matt Lewis
65786b2b96 fix(platform-browser): prevent duplicate stylesheets from being created (#52019)
Fixes a bug with REMOVE_STYLES_ON_COMPONENT_DESTROY when a component is destroyed and re-created, its previous stylesheets will not be re-used and instead a new stylesheet will still be created each time.

PR Close #52019
2023-10-05 14:06:56 -07:00
Alan Agius
3c0577f991 perf(platform-browser): disable styles of removed components instead of removing (#51808)
This commit changes the behaviour of `REMOVE_STYLES_ON_COMPONENT_DESTROY`.

Now, `style` nodes are disabled instead of removed from DOM. This causes the same runtime behaviour but avoids recomputations when the stylesheet is re-added when the component is re-created. https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/css/css_style_sheet.h;l=266;drc=31fb07c05718d671d96c227855bfe97af9e3fb20

NB: This changes is being done following some performance bottlenecks observed in Phanteon and their own recommendations.

Context:
http://chat/room/AAAAxKxTk40/jaP6Lj6fhmQ/jaP6Lj6fhmQ
https://crbug.com/1444522
http://b/289992821

PR Close #51808
2023-09-22 09:48:35 -07:00
Alan Agius
c340d6e044 feat(platform-browser): enable removal of styles on component destroy by default (#51571)
This change aligns the settings between G3 and P3 as `REMOVE_STYLES_ON_COMPONENT_DESTROY_DEFAULT` is already set to `true` internally.

BREAKING CHANGE: `REMOVE_STYLES_ON_COMPONENT_DESTROY` default value is now `true`. This causes CSS of components to be removed from the DOM when destroyed. You retain the previous behaviour by providing the `REMOVE_STYLES_ON_COMPONENT_DESTROY` injection token.

```ts
import {REMOVE_STYLES_ON_COMPONENT_DESTROY} from '@angular/platform-browser';
...
providers: [{
  provide: REMOVE_STYLES_ON_COMPONENT_DESTROY,
  useValue: false,
}]
```

PR Close #51571
2023-08-30 14:42:02 +00:00
Alan Agius
0380564f85 fix(platform-browser): wait until animation completion before destroying renderer (#50860)
Prior to this commit, the renderer destroy method was being called before the animation complete. This is problematic when using `REMOVE_STYLES_ON_COMPONENT_DESTROY` as it causes the styles to be removed too early.

This commit, updates this destroy logic to be call the render destroy once the animations complete.

This has been reported internally in:
- http://b/271251353#comment12
- http://b/282004950#comment5

PR Close #50860
2023-06-27 06:27:15 -07:00
Matthieu Riegler
5986ff54ec refactor(platform-browser): remove #9100 todos. (#49406)
This commit assigns the correct type instead of `any`.

PR Close #49406
2023-06-21 11:43:45 -07: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
0c441f6d64 refactor(platform-browser): Remove BrowserDetection (#50411)
Our tests should rely on the running browser.

PR Close #50411
2023-05-30 13:06:28 -07:00
Matthieu Riegler
80fe08be96 refactor(platform-browser): Throw tree-shakable errors. (#49341)
In a effort to have more tree-shakable errors, this commit transforms every `Error` into a tree-shakable `RuntimeError`

PR Close #49341
2023-05-04 12:21:20 +02:00
Alan Agius
2703fd6260 refactor: remove deprecated EventManager method addGlobalEventListener (#49645)
This commit removed the deprecated `EventManager` method  `addGlobalEventListener`.

BREAKING CHANGE: Deprecated `EventManager` method `addGlobalEventListener` has been removed as it is not used by Ivy.

PR Close #49645
2023-03-30 09:47:54 -07:00
Alan Agius
e8e36811d5 fix(platform-browser): set nonce attribute in a platform compatible way (#49624)
Setting the `nonce` attribute using the property is not supported by Domino. This change update the usage to use `setAttribute` and also add a test to verify that the `nonce` is set when it should.

PR Close #49624
2023-03-29 09:26:54 -07:00
Alan Agius
c934a8e72b fix(platform-browser): only add ng-app-id to style on server side (#49465)
This commit fixes an issue where it causes issues in G3 when we add `ng-app-id` on browser apps.

PR Close #49465
2023-03-17 17:26:27 +01:00
Alan Agius
9636910c01 refactor(platform-browser): rename ng-app style attribute to ng-app-id (#49424)
`ng-app` is an AngularJS attribute, see https://docs.angularjs.org/api/ng/directive/ngApp. Using this attribute on a non AngularJS element can cause DI issues in AngularJS when running an AngularJS and Angular application on the same page.

As such, we avoid such problems the Angular `ng-app` attribute is renamed to `ng-app-id`.

PR Close #49424
2023-03-17 10:46:03 +01:00
Alan Agius
9ab9a2a817 refactor(platform-browser): combine DomSharedStylesHost and SharedStylesHost (#49424)
The mentioned 2 classes have been combined since it is no longer required to have a separate `SharedStylesHost` for SSR. This changes also reduces the memory usage footprint as remove 1 Map that stores the CSS strings.

PR Close #49424
2023-03-17 10:46:03 +01:00
Alan Agius
9165ff2517 fix(platform-browser): reuse server generated component styles (#48253)
Prior to this change component styles generated on the server where removed prior to the client side component being rendered and attached it's own styles. In some cases this caused flickering. To mitigate this `initialNavigation: enabledBlocking'` was introduced which allowed the remove of server styles to be defer to a latter stage when the application has finished initialization.

This commit changes the need for this, by not removing the server generated component styles and reuse them for client side rendering.

PR Close #48253
2023-03-09 09:33:34 -08:00
Alan Agius
02d5e8d79d fix(platform-browser): remove styles from DOM of destroyed components (#48298)
Currently style of components using `encapsulation`, `None` or `Emulated` will not be removed from the DOM once the component get destroyed.

This change addresses this by keeping track of the number of times a component is rendered, when the component is destroyed the counter is decreased and once this reaches zero the style element is removed from the DOM.

Currently, this new behaviour is on opt-in bases, but it will be changed in the next major version.

To opt-in, set the `REMOVE_STYLES_ON_COMPONENT_DESTROY` DI token to `true`.

Example
```ts
@NgModule({
 declarations: [
   AppComponent,
 ],
 imports: [
   BrowserModule
 ],
 providers: [
   { provide: REMOVE_STYLES_ON_COMPONENT_DESTROY, useValue: true }
 ],
 bootstrap: [AppComponent]
})
export class AppModule { }
```

Closes #16670

PR Close #48298
2023-02-16 15:31:24 -08:00
dario-piotrowicz
87fe3161d4 refactor: remove unnecessary test support check utilities (#47543)
remove the following utilities used in unit tests which check for features
that are supported by all supported browsers:
 - supportsCustomElements
 - supportsWebAnimation
 - supportsRegExUnicodeFlag
 - supportsTemplateElement

also remove the following utilities which check for features that are
not supported (and aren't going to be) by any of the supported browsers:
 - supportsDeprecatedCustomCustomElementsV0
 - supportsDeprecatedShadowDomV0

PR Close #47543
2023-01-24 21:06:09 +00:00
Paul Gschwendtner
5c10efe002 build: fix legacy saucelabs test bundle generation after ESM changes (#48521)
ZoneJS is no longer loaded as an UMD, but instead is included as part
of the browser init entry-point. This means that ZoneJS is bundled and
the ESBuild logic needs to be adjusted for that.

PR Close #48521
2022-12-19 19:50:44 +00:00
Paul Gschwendtner
653e122868 refactor: update platform-browser tests to run as ESM (#48521)
`platform-browser` tests now run in ESM and with `.mjs` output, so
the build targets and tests need to be updated.

Here we change the `zone_event_unpatched` script to include the
`.init` suffix that will be picked up by `spec_bundle`.

Also some circular dependency tests are updated to refer to the
`.mjs` files.

PR Close #48521
2022-12-19 19:50:43 +00:00
Jessica Janiuk
a67a8b2fc7 refactor(platform-browser): Updates keyboard event library to support code field (#46030)
On MacOS, pressing the alt key and another key turns into symbols, and
doesn't match the intended behavior. For example, `keydown.alt.s`
reports instead as `keydown.alt.ß`. We rely on the `key` field and not
the `code` field, which properly reports the code for S in this case.

This change adds support to allow users to specify they want to look at
the `code` field instead of the `key` field within their event string.
Example: `keydown.code.alt.leftshift` would only match the LeftShift and
not the right shift based on code values. It would also allow the user
to specify `keydown.code.alt.keys` to match S instead of ß when alt /
option is pressed on MacOS and would also work on Windows.

Fixes #45992

PR Close #46030
2022-07-18 15:28:58 +00:00
Paul Gschwendtner
0934011b03 test: avoid test fixture affecting zone in all web tests (#46511)
We have a file called `test-events.js` (named in an ambiguous way
anyway) that runs for all Karma web tests and configures ZoneJS to
not patch the `scroll` event. There are two issues:

1. The patch applies to all web tests. This could cause unexpected
   issues.
2. The file is named ambiguously and also is placed at the project root,
   in a wrong spot.

Additionally, the test doesn't even fail when the file is removed. This
commit applies the Zone config locally to the closest build target and
also reworks the test to actually ensure it's testing what it describes.

PR Close #46511
2022-06-27 15:46:41 -07:00
Kristiyan Kostadinov
41223a81f2 build: update to jasmine 4.0 (#45558)
Updates us to version 4.0 of Jasmine and fixes some errors that were the result of us depending upon deprecated APIs. We need to do this both to stay up to date and because it was going to break eventually, because one of the Bazel packages was logging a deprecation warning that version 4.0 was required.

There were also some cases where the state of `ngDevMode` had started leaking out between tests.

PR Close #45558
2022-04-11 16:25:28 +00:00
Jessica Janiuk
7a37fe9f28 Revert "build: update to jasmine 4.0 (#45558)" (#45566)
This reverts commit a248df0682.

PR Close #45566
2022-04-08 19:07:29 +00:00
Kristiyan Kostadinov
a248df0682 build: update to jasmine 4.0 (#45558)
Updates us to version 4.0 of Jasmine and fixes some errors that were the result of us depending upon deprecated APIs. We need to do this both to stay up to date and because it was going to break eventually, because one of the Bazel packages was logging a deprecation warning that version 4.0 was required.

There were also some cases where the state of `ngDevMode` had started leaking out between tests.

PR Close #45558
2022-04-08 15:55:58 +00:00
Kristiyan Kostadinov
9fa6f5a552 fix(core): incorrectly inserting elements inside <template> element (#43429)
Currently whenever we insert element we do it directly on the node using `appendChild` or `insertBefore`, however this doesn't work with `<template>` elements where the `template.content` has to be used.

These changes add a few checks to call `appendChild` and `insertBefore` on the `content` of the template.

Fixes #15557.

PR Close #43429
2022-03-08 10:22:18 -08:00
arturovt
a01bcb8e7e fix(platform-browser): do not run change detection when loading Hammer (#44921)
The Hammer.JS might be loaded asynchronously if the `HAMMER_LOADER` token is provided.
Its loading causes additional change detection cycles when the script `load` event is fired
and the `import()` promise resolves. Its loading doesn't have to require Angular running `tick()`
since the Hammer instance is created outside of the Angular zone anyway.

BREAKING CHANGE:

This change may cause a breaking change in unit tests that are implicitly depending on a specific
number and sequence of change detections in order for their assertions to pass.

PR Close #44921
2022-02-02 19:50:46 +00:00
Kristiyan Kostadinov
359103274b test: clean up more entryComponents usages (#44561)
Cleans up some more tests that were using `entryComponents`.

PR Close #44561
2022-01-06 18:36:22 +00:00