angular/goldens/public-api/platform-server/index.api.md
Alan Agius 28926ba92c feat(core): introduce BootstrapContext for improved server bootstrapping (#63562)
This commit introduces a number of changes to the server bootstrapping process to make it more robust and less error-prone, especially for concurrent requests.

Previously, the server rendering process relied on a module-level global platform injector. This could lead to issues in server-side rendering environments where multiple requests are processed concurrently, as they could inadvertently share or overwrite the global injector state.

The new approach introduces a `BootstrapContext` that is passed to the `bootstrapApplication` function. This context provides a platform reference that is scoped to the individual request, ensuring that each server-side render has an isolated platform injector. This prevents state leakage between concurrent requests and makes the overall process more reliable.

BREAKING CHANGE:
The server-side bootstrapping process has been changed to eliminate the reliance on a global platform injector.

Before:
```ts
const bootstrap = () => bootstrapApplication(AppComponent, config);
```

After:
```ts
const bootstrap = (context: BootstrapContext) =>
  bootstrapApplication(AppComponent, config, context);
```

A schematic is provided to automatically update `main.server.ts` files to pass the `BootstrapContext` to the `bootstrapApplication` call.

In addition, `getPlatform()` and `destroyPlatform()` will now return `null` and be a no-op respectively when running in a server environment.

PR Close #63562
2025-09-09 10:57:09 -07:00

2.2 KiB

API Report File for "@angular/platform-server"

Do not edit this file. It is a report generated by API Extractor.


import { ApplicationRef } from '@angular/core';
import { BootstrapContext } from '@angular/platform-browser';
import { EnvironmentProviders } from '@angular/core';
import * as i0 from '@angular/core';
import * as i1 from '@angular/platform-browser';
import { InjectionToken } from '@angular/core';
import { PlatformRef } from '@angular/core';
import { Provider } from '@angular/core';
import { StaticProvider } from '@angular/core';
import { Type } from '@angular/core';
import { Version } from '@angular/core';

// @public
export const BEFORE_APP_SERIALIZED: InjectionToken<readonly (() => void | Promise<void>)[]>;

// @public
export const INITIAL_CONFIG: InjectionToken<PlatformConfig>;

// @public
export interface PlatformConfig {
    document?: string;
    url?: string;
}

// @public
export function platformServer(extraProviders?: StaticProvider[] | undefined): PlatformRef;

// @public
export class PlatformState {
    constructor(_doc: any);
    getDocument(): any;
    renderToString(): string;
    // (undocumented)
    static ɵfac: i0.ɵɵFactoryDeclaration<PlatformState, never>;
    // (undocumented)
    static ɵprov: i0.ɵɵInjectableDeclaration<PlatformState>;
}

// @public
export function provideServerRendering(): EnvironmentProviders;

// @public
export function renderApplication(bootstrap: (context: BootstrapContext) => Promise<ApplicationRef>, options: {
    document?: string | Document;
    url?: string;
    platformProviders?: Provider[];
}): Promise<string>;

// @public
export function renderModule<T>(moduleType: Type<T>, options: {
    document?: string | Document;
    url?: string;
    extraProviders?: StaticProvider[];
}): Promise<string>;

// @public
export class ServerModule {
    // (undocumented)
    static ɵfac: i0.ɵɵFactoryDeclaration<ServerModule, never>;
    // (undocumented)
    static ɵinj: i0.ɵɵInjectorDeclaration<ServerModule>;
    // (undocumented)
    static ɵmod: i0.ɵɵNgModuleDeclaration<ServerModule, never, never, [typeof i1.BrowserModule]>;
}

// @public (undocumented)
export const VERSION: Version;

// (No @packageDocumentation comment for this package)