101 Commits

Author SHA1 Message Date
Alan Agius
15677d0cb7 refactor: replace critters with beasties
The Critters project has been transferred to the Nuxt team, who will now manage its development and has been renamed to Beasties.

See: https://github.com/danielroe/beasties
2024-10-28 18:57:05 +01:00
Alan Agius
1fc8fdea2c refactor(@angular/ssr): remove custom Platform Server creation Logic
Replaced the custom logic for creating the platform server with the standard `platformServer` method.
2024-10-28 17:54:52 +01:00
Alan Agius
63722c309c fix(@angular/ssr): ensure wildcard RenderMode is applied when no Angular routes are defined
This fix addresses a bug where, in the absence of defined Angular routes, the RenderMode was not correctly applied based on the wildcard setting.
2024-10-28 16:43:16 +01:00
Alan Agius
43cd4584f5 fix(@schematics/angular): enable opt-in for new @angular/ssr feature
This commit updates several schematics to make the new `@angular/ssr` feature opt-in. Users can opt in by using the `--server-routing` option or by responding with `yes` to the prompt.
2024-10-25 19:51:12 +02:00
Angular Robot
0a1f171b6f build: update angular 2024-10-24 08:37:09 +02:00
Alan Agius
1cacb8de15 refactor(@angular/ssr): export tokens from the /tokens entry point
This commit relocates the DI tokens to a dedicated entry point. This change ensures that we do not depend on tree-shaking to eliminate server code from client bundles.

Closes #28670
2024-10-21 18:37:36 +02:00
Alan Agius
94dbacf447 refactor(@angular/ssr): remove useDefineForClassFields
This removes `useDefineForClassFields` to leave static field instead of using static blocks.
2024-10-21 10:47:39 +02:00
Alan Agius
44077f54e9 fix(@angular/ssr): designate package as side-effect free
Add `sideEffects` in the `package.json`
2024-10-21 09:15:13 +02:00
Angular Robot
3db884a12a build: update angular 2024-10-17 14:20:52 +00:00
Doug Parker
1ac8b41985 build: add tslib dependency to @angular/ssr target
Not sure why this wasn't needed before, but it seems to be necessary with the version bumps.
2024-10-17 09:03:51 +02:00
Angular Robot
1ab0aaa66a build: update angular 2024-10-11 08:45:27 -07:00
Alan Agius
292a4b7c2f feat(@schematics/angular): update app-shell and ssr schematics to adopt new Server Rendering API
This commit revises the app-shell and ssr schematics to incorporate the new Server Rendering API, along with the integration of server-side routes.

BREAKING CHANGE: The app-shell schematic is no longer compatible with Webpack-based builders.
2024-10-09 18:07:33 +02:00
Alan Agius
638715ecd4 refactor(@angular/ssr): Convert crypto unavailable error to a soft error
This update changes the handling of the crypto unavailable error in the Angular SSR environment. Instead of throwing a hard error, which could interrupt the application flow, the error is now treated as a soft error
2024-10-04 07:30:33 +02:00
Angular Robot
5c72d5aa58 build: update angular 2024-10-02 16:50:33 +02:00
Alan Agius
12ff37adbe perf(@angular/ssr): cache generated inline CSS for HTML
Implement LRU cache for inlined CSS in server-side rendered HTML.

This optimization significantly improves server-side rendering performance by reusing previously inlined styles and reducing the overhead of repeated CSS inlining.

Performance improvements observed:
Performance improvements observed:
* **Latency:** Reduced by ~18.1% (from 1.01s to 827.47ms)
* **Requests per Second:** Increased by ~24.1% (from 381.16 to 472.85)
* **Transfer per Second:** Increased by ~24.1% (from 0.87MB to 1.08MB)

These gains demonstrate the effectiveness of caching inlined CSS for frequently accessed pages, resulting in a faster and more efficient user experience.
2024-09-30 08:41:58 +02:00
Alan Agius
64c52521d0 fix(@angular/ssr): show error when multiple routes are set with RenderMode.AppShell
This change introduces error handling to ensure that when multiple routes are configured with `RenderMode.AppShell`, an error message is displayed. This prevents misconfiguration and enhances clarity in route management.
2024-09-26 22:50:37 +02:00
Alan Agius
50df631960 fix(@angular/ssr): improve handling of route mismatches between Angular server routes and Angular router
This commit resolves an issue where routes defined in the Angular server routing configuration did not match those in the Angular router. Previously, discrepancies between these routes went unnoticed by users. With this update, appropriate error messages are now displayed when mismatches occur, enhancing the developer experience and facilitating easier troubleshooting.
2024-09-26 22:50:37 +02:00
Jan Martin
e52ae7f6f5 perf(@angular/ssr): prevent potential stampede in entry-points cache
If multiple concurrent requests hit `getEntryPointExports`, all of
them would previously see the cache miss for entry point. With this
change, only the first request will and the others can leverage the
cache.

This can be important when instances are added to a pool under high
traffic.
2024-09-26 09:14:53 -07:00
Alan Agius
1d70e3b468 perf(@angular/ssr): cache resolved entry-points
Improve request throughput by 4.34% and reduce latency by caching resolved entry-points.
2024-09-26 17:02:33 +02:00
Angular Robot
c6dd4696bf build: update angular 2024-09-25 15:45:46 -04:00
Alan Agius
65b6e75a5d fix(@angular/ssr): export RESPONSE_INIT, REQUEST, and REQUEST_CONTEXT tokens
This commit exports that the `RESPONSE_INIT`, `REQUEST`, and `REQUEST_CONTEXT` tokens.
2024-09-25 17:08:42 +02:00
Alan Agius
92209dd2e9 feat(@angular/ssr): add createRequestHandler and createNodeRequestHandler utilities
Introduced the `createRequestHandler` and `createNodeRequestHandler` utilities to expose middleware functions from the `server.ts` entry point for use with Vite.
This provides flexibility in integrating different server frameworks, including Express, Hono, and Fastify, with Angular SSR.

Examples:

**Express**
```ts
export default createNodeRequestHandler(app);
```

**Nest.js**
```ts
const app = await NestFactory.create(AppModule);
export default createNodeRequestHandler(app);
```

**Hono**
```ts
const app = new Hono();
export default createRequestHandler(app.fetch);
```

**Fastify**
```ts
export default createNodeRequestHandler(async (req, res) => {
  await app.ready();
  app.server.emit('request', req, res);
});
```
2024-09-23 22:34:55 +02:00
Alan Agius
bbc290133f feat(@angular/build): utilize ssr.entry in Vite dev-server when available
When `ssr.entry` (server.ts) is defined, Vite will now use it in the dev-server. This allows API and routes defined in `server.ts` to be accessible during development. This feature requires the new `@angular/ssr` APIs, which are currently in developer preview.
2024-09-23 22:34:55 +02:00
Alan Agius
ad014c7d9b refactor(@angular/ssr): update HtmlTransformHandler type to include URL parameter
Modified the `HtmlTransformHandler` type to accept a context object containing a URL and HTML content. This change supports the `html:transform:pre` hook, enhancing the handler's capability to process transformations based on the request URL.
2024-09-23 22:34:55 +02:00
Alan Agius
3b00fc908d feat(@angular/build): introduce outputMode option to the application builder
The `outputMode` option accepts two values:
- **`static`:**  Generates a static output (HTML, CSS, JavaScript) suitable for deployment on static hosting services or CDNs. This mode supports both client-side rendering (CSR) and static site generation (SSG).
- **`server`:** Generates a server bundle in addition to static assets, enabling server-side rendering (SSR) and hybrid rendering strategies. This output is intended for deployment on a Node.js server or serverless environment.

- **Replaces `appShell` and `prerender`:**  The `outputMode` option simplifies the CLI by replacing the `appShell` and `prerender` options when server-side routing is configured.
- **Controls Server API Usage:**  `outputMode` determines whether the new server API is utilized. In `server` mode, `server.ts` is bundled as a separate entry point, preventing direct references to `main.server.ts` and excluding it from localization.

Closes #27356, closes #27403, closes #25726, closes #25718 and closes #27196
2024-09-19 21:29:34 +02:00
Angular Robot
8c9bf694da build: update angular 2024-09-18 11:34:04 -07:00
Alan Agius
ea4b99b36f refactor(@angular/ssr): add option to exclude fallback SSG routes from extraction
This option allows validation during the build process to ensure that, when the output mode is set to static, no routes requiring server-side rendering are included.
2024-09-17 18:14:56 +02:00
Alan Agius
f346ee8a88 feat(@angular/ssr): add isMainModule function
Adds a new function `isMainModule` that checks if the current module is the main entry point of the application.

This is useful to ensure that server listener handlers are only registered when the module is executed directly and not when it's imported as a dependency such as the dev-server. This prevents potential issues with multiple listeners being registered unintentionally.
2024-09-17 16:41:00 +02:00
Alan Agius
2640bf7a68 fix(@angular/ssr): correct route extraction and error handling
This commit introduces the following changes:
- Disallows paths starting with a slash to match Angular router behavior.
- Errors are now stored and displayed at a later stage, improving UX by avoiding unnecessary stack traces that are not useful in this context.
2024-09-16 21:22:10 +02:00
Alan Agius
d66aaa3ca4 feat(@angular/ssr): add server routing configuration API
This commit introduces a new server routing configuration API, as discussed in RFC https://github.com/angular/angular/discussions/56785. The new API provides several enhancements:

```ts
const serverRoutes: ServerRoute[] = [
  {
    path: '/error',
    renderMode: RenderMode.Server,
    status: 404,
    headers: {
      'Cache-Control': 'no-cache'
    }
  }
];
```

```ts
const serverRoutes: ServerRoute[] = [
  {
    path: '/product/:id',
    renderMode: RenderMode.Prerender,
    async getPrerenderPaths() {
      const dataService = inject(ProductService);
      const ids = await dataService.getIds(); // Assuming this returns ['1', '2', '3']
      return ids.map(id => ({ id })); // Generates paths like: [{ id: '1' }, { id: '2' }, { id: '3' }]
    }
  }
];
```

```ts
const serverRoutes: ServerRoute[] = [
  {
    path: '/product/:id',
    renderMode: RenderMode.Prerender,
    fallback: PrerenderFallback.Server, // Can be Server, Client, or None
    async getPrerenderPaths() {
    }
  }
];
```

```ts
const serverRoutes: ServerRoute[] = [
  {
    path: '/product/:id',
    renderMode: RenderMode.Server,
  },
  {
    path: '/error',
    renderMode: RenderMode.Client,
  },
  {
    path: '/**',
    renderMode: RenderMode.Prerender,
  },
];
```

These additions aim to provide greater flexibility and control over server-side rendering configurations and prerendering behaviors.
2024-09-12 19:59:05 +02:00
Alan Agius
85df4011ba fix(@angular/ssr): resolve bootstrap is not a function error
In cases where the application is not zoneless and async/await is downleveled, an issue occurred where `await` was not being downleveled correctly. This led to the `bootstrap is not a function` error.

See: https://github.com/angular/angular/actions/runs/10817795242/job/30014914340?pr=57776
2024-09-12 17:09:19 +02:00
JoostK
056d17aa09 refactor(@angular/ssr): use ReadonlyMap instead of Readonly mapped type
The `Readonly` mapped type only introduces the `readonly` modifier for each property,
but `Map` has mutating methods like `clear`, `delete` and `set` that would still
remain usable. This commit switches those usages over to the `ReadonlyMap` type which
doesn't have any of the mutating methods.
2024-09-12 15:05:55 +02:00
Angular Robot
52f4aa1df2 build: update angular 2024-09-12 12:07:32 +02:00
Alan Agius
743188ba62 refactor: Add lines-around-comment rule
I often struggle with spacing around block comments, so I've decided to add the `lines-around-comment` lint rule to help manage this.

For more details, see the https://eslint.style/rules/js/lines-around-comment
2024-09-11 12:10:54 +02:00
Alan Agius
e9c9e4995e fix(@angular/ssr): resolve circular dependency issue from main.server.js reference in manifest
The issue was addressed by changing the top-level import to a dynamic import.

Closes #28358
2024-09-06 16:11:34 +02:00
Alan Agius
7d9ce246a3 refactor(@angular/ssr): remove singleton helpers
This commit removes the singleton helpers and instead exposes the
classes directly.
2024-09-06 07:13:04 +02:00
Alan Agius
41fb2ed860 feat(@angular/ssr): Add getHeaders Method to AngularAppEngine and AngularNodeAppEngine for handling pages static headers
This commit introduces a new `getHeaders` method to the `AngularAppEngine` and `AngularNodeAppEngine` classes, designed to facilitate the retrieval of HTTP headers based on URL pathnames for statically generated (SSG) pages.

```typescript
const angularAppEngine = new AngularNodeAppEngine();

app.use(express.static('dist/browser', {
  setHeaders: (res, path) => {
    // Retrieve headers for the current request
    const headers = angularAppEngine.getHeaders(res.req);

    // Apply the retrieved headers to the response
    for (const { key, value } of headers) {
      res.setHeader(key, value);
    }
  }
}));
```

In this example, the `getHeaders` method is used within an Express application to dynamically set HTTP headers for static files. This ensures that appropriate headers are applied based on the specific request, enhancing the handling of SSG pages.
2024-09-06 07:13:04 +02:00
Alan Agius
576ff604cd feat(@angular/ssr): introduce AngularNodeAppEngine API for Node.js integration
Expose a variant of `AngularAppEngine` tailored for Node.js. These additions streamline the process by minimizing boilerplate code and eliminate the need for users to call `createWebRequestFromNodeRequest` before invoking the render method.
2024-09-06 07:13:04 +02:00
Alan Agius
8419f7feab refactor(@angular/ssr): move ɵresetCompiledComponents to destroyAngularServerApp
This change is necessary to prevent NgModule-based rendering from failing with JIT in development mode.
2024-09-04 21:15:19 +02:00
Angular Robot
f5b070d42d build: update angular 2024-09-04 13:36:07 -04:00
Alan Agius
63f2389b78 build: lock file maintenance 2024-09-04 13:31:16 +02:00
Alan Agius
76de1bfff1 test: update ssr UT to zoneless
This commit updates the UT tests to zoneless.
2024-08-30 09:49:40 -07:00
Alan Agius
455b5700c2 feat(@angular/ssr): expose writeResponseToNodeResponse and createWebRequestFromNodeRequest in public API
These additions enhance server-side rendering capabilities by providing more flexibility in handling web requests and responses within Node.js environments.
2024-08-30 09:49:24 -07:00
Angular Robot
5226c535bd build: update angular 2024-08-29 07:28:28 +02:00
Alan Agius
9fa75a852b refactor(@angular/ssr): Add Utility Function for route extraction and tree creation
This commit introduces a new utility function designed to extract routes and creating a corresponding route tree.
2024-08-29 07:08:13 +02:00
Alan Agius
f2edaaf624 refactor(@angular/ssr): remove circular dependency between app.ts and manifest.ts
Updated `EntryPointExports` interface to avoid a circular dependency between `app.ts` and `manifest.ts`.
2024-08-28 07:51:27 +02:00
Alan Agius
30c25bf688 feat(@angular/ssr): export AngularAppEngine as public API
Added `AngularAppEngine` to the public API of `@angular/ssr`, allowing users to access it directly for enhanced server-side rendering functionality.
2024-08-28 07:51:27 +02:00
Alan Agius
70d3eb90d6 build: remove express from externals list
The `@angular/ssr` package has no direct dependency on `express`, hence setting this as external is not required.
2024-08-28 07:05:23 +02:00
Alan Agius
501c9a7fb7 build: prevent rollup from bundling @angular/ssr in @angular/ssr/node
This update addresses an issue on Windows where rollup attempts to bundle the `@angular/ssr`as part of the `@angular/ssr/node` FESM. Additionally, `tslib` is removed from externals as it is already configured internally within `ng_package`. See: 76b9e2b836/packages/bazel/src/ng_package/ng_package.bzl (L106)
2024-08-28 07:05:23 +02:00
Alan Agius
c7fc9190f5 refactor(@angular/ssr): relocate Node.js Request and Response Helpers to /node entry point
This refactor moves the Node.js-specific request and response helper functions to the /node entry point. This change improves modularity by separating Node.js-specific logic from the main SSR codebase.
2024-08-27 19:48:39 +02:00