Skip to content

Commit

Permalink
refactor(platform-browser): update renderer to be able to remove `Ser…
Browse files Browse the repository at this point in the history
…verRendererFactory2` and `EmulatedEncapsulationServerRenderer2` (#49630)

This commits updates the render to able to handle the slight differences between platform-server and platform-browser.

This is needed to eventually be able to remove `ServerRendererFactory2` and `EmulatedEncapsulationServerRenderer2` from platform-server.

PR Close #49630
  • Loading branch information
alan-agius4 authored and dylhunn committed Apr 5, 2023
1 parent a6fc8b3 commit 42f2f41
Show file tree
Hide file tree
Showing 14 changed files with 154 additions and 90 deletions.
8 changes: 5 additions & 3 deletions packages/core/test/acceptance/renderer_factory_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ import {AnimationEvent} from '@angular/animations';
import {ɵAnimationEngine, ɵNoopAnimationStyleNormalizer} from '@angular/animations/browser';
import {MockAnimationDriver, MockAnimationPlayer} from '@angular/animations/browser/testing';
import {CommonModule, DOCUMENT} from '@angular/common';
import {PLATFORM_BROWSER_ID, PLATFORM_SERVER_ID} from '@angular/common/src/platform_id';
import {Component, DoCheck, NgZone, Renderer2, RendererFactory2, RendererStyleFlags2, RendererType2, ViewEncapsulation} from '@angular/core';
import {RElement} from '@angular/core/src/render3/interfaces/renderer_dom';
import {ngDevModeResetPerfCounters} from '@angular/core/src/util/ng_dev_mode';
import {NoopNgZone} from '@angular/core/src/zone/ng_zone';
import {TestBed} from '@angular/core/testing';
import {EventManager, ɵSharedStylesHost} from '@angular/platform-browser';
import {ɵAnimationRendererFactory} from '@angular/platform-browser/animations';
import {DomRendererFactory2} from '@angular/platform-browser/src/dom/dom_renderer';
import {expect} from '@angular/platform-browser/testing/src/matchers';
import {ServerRendererFactory2} from '@angular/platform-server/src/server_renderer';

describe('renderer factory lifecycle', () => {
let logs: string[] = [];
Expand Down Expand Up @@ -322,8 +323,9 @@ function getRendererFactory2(document: any): RendererFactory2 {
const fakeNgZone: NgZone = new NoopNgZone();
const eventManager = new EventManager([], fakeNgZone);
const appId = 'app-id';
const rendererFactory = new ServerRendererFactory2(
eventManager, fakeNgZone, document, new ɵSharedStylesHost(document, appId), appId);
const rendererFactory = new DomRendererFactory2(
eventManager, new ɵSharedStylesHost(document, appId), appId, true, document,
isNode ? PLATFORM_SERVER_ID : PLATFORM_BROWSER_ID, fakeNgZone);
const origCreateRenderer = rendererFactory.createRenderer;
rendererFactory.createRenderer = function(element: any, type: RendererType2|null) {
const renderer = origCreateRenderer.call(this, element, type);
Expand Down
2 changes: 2 additions & 0 deletions packages/core/test/application_ref_integration_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {DOCUMENT} from '@angular/common';
import {ApplicationRef, Component, DoCheck, NgModule, OnInit, TestabilityRegistry} from '@angular/core';
import {getTestBed} from '@angular/core/testing';
import {BrowserModule} from '@angular/platform-browser';
Expand Down Expand Up @@ -34,6 +35,7 @@ describe('ApplicationRef bootstrap', () => {
declarations: [HelloWorldComponent],
bootstrap: [HelloWorldComponent],
imports: [BrowserModule],
providers: [{provide: DOCUMENT, useFactory: () => document}]
})
class MyAppModule {
}
Expand Down
32 changes: 10 additions & 22 deletions packages/core/test/bundling/animations/bundle.golden_symbols.json
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,9 @@
{
"name": "PLATFORM_INITIALIZER"
},
{
"name": "PLATFORM_SERVER_ID"
},
{
"name": "PRESERVE_HOST_CONTENT"
},
Expand Down Expand Up @@ -641,18 +644,12 @@
{
"name": "_applyRootElementTransformImpl"
},
{
"name": "_contains"
},
{
"name": "_convertTimeValueToMS"
},
{
"name": "_currentInjector"
},
{
"name": "_documentElement"
},
{
"name": "_enable_super_gross_mode_that_will_cause_bad_things"
},
Expand Down Expand Up @@ -686,9 +683,6 @@
{
"name": "_processI18nInsertBefore"
},
{
"name": "_query"
},
{
"name": "_retrieveHydrationInfoImpl"
},
Expand Down Expand Up @@ -884,6 +878,9 @@
{
"name": "diPublicInInjector"
},
{
"name": "dominoElementHasProperty"
},
{
"name": "empty"
},
Expand Down Expand Up @@ -1064,9 +1061,6 @@
{
"name": "getSimpleChangesStore"
},
{
"name": "getStyleAttributeString"
},
{
"name": "getSymbolIterator"
},
Expand Down Expand Up @@ -1157,9 +1151,6 @@
{
"name": "isArrayLike"
},
{
"name": "isBrowser"
},
{
"name": "isComponentDef"
},
Expand Down Expand Up @@ -1193,9 +1184,6 @@
{
"name": "isLView"
},
{
"name": "isNode"
},
{
"name": "isNodeMatchingSelector"
},
Expand All @@ -1205,6 +1193,9 @@
{
"name": "isObject"
},
{
"name": "isPlatformServer"
},
{
"name": "isPositive"
},
Expand Down Expand Up @@ -1544,9 +1535,6 @@
{
"name": "writeDirectClass"
},
{
"name": "writeStyleAttribute"
},
{
"name": "ɵPRE_STYLE"
},
Expand Down Expand Up @@ -1580,4 +1568,4 @@
{
"name": "ɵɵproperty"
}
]
]
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,9 @@
{
"name": "PLATFORM_INITIALIZER"
},
{
"name": "PLATFORM_SERVER_ID"
},
{
"name": "PRESERVE_HOST_CONTENT"
},
Expand Down Expand Up @@ -938,6 +941,9 @@
{
"name": "isObject"
},
{
"name": "isPlatformServer"
},
{
"name": "isPositive"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,9 @@
{
"name": "PLATFORM_INITIALIZER"
},
{
"name": "PLATFORM_SERVER_ID"
},
{
"name": "PRESERVE_HOST_CONTENT"
},
Expand Down Expand Up @@ -1304,6 +1307,9 @@
{
"name": "isOptionsObj"
},
{
"name": "isPlatformServer"
},
{
"name": "isPositive"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,9 @@
{
"name": "PLATFORM_INITIALIZER"
},
{
"name": "PLATFORM_SERVER_ID"
},
{
"name": "PRESERVE_HOST_CONTENT"
},
Expand Down Expand Up @@ -1262,6 +1265,9 @@
{
"name": "isOptionsObj"
},
{
"name": "isPlatformServer"
},
{
"name": "isPositive"
},
Expand Down
6 changes: 6 additions & 0 deletions packages/core/test/bundling/router/bundle.golden_symbols.json
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,9 @@
{
"name": "PLATFORM_INITIALIZER"
},
{
"name": "PLATFORM_SERVER_ID"
},
{
"name": "PRESERVE_HOST_CONTENT"
},
Expand Down Expand Up @@ -1595,6 +1598,9 @@
{
"name": "isObject"
},
{
"name": "isPlatformServer"
},
{
"name": "isPositive"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,9 @@
{
"name": "PLATFORM_INITIALIZER"
},
{
"name": "PLATFORM_SERVER_ID"
},
{
"name": "PRESERVE_HOST_CONTENT"
},
Expand Down Expand Up @@ -824,6 +827,9 @@
{
"name": "isObject"
},
{
"name": "isPlatformServer"
},
{
"name": "isPositive"
},
Expand Down
6 changes: 6 additions & 0 deletions packages/core/test/bundling/todo/bundle.golden_symbols.json
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@
{
"name": "PLATFORM_INITIALIZER"
},
{
"name": "PLATFORM_SERVER_ID"
},
{
"name": "PRESERVE_HOST_CONTENT"
},
Expand Down Expand Up @@ -1130,6 +1133,9 @@
{
"name": "isObject"
},
{
"name": "isPlatformServer"
},
{
"name": "isPositive"
},
Expand Down
6 changes: 4 additions & 2 deletions packages/core/test/render3/imported_renderer2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import {ɵAnimationEngine, ɵNoopAnimationStyleNormalizer} from '@angular/animations/browser';
import {MockAnimationDriver} from '@angular/animations/browser/testing';
import {PLATFORM_BROWSER_ID, PLATFORM_SERVER_ID} from '@angular/common/src/platform_id';
import {NgZone, RendererFactory2, RendererType2} from '@angular/core';
import {NoopNgZone} from '@angular/core/src/zone/ng_zone';
import {EventManager, ɵDomRendererFactory2, ɵSharedStylesHost} from '@angular/platform-browser';
Expand Down Expand Up @@ -39,8 +40,9 @@ export function getRendererFactory2(document: any): RendererFactory2 {
const fakeNgZone: NgZone = new NoopNgZone();
const eventManager = new EventManager([new SimpleDomEventsPlugin(document)], fakeNgZone);
const appId = 'appid';
const rendererFactory =
new ɵDomRendererFactory2(eventManager, new ɵSharedStylesHost(document, appId), appId, true);
const rendererFactory = new ɵDomRendererFactory2(
eventManager, new ɵSharedStylesHost(document, appId), appId, true, document,
isNode ? PLATFORM_SERVER_ID : PLATFORM_BROWSER_ID, fakeNgZone);
const origCreateRenderer = rendererFactory.createRenderer;
rendererFactory.createRenderer = function(element: any, type: RendererType2|null) {
const renderer = origCreateRenderer.call(this, element, type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* found in the LICENSE file at https://angular.io/license
*/

import {COMPILER_OPTIONS, CompilerFactory, createPlatformFactory, platformCore, PlatformRef, StaticProvider} from '@angular/core';
import {COMPILER_OPTIONS, CompilerFactory, createPlatformFactory, platformCore} from '@angular/core';

import {JitCompilerFactory} from './compiler_factory';

Expand Down
Loading

0 comments on commit 42f2f41

Please sign in to comment.