diff --git a/packages/angular/ssr/src/routes/ng-routes.ts b/packages/angular/ssr/src/routes/ng-routes.ts index 7c2db5275023..c80755a0a446 100644 --- a/packages/angular/ssr/src/routes/ng-routes.ts +++ b/packages/angular/ssr/src/routes/ng-routes.ts @@ -634,7 +634,7 @@ export async function getRoutesFromAngularRouterConfig( const moduleRef = await platformRef.bootstrapModule(bootstrap); applicationRef = moduleRef.injector.get(ApplicationRef); } else { - applicationRef = await bootstrap(); + applicationRef = await bootstrap(platformRef.injector); } const injector = applicationRef.injector; diff --git a/packages/angular/ssr/src/routes/route-config.ts b/packages/angular/ssr/src/routes/route-config.ts index bcd791a7c5c4..ea05faa1f04d 100644 --- a/packages/angular/ssr/src/routes/route-config.ts +++ b/packages/angular/ssr/src/routes/route-config.ts @@ -353,16 +353,16 @@ export function withAppShell( * * @example * Basic example of how you can enable server-side rendering in your application - * when using the `bootstrapApplication` function: + * when using the `bootstrapServerApplication` function: * * ```ts - * import { bootstrapApplication } from '@angular/platform-browser'; + * import { bootstrapServerApplication } from '@angular/platform-server'; * import { provideServerRendering, withRoutes, withAppShell } from '@angular/ssr'; * import { AppComponent } from './app/app.component'; * import { SERVER_ROUTES } from './app/app.server.routes'; * import { AppShellComponent } from './app/app-shell.component'; * - * bootstrapApplication(AppComponent, { + * export default bootstrapServerApplication(AppComponent, { * providers: [ * provideServerRendering( * withRoutes(SERVER_ROUTES), diff --git a/packages/angular/ssr/src/utils/ng.ts b/packages/angular/ssr/src/utils/ng.ts index b92aa51d1d84..2d36830f6b78 100644 --- a/packages/angular/ssr/src/utils/ng.ts +++ b/packages/angular/ssr/src/utils/ng.ts @@ -17,6 +17,7 @@ import { import { INITIAL_CONFIG, ɵSERVER_CONTEXT as SERVER_CONTEXT, + bootstrapServerApplication, platformServer, ɵrenderInternal as renderInternal, } from '@angular/platform-server'; @@ -31,7 +32,7 @@ import { joinUrlParts, stripIndexHtmlFromURL } from './url'; * - A reference to an Angular component or module (`Type`) that serves as the root of the application. * - A function that returns a `Promise`, which resolves with the root application reference. */ -export type AngularBootstrap = Type | (() => Promise); +export type AngularBootstrap = Type | ReturnType; /** * Renders an Angular application or module to an HTML string. @@ -90,7 +91,7 @@ export async function renderAngular( const moduleRef = await platformRef.bootstrapModule(bootstrap); applicationRef = moduleRef.injector.get(ApplicationRef); } else { - applicationRef = await bootstrap(); + applicationRef = await bootstrap(platformRef.injector); } // Block until application is stable. diff --git a/packages/angular/ssr/test/BUILD.bazel b/packages/angular/ssr/test/BUILD.bazel index 98ee6bbc4d4d..fb2756fe2c0a 100644 --- a/packages/angular/ssr/test/BUILD.bazel +++ b/packages/angular/ssr/test/BUILD.bazel @@ -12,7 +12,7 @@ ts_project( "//:node_modules/@angular/common", "//:node_modules/@angular/compiler", "//:node_modules/@angular/core", - "//:node_modules/@angular/platform-browser", + "//:node_modules/@angular/platform-server", "//:node_modules/@angular/router", "//:node_modules/@types/node", "//packages/angular/ssr", diff --git a/packages/angular/ssr/test/testing-utils.ts b/packages/angular/ssr/test/testing-utils.ts index 9f1cd076e33e..64de0f768669 100644 --- a/packages/angular/ssr/test/testing-utils.ts +++ b/packages/angular/ssr/test/testing-utils.ts @@ -13,7 +13,7 @@ import { Type, provideZonelessChangeDetection, } from '@angular/core'; -import { bootstrapApplication } from '@angular/platform-browser'; +import { bootstrapServerApplication } from '@angular/platform-server'; import { RouterOutlet, Routes, provideRouter } from '@angular/router'; import { destroyAngularServerApp } from '../src/app'; import { ServerAsset, setAngularAppManifest } from '../src/manifest'; @@ -90,8 +90,8 @@ export function setAngularAppTestingManifest( `, }, }, - bootstrap: async () => () => { - return bootstrapApplication(rootComponent, { + bootstrap: async () => { + return bootstrapServerApplication(rootComponent, { providers: [ provideZonelessChangeDetection(), provideRouter(routes), diff --git a/packages/schematics/angular/server/files/application-builder/standalone-src/main.server.ts.template b/packages/schematics/angular/server/files/application-builder/standalone-src/main.server.ts.template index bc0b6ba59758..253dda6b4014 100644 --- a/packages/schematics/angular/server/files/application-builder/standalone-src/main.server.ts.template +++ b/packages/schematics/angular/server/files/application-builder/standalone-src/main.server.ts.template @@ -1,7 +1,5 @@ -import { bootstrapApplication } from '@angular/platform-browser'; +import { bootstrapServerApplication } from '@angular/platform-server'; import { <%= appComponentName %> } from '<%= appComponentPath %>'; import { config } from './app/app.config.server'; -const bootstrap = () => bootstrapApplication(<%= appComponentName %>, config); - -export default bootstrap; +export default bootstrapServerApplication(<%= appComponentName %>, config); diff --git a/packages/schematics/angular/server/files/server-builder/standalone-src/main.server.ts.template b/packages/schematics/angular/server/files/server-builder/standalone-src/main.server.ts.template index bc0b6ba59758..253dda6b4014 100644 --- a/packages/schematics/angular/server/files/server-builder/standalone-src/main.server.ts.template +++ b/packages/schematics/angular/server/files/server-builder/standalone-src/main.server.ts.template @@ -1,7 +1,5 @@ -import { bootstrapApplication } from '@angular/platform-browser'; +import { bootstrapServerApplication } from '@angular/platform-server'; import { <%= appComponentName %> } from '<%= appComponentPath %>'; import { config } from './app/app.config.server'; -const bootstrap = () => bootstrapApplication(<%= appComponentName %>, config); - -export default bootstrap; +export default bootstrapServerApplication(<%= appComponentName %>, config); diff --git a/packages/schematics/angular/utility/standalone/util.ts b/packages/schematics/angular/utility/standalone/util.ts index 4c64e68ad559..bdcace4f0d51 100644 --- a/packages/schematics/angular/utility/standalone/util.ts +++ b/packages/schematics/angular/utility/standalone/util.ts @@ -55,14 +55,12 @@ export function getSourceFile(tree: Tree, path: string): ts.SourceFile { return source; } -/** Finds the call to `bootstrapApplication` within a file. */ +/** Finds the call to `bootstrapApplication` or `bootstrapServerApplication` within a file. */ export function findBootstrapApplicationCall(tree: Tree, mainFilePath: string): ts.CallExpression { const sourceFile = getSourceFile(tree, mainFilePath); - const localName = findImportLocalName( - sourceFile, - 'bootstrapApplication', - '@angular/platform-browser', - ); + const localName = + findImportLocalName(sourceFile, 'bootstrapApplication', '@angular/platform-browser') ?? + findImportLocalName(sourceFile, 'bootstrapServerApplication', '@angular/platform-server'); if (localName) { let result: ts.CallExpression | null = null; @@ -86,7 +84,9 @@ export function findBootstrapApplicationCall(tree: Tree, mainFilePath: string): } } - throw new SchematicsException(`Could not find bootstrapApplication call in ${mainFilePath}`); + throw new SchematicsException( + `Could not find bootstrapApplication or bootstrapServerApplication call in ${mainFilePath}`, + ); } /**