@angular/platform-server 18.0.0-next.4 → 18.0.0-next.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,12 @@
1
1
  /**
2
- * @license Angular v18.0.0-next.4
2
+ * @license Angular v18.0.0-next.6
3
3
  * (c) 2010-2024 Google LLC. https://angular.io/
4
4
  * License: MIT
5
5
  */
6
6
 
7
7
  import { ɵsetRootDomAdapter, DOCUMENT, PlatformLocation, XhrFactory, ɵgetDOM, ɵPLATFORM_SERVER_ID, ViewportScroller, ɵNullViewportScroller } from '@angular/common';
8
8
  import * as i0 from '@angular/core';
9
- import { Injectable, Inject, inject, InjectionToken, Optional, APP_ID, TransferState, Injector, PLATFORM_ID, PLATFORM_INITIALIZER, ɵALLOW_MULTIPLE_PLATFORMS, Testability, ɵTESTABILITY, NgModule, ɵsetDocument, createPlatformFactory, platformCore, makeEnvironmentProviders, ɵSSR_CONTENT_INTEGRITY_MARKER, Renderer2, ɵwhenStable, ɵIS_HYDRATION_DOM_REUSE_ENABLED, ɵannotateForHydration, ApplicationRef, Version } from '@angular/core';
9
+ import { Injectable, Inject, inject, InjectionToken, Optional, APP_ID, TransferState, Injector, PLATFORM_ID, PLATFORM_INITIALIZER, ɵALLOW_MULTIPLE_PLATFORMS, Testability, ɵTESTABILITY, NgModule, ɵsetDocument, createPlatformFactory, platformCore, makeEnvironmentProviders, ɵSSR_CONTENT_INTEGRITY_MARKER, Renderer2, ɵwhenStable, ɵIS_HYDRATION_DOM_REUSE_ENABLED, ɵannotateForHydration, CSP_NONCE, ApplicationRef, Version } from '@angular/core';
10
10
  import { ɵBrowserDomAdapter, EventManagerPlugin, EVENT_MANAGER_PLUGINS, BrowserModule } from '@angular/platform-browser';
11
11
  import { NoopAnimationsModule, provideNoopAnimations } from '@angular/platform-browser/animations';
12
12
  import { ɵHTTP_ROOT_INTERCEPTOR_FNS, HttpClientModule } from '@angular/common/http';
@@ -5032,7 +5032,7 @@ var require_CSSStyleDeclaration = __commonJS({
5032
5032
  delete styles.priority[property];
5033
5033
  }
5034
5034
  } else {
5035
- if (value.indexOf(";") !== -1)
5035
+ if (value.includes(";") && !value.includes("data:"))
5036
5036
  return;
5037
5037
  var newprops = parseStyles(property + ":" + value);
5038
5038
  if (Object.getOwnPropertyNames(newprops.property).length === 0) {
@@ -16216,10 +16216,10 @@ class PlatformState {
16216
16216
  getDocument() {
16217
16217
  return this._doc;
16218
16218
  }
16219
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.0-next.4", ngImport: i0, type: PlatformState, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable }); }
16220
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.0-next.4", ngImport: i0, type: PlatformState }); }
16219
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.0-next.6", ngImport: i0, type: PlatformState, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable }); }
16220
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.0-next.6", ngImport: i0, type: PlatformState }); }
16221
16221
  }
16222
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.0-next.4", ngImport: i0, type: PlatformState, decorators: [{
16222
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.0-next.6", ngImport: i0, type: PlatformState, decorators: [{
16223
16223
  type: Injectable
16224
16224
  }], ctorParameters: () => [{ type: undefined, decorators: [{
16225
16225
  type: Inject,
@@ -16244,10 +16244,10 @@ class ServerXhr {
16244
16244
  }
16245
16245
  return new impl.XMLHttpRequest();
16246
16246
  }
16247
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.0-next.4", ngImport: i0, type: ServerXhr, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
16248
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.0-next.4", ngImport: i0, type: ServerXhr }); }
16247
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.0-next.6", ngImport: i0, type: ServerXhr, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
16248
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.0-next.6", ngImport: i0, type: ServerXhr }); }
16249
16249
  }
16250
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.0-next.4", ngImport: i0, type: ServerXhr, decorators: [{
16250
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.0-next.6", ngImport: i0, type: ServerXhr, decorators: [{
16251
16251
  type: Injectable
16252
16252
  }] });
16253
16253
  function relativeUrlsTransformerInterceptorFn(request, next) {
@@ -16352,7 +16352,12 @@ class ServerPlatformLocation {
16352
16352
  }
16353
16353
  this.hash = value;
16354
16354
  const newUrl = this.url;
16355
- queueMicrotask(() => this._hashUpdate.next({ type: 'hashchange', state: null, oldUrl, newUrl }));
16355
+ queueMicrotask(() => this._hashUpdate.next({
16356
+ type: 'hashchange',
16357
+ state: null,
16358
+ oldUrl,
16359
+ newUrl,
16360
+ }));
16356
16361
  }
16357
16362
  replaceState(state, title, newUrl) {
16358
16363
  const oldUrl = this.url;
@@ -16374,10 +16379,10 @@ class ServerPlatformLocation {
16374
16379
  getState() {
16375
16380
  return undefined;
16376
16381
  }
16377
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.0-next.4", ngImport: i0, type: ServerPlatformLocation, deps: [{ token: DOCUMENT }, { token: INITIAL_CONFIG, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
16378
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.0-next.4", ngImport: i0, type: ServerPlatformLocation }); }
16382
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.0-next.6", ngImport: i0, type: ServerPlatformLocation, deps: [{ token: DOCUMENT }, { token: INITIAL_CONFIG, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
16383
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.0-next.6", ngImport: i0, type: ServerPlatformLocation }); }
16379
16384
  }
16380
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.0-next.4", ngImport: i0, type: ServerPlatformLocation, decorators: [{
16385
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.0-next.6", ngImport: i0, type: ServerPlatformLocation, decorators: [{
16381
16386
  type: Injectable
16382
16387
  }], ctorParameters: () => [{ type: undefined, decorators: [{
16383
16388
  type: Inject,
@@ -16401,10 +16406,10 @@ class ServerEventManagerPlugin extends EventManagerPlugin {
16401
16406
  addEventListener(element, eventName, handler) {
16402
16407
  return ɵgetDOM().onAndCancel(element, eventName, handler);
16403
16408
  }
16404
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.0-next.4", ngImport: i0, type: ServerEventManagerPlugin, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable }); }
16405
- static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.0-next.4", ngImport: i0, type: ServerEventManagerPlugin }); }
16409
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.0-next.6", ngImport: i0, type: ServerEventManagerPlugin, deps: [{ token: DOCUMENT }], target: i0.ɵɵFactoryTarget.Injectable }); }
16410
+ static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.0.0-next.6", ngImport: i0, type: ServerEventManagerPlugin }); }
16406
16411
  }
16407
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.0-next.4", ngImport: i0, type: ServerEventManagerPlugin, decorators: [{
16412
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.0-next.6", ngImport: i0, type: ServerEventManagerPlugin, decorators: [{
16408
16413
  type: Injectable
16409
16414
  }], ctorParameters: () => [{ type: undefined, decorators: [{
16410
16415
  type: Inject,
@@ -16419,6 +16424,15 @@ const TRANSFER_STATE_SERIALIZATION_PROVIDERS = [
16419
16424
  multi: true,
16420
16425
  },
16421
16426
  ];
16427
+ /** TODO: Move this to a utils folder and convert to use SafeValues. */
16428
+ function createScript(doc, textContent, nonce) {
16429
+ const script = doc.createElement('script');
16430
+ script.textContent = textContent;
16431
+ if (nonce) {
16432
+ script.setAttribute('nonce', nonce);
16433
+ }
16434
+ return script;
16435
+ }
16422
16436
  function serializeTransferStateFactory(doc, appId, transferStore) {
16423
16437
  return () => {
16424
16438
  // The `.toJSON` here causes the `onSerialize` callbacks to be called.
@@ -16429,10 +16443,14 @@ function serializeTransferStateFactory(doc, appId, transferStore) {
16429
16443
  // avoid creating an extra `<script>` tag in this case.
16430
16444
  return;
16431
16445
  }
16432
- const script = doc.createElement('script');
16446
+ const script = createScript(doc, content,
16447
+ /**
16448
+ * `nonce` is not required for 'application/json'
16449
+ * See: https://html.spec.whatwg.org/multipage/scripting.html#attr-script-type
16450
+ */
16451
+ null);
16433
16452
  script.id = appId + '-state';
16434
16453
  script.setAttribute('type', 'application/json');
16435
- script.textContent = content;
16436
16454
  // It is intentional that we add the script at the very bottom. Angular CLI script tags for
16437
16455
  // bundles are always `type="module"`. These are deferred by default and cause the transfer
16438
16456
  // transfer data to be queried only after the browser has finished parsing the DOM.
@@ -16443,14 +16461,15 @@ function serializeTransferStateFactory(doc, appId, transferStore) {
16443
16461
  const INTERNAL_SERVER_PLATFORM_PROVIDERS = [
16444
16462
  { provide: DOCUMENT, useFactory: _document, deps: [Injector] },
16445
16463
  { provide: PLATFORM_ID, useValue: ɵPLATFORM_SERVER_ID },
16446
- { provide: PLATFORM_INITIALIZER, useFactory: initDominoAdapter, multi: true }, {
16464
+ { provide: PLATFORM_INITIALIZER, useFactory: initDominoAdapter, multi: true },
16465
+ {
16447
16466
  provide: PlatformLocation,
16448
16467
  useClass: ServerPlatformLocation,
16449
- deps: [DOCUMENT, [Optional, INITIAL_CONFIG]]
16468
+ deps: [DOCUMENT, [Optional, INITIAL_CONFIG]],
16450
16469
  },
16451
16470
  { provide: PlatformState, deps: [DOCUMENT] },
16452
16471
  // Add special provider that allows multiple instances of platformServer* to be created.
16453
- { provide: ɵALLOW_MULTIPLE_PLATFORMS, useValue: true }
16472
+ { provide: ɵALLOW_MULTIPLE_PLATFORMS, useValue: true },
16454
16473
  ];
16455
16474
  function initDominoAdapter() {
16456
16475
  return () => {
@@ -16474,11 +16493,11 @@ const PLATFORM_SERVER_PROVIDERS = [
16474
16493
  * @publicApi
16475
16494
  */
16476
16495
  class ServerModule {
16477
- static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.0-next.4", ngImport: i0, type: ServerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
16478
- static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.0.0-next.4", ngImport: i0, type: ServerModule, imports: [HttpClientModule, NoopAnimationsModule], exports: [BrowserModule] }); }
16479
- static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.0.0-next.4", ngImport: i0, type: ServerModule, providers: PLATFORM_SERVER_PROVIDERS, imports: [HttpClientModule, NoopAnimationsModule, BrowserModule] }); }
16496
+ static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.0.0-next.6", ngImport: i0, type: ServerModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); }
16497
+ static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "18.0.0-next.6", ngImport: i0, type: ServerModule, imports: [HttpClientModule, NoopAnimationsModule], exports: [BrowserModule] }); }
16498
+ static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "18.0.0-next.6", ngImport: i0, type: ServerModule, providers: PLATFORM_SERVER_PROVIDERS, imports: [HttpClientModule, NoopAnimationsModule, BrowserModule] }); }
16480
16499
  }
16481
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.0-next.4", ngImport: i0, type: ServerModule, decorators: [{
16500
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.0.0-next.6", ngImport: i0, type: ServerModule, decorators: [{
16482
16501
  type: NgModule,
16483
16502
  args: [{
16484
16503
  exports: [BrowserModule],
@@ -16490,8 +16509,10 @@ function _document(injector) {
16490
16509
  const config = injector.get(INITIAL_CONFIG, null);
16491
16510
  let document;
16492
16511
  if (config && config.document) {
16493
- document = typeof config.document === 'string' ? parseDocument(config.document, config.url) :
16494
- config.document;
16512
+ document =
16513
+ typeof config.document === 'string'
16514
+ ? parseDocument(config.document, config.url)
16515
+ : config.document;
16495
16516
  }
16496
16517
  else {
16497
16518
  document = ɵgetDOM().createHtmlDocument();
@@ -16521,12 +16542,18 @@ const platformServer = createPlatformFactory(platformCore, 'server', INTERNAL_SE
16521
16542
  * @returns A set of providers to setup the server.
16522
16543
  */
16523
16544
  function provideServerRendering() {
16524
- return makeEnvironmentProviders([
16525
- provideNoopAnimations(),
16526
- ...PLATFORM_SERVER_PROVIDERS,
16527
- ]);
16545
+ return makeEnvironmentProviders([provideNoopAnimations(), ...PLATFORM_SERVER_PROVIDERS]);
16528
16546
  }
16529
16547
 
16548
+ /**
16549
+ * Event dispatch (JSAction) script is inlined into the HTML by the build
16550
+ * process to avoid extra blocking request on a page. The script looks like this:
16551
+ * ```
16552
+ * <script type="text/javascript" id="ng-event-dispatch-contract">...</script>
16553
+ * ```
16554
+ * This const represents the "id" attribute value.
16555
+ */
16556
+ const EVENT_DISPATCH_SCRIPT_ID = 'ng-event-dispatch-contract';
16530
16557
  /**
16531
16558
  * Creates an instance of a server platform (with or without JIT compiler support
16532
16559
  * depending on the `ngJitMode` global const value), using provided options.
@@ -16535,9 +16562,23 @@ function createServerPlatform(options) {
16535
16562
  const extraProviders = options.platformProviders ?? [];
16536
16563
  return platformServer([
16537
16564
  { provide: INITIAL_CONFIG, useValue: { document: options.document, url: options.url } },
16538
- extraProviders
16565
+ extraProviders,
16539
16566
  ]);
16540
16567
  }
16568
+ /**
16569
+ * Finds and returns inlined event dispatch script if it exists.
16570
+ * See the `EVENT_DISPATCH_SCRIPT_ID` const docs for additional info.
16571
+ */
16572
+ function findEventDispatchScript(doc) {
16573
+ return doc.getElementById(EVENT_DISPATCH_SCRIPT_ID);
16574
+ }
16575
+ /**
16576
+ * Removes inlined event dispatch script if it exists.
16577
+ * See the `EVENT_DISPATCH_SCRIPT_ID` const docs for additional info.
16578
+ */
16579
+ function removeEventDispatchScript(doc) {
16580
+ findEventDispatchScript(doc)?.remove();
16581
+ }
16541
16582
  /**
16542
16583
  * Creates a marker comment node and append it into the `<body>`.
16543
16584
  * Some CDNs have mechanisms to remove all comment node from HTML.
@@ -16545,10 +16586,11 @@ function createServerPlatform(options) {
16545
16586
  * marker comment is still available or else throw an error
16546
16587
  */
16547
16588
  function appendSsrContentIntegrityMarker(doc) {
16548
- // Adding a ng hydration marken comment
16589
+ // Adding a ng hydration marker comment
16549
16590
  const comment = doc.createComment(ɵSSR_CONTENT_INTEGRITY_MARKER);
16550
- doc.body.firstChild ? doc.body.insertBefore(comment, doc.body.firstChild) :
16551
- doc.body.append(comment);
16591
+ doc.body.firstChild
16592
+ ? doc.body.insertBefore(comment, doc.body.firstChild)
16593
+ : doc.body.append(comment);
16552
16594
  }
16553
16595
  /**
16554
16596
  * Adds the `ng-server-context` attribute to host elements of all bootstrapped components
@@ -16557,7 +16599,7 @@ function appendSsrContentIntegrityMarker(doc) {
16557
16599
  function appendServerContextInfo(applicationRef) {
16558
16600
  const injector = applicationRef.injector;
16559
16601
  let serverContext = sanitizeServerContext(injector.get(SERVER_CONTEXT, DEFAULT_SERVER_CONTEXT));
16560
- applicationRef.components.forEach(componentRef => {
16602
+ applicationRef.components.forEach((componentRef) => {
16561
16603
  const renderer = componentRef.injector.get(Renderer2);
16562
16604
  const element = componentRef.location.nativeElement;
16563
16605
  if (element) {
@@ -16565,15 +16607,35 @@ function appendServerContextInfo(applicationRef) {
16565
16607
  }
16566
16608
  });
16567
16609
  }
16610
+ function insertEventRecordScript(appId, doc, eventTypesToBeReplayed, nonce) {
16611
+ const eventDispatchScript = findEventDispatchScript(doc);
16612
+ if (eventDispatchScript) {
16613
+ const events = Array.from(eventTypesToBeReplayed);
16614
+ // This is defined in packages/core/primitives/event-dispatch/contract_binary.ts
16615
+ const replayScriptContents = `window.__jsaction_bootstrap('ngContracts', document.body, ${JSON.stringify(appId)}, ${JSON.stringify(events)});`;
16616
+ const replayScript = createScript(doc, replayScriptContents, nonce);
16617
+ // Insert replay script right after inlined event dispatch script, since it
16618
+ // relies on `__jsaction_bootstrap` to be defined in the global scope.
16619
+ eventDispatchScript.after(replayScript);
16620
+ }
16621
+ }
16568
16622
  async function _render(platformRef, applicationRef) {
16569
16623
  const environmentInjector = applicationRef.injector;
16570
16624
  // Block until application is stable.
16571
16625
  await ɵwhenStable(applicationRef);
16572
16626
  const platformState = platformRef.injector.get(PlatformState);
16573
- if (applicationRef.injector.get(ɵIS_HYDRATION_DOM_REUSE_ENABLED, false)) {
16627
+ if (environmentInjector.get(ɵIS_HYDRATION_DOM_REUSE_ENABLED, false)) {
16574
16628
  const doc = platformState.getDocument();
16575
16629
  appendSsrContentIntegrityMarker(doc);
16576
- ɵannotateForHydration(applicationRef, doc);
16630
+ const eventTypesToBeReplayed = ɵannotateForHydration(applicationRef, doc);
16631
+ if (eventTypesToBeReplayed) {
16632
+ insertEventRecordScript(environmentInjector.get(APP_ID), doc, eventTypesToBeReplayed, environmentInjector.get(CSP_NONCE, null));
16633
+ }
16634
+ else {
16635
+ // No events to replay, we should remove inlined event dispatch script
16636
+ // (which was injected by the build process) from the HTML.
16637
+ removeEventDispatchScript(doc);
16638
+ }
16577
16639
  }
16578
16640
  // Run any BEFORE_APP_SERIALIZED callbacks just before rendering to string.
16579
16641
  const callbacks = environmentInjector.get(BEFORE_APP_SERIALIZED, null);
@@ -16683,7 +16745,7 @@ async function renderApplication(bootstrap, options) {
16683
16745
  /**
16684
16746
  * @publicApi
16685
16747
  */
16686
- const VERSION = new Version('18.0.0-next.4');
16748
+ const VERSION = new Version('18.0.0-next.6');
16687
16749
 
16688
16750
  /// <reference types="node" />
16689
16751
  // This file only reexports content of the `src` folder. Keep it that way.