Skip to content

Commit fc897af

Browse files
committed
Resolve some bugs that were found when running ng-render on a client project
1 parent 1c229c0 commit fc897af

File tree

4 files changed

+27
-17
lines changed

4 files changed

+27
-17
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-ssr",
3-
"version": "0.10.6",
3+
"version": "0.10.7",
44
"description": "Angular server-side rendering implementation",
55
"main": "build/index.js",
66
"typings": "build/index.d.ts",
@@ -79,7 +79,7 @@
7979
"bluebird": "^3.4.7",
8080
"chalk": "^1.1.3",
8181
"commander": "2.9.0",
82-
"domino": "https://github.com/clbond/domino/archive/1.0.44.tar.gz",
82+
"domino": "https://github.com/clbond/domino/archive/1.0.45.tar.gz",
8383
"jsonschema": "^1.1.1",
8484
"lru_map": "^0.3.3",
8585
"mkdir-recursive": "^0.3.0",
@@ -90,7 +90,7 @@
9090
"rimraf": "2.5.4",
9191
"rxjs": "^5.0.1",
9292
"scoped-logger": "^0.0.19",
93-
"source-map-support": "^0.4.11",
93+
"source-map-support": ">=0.1.0",
9494
"symbol-observable": "^1.0.4",
9595
"xhr2": "^0.1.4"
9696
},

source/runtime/browser-emulation/create.ts

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,25 @@ import {bindTypes} from './types';
1616

1717
Object.assign(global, {__domino_frozen__: false}); // allow overwrite
1818

19+
const conditionalOverwrite = (target, fills: Array<any>) => {
20+
for (const [overwrite, properties] of fills) {
21+
for (const k in properties) {
22+
if (overwrite || typeof target[k] === 'undefined') {
23+
Object.defineProperty(target, k, {
24+
configurable: true,
25+
enumerable: false,
26+
value: properties[k],
27+
writable: true,
28+
});
29+
}
30+
}
31+
}
32+
};
33+
1934
export const upgradeWindow = (target, window: () => Window): void => {
2035
const {impl: DOM} = domino;
2136

22-
const fills = [
37+
conditionalOverwrite(target, [
2338
[true, DOM],
2439
[true, bindTypes],
2540
bindAnimation(window),
@@ -34,19 +49,12 @@ export const upgradeWindow = (target, window: () => Window): void => {
3449
bindSelection(window),
3550
bindStorage(window),
3651
bindStyle(window),
37-
];
52+
]);
3853

39-
for (const [overwrite, properties] of fills) {
40-
for (const k in properties) {
41-
if (overwrite || typeof target[k] === 'undefined') {
42-
Object.defineProperty(target, k, {
43-
configurable: true,
44-
enumerable: false,
45-
value: properties[k],
46-
writable: true,
47-
});
48-
}
49-
}
54+
if (target.document) {
55+
conditionalOverwrite(target.document, [
56+
bindSelection(() => window().document)
57+
]);
5058
}
5159
};
5260

source/runtime/browser-emulation/selection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ export class Selection implements Selection {
8282

8383
const getSelection = () => new Selection();
8484

85-
export const bindSelection = (target: () => Window) => [true, {getSelection}];
85+
export const bindSelection = (target: () => Window | Document) => [true, {getSelection}];

source/runtime/browser-emulation/tests/window.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,13 @@ describe('window', () => {
2727

2828
it('focus', async () => {
2929
expect(() => window.focus()).not.toThrow();
30+
expect(() => typeof HTMLElement.prototype.focus === 'function').toBeTruthy();
3031
});
3132

3233
it('getSelection', async () => {
3334
let selection: Selection;
3435
expect(() => selection = window.getSelection()).not.toThrow();
36+
expect(() => selection = window.document.getSelection()).not.toThrow();
3537
expect(selection).not.toBeNull();
3638
expect(selection.anchorNode).toBeNull();
3739
expect(selection.baseNode).toBeNull();

0 commit comments

Comments
 (0)