189 Commits

Author SHA1 Message Date
Alan Agius
d63e31c326 refactor(@angular/ssr): remove deprecated provideServerRoutesConfig dev-preview API
`provideServerRouting` should be used instead.
2025-03-03 15:59:52 +01:00
Angular Robot
44b06f4486 build: update angular 2025-02-27 08:58:21 -08:00
Charles Lyding
5e90c1b4ec fix(@angular/cli): remove Node.js v18 support
Node.js v18 will reach its End-of-Life on 2025-04-30 and as a result will
not be supported with the upcoming Angular v20.
Node.js Release Schedule: https://github.com/nodejs/release#release-schedule

BREAKING CHANGE: Node.js v18 is no longer supported with Angular.

Before updating a project to Angular v20, the Node.js version must be
at least 20.11.1. For the full list of supported Node.js versions,
see https://angular.dev/reference/versions.
2025-02-20 13:37:53 -05:00
Angular Robot
8f73dad78d build: update angular 2025-02-19 16:28:28 -05:00
Joey Perrott
ca1e86b684 build: disable failing strict_deps targets
Disable all failing strict_deps targets with TODOs to fix them moving forward.
2025-02-19 15:22:58 -05:00
Joey Perrott
c9273f8b85 build: add @types/node to assorted locations where node types are being relied on and currently obtained transitively. 2025-02-19 12:53:55 -05:00
Alan Agius
833dc986db fix(@angular/ssr): properly handle baseHref with protocol
Enhances handling of `baseHref` when it includes a full URL with a protocol.

Closes #29590
2025-02-10 15:33:31 -08:00
Angular Robot
021985fcb1 build: update angular 2025-02-07 11:04:05 -08:00
Alan Agius
25dbe7cfc1 refactor(@angular/ssr): simplify preload append logic in metadata
Replace `filter` and `map` with a `for...of` loop to improve readability in the preload append logic within metadata.
2025-02-03 15:20:18 -08:00
Alan Agius
6448f80bfb fix(@angular/ssr): prioritize the first matching route over subsequent ones
Ensures that the SSR router gives precedence to the first matching route, addressing the issue where later conflicting routes.

This change prevents the incorrect prioritization of routes and ensures the intended route is matched first, aligning routing behavior.

Closes: #29539
2025-02-03 12:23:19 -08:00
Alan Agius
9726cd084b feat(@angular/ssr): Add support for route matchers with fine-grained render mode control
This commit adds support for custom route matchers in Angular SSR, allowing fine-grained control over the `renderMode` (Server, Client) for individual routes, including those defined with matchers.

Routes with custom matchers are **not** supported during prerendering and must explicitly define a `renderMode` of either server or client.

The following configuration demonstrates how to use glob patterns (including recursive `**`) to define server-side rendering (SSR) or client-side rendering (CSR) for specific parts of the 'product' route and its child routes.

```typescript
// app.routes.ts
import { Routes } from '@angular/router';

export const routes: Routes = [
  {
    path: '',
    component: DummyComponent,
  },
  {
    path: 'product',
    component: DummyComponent,
    children: [
      {
        path: '',
        component: DummyComponent,
      },
      {
        path: 'list',
        component: DummyComponent,
      },
      {
        matcher: () => null, // Example custom matcher (always returns null)
        component: DummyComponent,
      },
    ],
  },
];
```

```typescript
// app.routes.server.ts
import { RenderMode, ServerRoute } from '@angular/ssr';

export const serverRoutes: ServerRoute[] = [
  { path: '**', renderMode: RenderMode.Client },
  { path: 'product', renderMode: RenderMode.Prerender },
  { path: 'product/list', renderMode: RenderMode.Prerender },
  { path: 'product/**/overview/details', renderMode: RenderMode.Server },
];
```

Closes #29284
2025-01-31 13:09:34 +01:00
Paul Gschwendtner
c0d20e05c3 build: switch beasties bundling to rules_js
Switches the beasties bundling to `rules_js`, using rollup directly from
the node modules installation.

Notably we are facing a small issue that doesn't cause any issues right
now, because rollup tries to dereference symlinks by default given
a bug: https://github.com/aspect-build/rules_js/issues/1827.

This means we can't rely on the jailed resolution, but in practice it
shouldn't cause an issue at this point.
2025-01-30 11:16:46 +01:00
Paul Gschwendtner
2236bc185a build: remove legacy defaults.bzl macro file
This file is currently no longer necessary after migrating all consumers
to their `rules_js` variants, so we can delete the file.

In follow-ups we will consider renaming `defaults2.bzl` back to this
file, or have a better name altogether.
2025-01-30 11:16:46 +01:00
Paul Gschwendtner
83b9d33946 build: migrate remaining usage of pkg_npm to rules_js
This is necessary so that we can delete the `pkg_npm` macro and fully
leverage the `rules_js` variant.
2025-01-30 11:16:46 +01:00
Angular Robot
448e920e34 build: update angular 2025-01-30 08:00:17 +01:00
Alan Agius
46581db16b fix(@angular/ssr): redirect to locale pathname instead of full URL
When redirecting to the preferred locale, the previous implementation used the full URL for the 302 redirect to i18n subpaths based on the user's preferred locale. This update ensures that the redirect now uses the locale-specific pathname instead of the full URL.

Closes #29514
2025-01-29 16:18:16 +01:00
Paul Gschwendtner
539336e01a build: migrate remaining @angular/ssr tests to rules_js
Migrates the remaining `@angular/ssr` tests to `rules_js`.
2025-01-29 10:16:32 +01:00
Alan Agius
ec05c814ee fix(@angular/ssr): rename provideServerRoutesConfig to provideServerRouting
This commit renames `provideServerRoutesConfig` to `provideServerRouting` and updates the second parameter to use the `ServerRoutes` features.

This change improves alignment with the framework's API conventions and the way features are integrated.

### Example Usage:
Before:
```typescript
provideServerRoutesConfig(serverRoutes, { appShellRoute: 'shell' })
```

After:
```typescript
provideServerRouting(serverRoutes, withAppShell(AppShellComponent))
```
2025-01-28 09:25:42 +01:00
alexfriesen
57ae111e28 refactor(@angular/ssr): drain node stream 2025-01-28 09:07:25 +01:00
Alan Agius
4df97d1923 fix(@angular/ssr): enhance dynamic route matching for better performance and accuracy
Updated route matching logic to prioritize closest matches, improving the accuracy of dynamic route resolution. Also we optimized performance by eliminating unnecessary recursive checks, reducing overhead during route matching.

Closes #29452
2025-01-24 11:44:16 +01:00
Paul Gschwendtner
af25379a3b build: migrate @angular/ssr tests to rules_js
Migrates the SSR tesst to run natively via `rules_js`. Notably, we still
need the bundling in between as the tests and SSR plain code is not
valid ESM technically; due to lack of extensions.

We'll need to revisit this in the future, or at the very least come up
with a `rules_js`-variant of the `spec_bundle`; but for this is
sufficient and unblocks other packages.
2025-01-23 15:27:55 +01:00
Alan Agius
b9151e25ff refactor(@angular/ssr): remove unused segment property from metadata
The `segment` property within the route-tree metadata is redundant and serves no functional purpose. Therefore, it has been removed.
2025-01-22 16:57:47 -05:00
Charles Lyding
5ee647049a build: update Angular versions for 19.2 prereleases 2025-01-22 16:55:46 -05:00
Alan Agius
b0c2d1900f refactor(@angular/ssr): update getPathSegments to use stripTrailingSlash instead of filter(Boolean)
This change modifies the `getPathSegments` function to use `stripTrailingSlash`, providing a more consistent and reliable way to handle trailing slashes in paths. This update also resolves issues causing CI failures.
2025-01-22 10:54:13 +01:00
Alan Agius
3546c6d12d fix(@angular/ssr): properly manage catch-all routes with base href
This fix ensures that catch-all routes (e.g., wildcard routes like `**`) are handled correctly when a base href is configured in an Angular SSR application.

Closes #29397
2025-01-22 09:06:29 +01:00
Alan Agius
4a1833d842 fix(@angular/ssr): unblock route extraction with withEnabledBlockingInitialNavigation
This fix ensures that route extraction is not blocked when `withEnabledBlockingInitialNavigation` is used.

Closes #29400
2025-01-20 18:51:23 +01:00
Angular Robot
a0efac87ce build: update angular 2025-01-20 12:35:40 -05:00
Alan Agius
f3a923301e fix(@angular/ssr): prevent route matcher error when SSR routing is not used
Although route matchers are not supported with the SSR Routing API, they still function with the legacy `CommonEngine`. Therefore, no error should be issued in this case.

Closes #29420
2025-01-20 16:17:29 +01:00
Angular Robot
d048368cfd build: update angular 2025-01-17 11:03:53 -08:00
Alan Agius
31cbf5f9ad build: replace hardcoded Angular and ng-packagr peer dependencies with Bazel stamping
Refactor the build configuration to use Bazel stamping for Angular and ng-packagr dependencies, eliminating the need for hardcoded peer dependencies.
2025-01-16 19:06:30 +01:00
Paul Gschwendtner
4fee94a96c build: rename //:root_modules to //:node_modules.
This is necessary as `rules_js` requires this "common name" when dealing
with Yarn workspaces, linking first party dependencies automatically.

In the future, we may be able to send a PR to `rules_js` to support a
custom name somehow.
2025-01-15 19:20:40 +01:00
Alan Agius
8ba6b28b43 docs: enhance descriptions for schematics options
Refined and clarified the descriptions for various schematics options to improve their readability and accuracy. These changes aim to make the documentation more user-friendly and accessible for developers.

Closes #25571
2025-01-15 17:31:06 +01:00
Angular Robot
ecadcae831 build: update bazel 2025-01-10 17:34:01 +01:00
Angular Robot
6fc31fd348 build: update angular 2025-01-08 11:34:47 -08:00
Paul Gschwendtner
8c94d22469 build: migrate @angular/ssr to ts_project
Migrates `@angular/ssr` to `ts_project`. Possible after
various upstream fixes for `ng_package` and interop changes.
2025-01-08 07:42:19 -08:00
Alan Agius
6edb908837 fix(@angular/ssr): throw error when using route matchers
Route matchers are not currently supported in Angular SSR. This commit ensures an error is issued when a route matcher is detected.
2025-01-08 15:53:35 +01:00
Matthieu Riegler
ccf3650665 refactor(@angular/ssr): clean up comment.
The double JSDoc start sequence was visible in the docs (https://angular.dev/api/ssr/provideServerRoutesConfig). This commit fixes it.
2025-01-06 11:54:19 +01:00
Alan Agius
3feecddbba fix(@angular/ssr): disable component boostrapping when running route extraction
This commit fixes an issue where the components where still being
boostrapped when using `provideAppInitializer`

Closes #29131
2024-12-19 17:39:23 +01:00
Angular Robot
07a8bce68f build: update angular 2024-12-19 07:38:40 +01:00
Alan Agius
ad1d7d76fc fix(@angular/ssr): ensure correct Location header for redirects behind a proxy
Previously, when the application was served behind a proxy, server-side redirects generated an incorrect Location header, causing navigation issues. This fix updates `createRequestUrl` to use the port from the Host header, ensuring accurate in proxy environments. Additionally, the Location header now only contains the pathname, improving compliance with redirect handling in such setups.

Closes #29151
2024-12-17 12:33:49 -08:00
Alan Agius
f7c0a83c5d refactor(@angular/ssr): mark LINK_LOAD_SCRIPT_CONTENT as @PURE
This const is pure.
2024-12-17 11:27:54 -08:00
Alan Agius
78c41f67ec refactor(@angular/ssr): add timeout to prevent 'adev' hanging during route extraction
A timeout was added during route extraction to resolve an issue where 'adev' would hang in production builds.
The root cause is currently unclear, but this change ensures the build completes successfully.
2024-12-16 14:58:48 +01:00
Angular Robot
8d35b9bd38 build: update angular 2024-12-13 11:30:46 -08:00
Alan Agius
10a5b8b6b8 fix(@angular/ssr): disable component bootstrapping during route extraction
This commit disables component bootstrapping during route extraction to prevent invoking the AppComponent and its lifecycle hooks.

Closes #29085
2024-12-11 18:16:46 +01:00
Alan Agius
6eed4609f4 refactor(@angular/ssr): move ignored messages as a global
Refactored the ignored log messages into a global constant.
2024-12-11 14:52:26 +01:00
Alan Agius
41ece633b3 feat(@angular/ssr): redirect to preferred locale when accessing root route without a specified locale
When users access the root route `/` without providing a locale, the application now redirects them to their preferred locale based on the `Accept-Language` header.

This enhancement leverages the user's browser preferences to determine the most appropriate locale, providing a seamless and personalized experience without requiring manual locale selection.
2024-12-10 13:11:06 +01:00
Alan Agius
8d7a51dfc9 feat(@angular/ssr): add modulepreload for lazy-loaded routes
Enhance performance when using SSR by adding `modulepreload` links to lazy-loaded routes. This ensures that the required modules are preloaded in the background, improving the user experience and reducing the time to interactive.

Closes #26484
2024-12-10 12:39:47 +01:00
Alan Agius
0a570c0c2e feat(@angular/build): add support for customizing URL segments with i18n
Previously, the `baseHref` option under each locale allowed for generating a unique base href for specific locales. However, users were still required to handle file organization manually, and `baseHref` appeared to be primarily designed for this purpose.

This commit introduces a new `subPath` option, which simplifies the i18n process, particularly in static site generation (SSG) and server-side rendering (SSR). When the `subPath` option is used, the `baseHref` is ignored. Instead, the `subPath` serves as both the base href and the name of the directory containing the localized version of the app.

Below is an example configuration showcasing the use of `subPath`:

```json
"i18n": {
  "sourceLocale": {
    "code": "en-US",
    "subPath": ""
  },
  "locales": {
    "fr-BE": {
      "subPath": "fr",
      "translation": "src/i18n/messages.fr-BE.xlf"
    },
    "de-BE": {
      "subPath": "de",
      "translation": "src/i18n/messages.de-BE.xlf"
    }
  }
}
```

The following tree structure demonstrates how the `subPath` organizes localized build output:
```
dist/
├── app/
│   └── browser/  # Default locale, accessible at `/`
│       ├── fr/  # Locale for `fr-BE`, accessible at `/fr`
│       └── de/  # Locale for `de-BE`, accessible at `/de`
```

DEPRECATED: The `baseHref` option under `i18n.locales` and `i18n.sourceLocale` in `angular.json` is deprecated in favor of `subPath`.

The `subPath` defines the URL segment for the locale, serving as both the HTML base HREF and the directory name for output. By default, if not specified, `subPath` will use the locale code.

Closes #16997 and closes #28967
2024-12-07 19:00:32 +01:00
Alan Agius
d7214e9610 fix(@angular/ssr): include Content-Language header when locale is set
The server now includes the `Content-Language` HTTP header in responses whenever a locale is explicitly set.
2024-12-07 18:46:14 +01:00
Alan Agius
6647247ec0 test(@angular/ssr): refine spec setup to resolve component ID collision warnings
This update addresses excessive log noise caused by the following warning:
`NG0912: Component ID generation collision detected. Components 'AppComponent' and 'AppComponent' with selector 'app-root' generated the same component ID. To fix this, you can change the selector of one of those components or add an extra host attribute to force a different ID. Find more at https://angular.dev/errors/NG0912`.
2024-12-06 08:24:11 +01:00