Skip to content

Commit

Permalink
fix(core): empty and errors were blocking Universal rendering (#1832)
Browse files Browse the repository at this point in the history
* fix(core): empty and errors were blocking Universal rendering

* fix(core): handle more than one emissions in keepUnstableUntilFirst
  • Loading branch information
jamesdaniels authored and davideast committed Aug 23, 2018
1 parent d945614 commit 36a8ff8
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 30 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@
"protractor": "3.0.0",
"reflect-metadata": "0.1.2",
"rimraf": "^2.5.4",
"rollup": "^0.35.11",
"rollup-plugin-node-resolve": "^3.0.0",
"rollup-watch": "^2.5.0",
"rollup": "^0.64.1",
"rollup-plugin-node-resolve": "^3.3.0",
"rollup-watch": "^4.3.1",
"shelljs": "^0.8.0",
"systemjs": "^0.19.16",
"systemjs-builder": "^0.15.7",
Expand Down
19 changes: 15 additions & 4 deletions src/core/angularfire2.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { InjectionToken, NgZone } from '@angular/core';
import { isPlatformServer } from '@angular/common';
import { Observable, Subscription, queueScheduler as queue } from 'rxjs';
import { first } from 'rxjs/operators';

// Put in database.ts when we drop database-depreciated
export const RealtimeDatabaseURL = new InjectionToken<string>('angularfire2.realtimeDatabaseURL');
Expand All @@ -17,8 +16,20 @@ export class FirebaseZoneScheduler {
return new Observable<T>(subscriber => {
const noop = () => {};
const task = Zone.current.scheduleMacroTask('firebaseZoneBlock', noop, {}, noop, noop);
obs$.pipe(first()).subscribe(() => this.zone.runOutsideAngular(() => task.invoke()));
return obs$.subscribe(subscriber);
obs$.subscribe(
next => {
if (task.state === 'scheduled') { task.invoke() };
subscriber.next(next);
},
error => {
if (task.state === 'scheduled') { task.invoke() }
subscriber.error(error);
},
() => {
if (task.state === 'scheduled') { task.invoke() }
subscriber.complete();
}
);
});
} else {
return obs$;
Expand Down Expand Up @@ -47,4 +58,4 @@ export const runOutsideAngular = (zone: NgZone) => <T>(obs$: Observable<T>): Obs
);
});
});
}
}
3 changes: 2 additions & 1 deletion src/messaging/messaging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export class AngularFireMessaging {

if (isPlatformBrowser(platformId)) {

const requireMessaging = from(require('firebase/messaging'));
// @ts-ignore
const requireMessaging = from(import('firebase/messaging'));

this.messaging = requireMessaging.pipe(
map(() => _firebaseAppFactory(options, nameOrConfig)),
Expand Down
20 changes: 10 additions & 10 deletions tools/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,25 +115,25 @@ function spawnObservable(command, args) {
});
}

function generateBundle(entry, { dest, globals, moduleName }) {
return rollup({ entry }).then(bundle => {
function generateBundle(input, { file, globals, name }) {
return rollup({ input }).then(bundle => {
return bundle.write({
format: 'umd',
external: Object.keys(globals),
plugins: [resolve()],
dest,
file,
globals,
moduleName,
name,
});
});
}

function createFirebaseBundles(featurePaths, globals) {
return Object.keys(featurePaths).map(feature => {
return generateBundle(featurePaths[feature], {
dest: `${process.cwd()}/dist/bundles/${feature}.js`,
file: `${process.cwd()}/dist/bundles/${feature}.js`,
globals,
moduleName: `firebase.${feature}`
name: `firebase.${feature}`
});
});
}
Expand All @@ -148,19 +148,19 @@ function createUmd(name, globals) {
const moduleName = MODULE_NAMES[name];
const entry = ENTRIES[name];
return generateBundle(entry, {
dest: `${process.cwd()}/dist/packages-dist/bundles/${name}.umd.js`,
file: `${process.cwd()}/dist/packages-dist/bundles/${name}.umd.js`,
globals,
moduleName
name: moduleName
});
}

function createTestUmd(globals) {
const entry = `${process.cwd()}/dist/root.spec.js`;
const moduleName = 'angularfire2.test';
return generateBundle(entry, {
dest: `${process.cwd()}/dist/packages-dist/bundles/test.umd.js`,
file: `${process.cwd()}/dist/packages-dist/bundles/test.umd.js`,
globals,
moduleName
name: moduleName
});
}

Expand Down
46 changes: 34 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@
version "0.2.8"
resolved "https://registry.yarnpkg.com/@firebase/webchannel-wrapper/-/webchannel-wrapper-0.2.8.tgz#38a936b60b898a1ad0f3719543ff1a1031f60f8b"

"@types/estree@0.0.39":
version "0.0.39"
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f"

"@types/form-data@0.0.*":
version "0.0.33"
resolved "https://registry.yarnpkg.com/@types/form-data/-/form-data-0.0.33.tgz#c9ac85b2a5fd18435b8c85d9ecb50e6d6c893ff8"
Expand Down Expand Up @@ -936,7 +940,7 @@ chalk@^2.0.1, chalk@^2.1.0:
escape-string-regexp "^1.0.5"
supports-color "^5.3.0"

chokidar@^1.4.1, chokidar@^1.4.2:
chokidar@^1.4.1, chokidar@^1.4.2, chokidar@^1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.7.0.tgz#798e689778151c8076b4b360e5edd28cda2bb468"
dependencies:
Expand Down Expand Up @@ -1683,6 +1687,10 @@ estraverse@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.2.0.tgz#0dee3fed31fcd469618ce7342099fc1afa0bdb13"

estree-walker@^0.5.2:
version "0.5.2"
resolved "https://registry.yarnpkg.com/estree-walker/-/estree-walker-0.5.2.tgz#d3850be7529c9580d815600b53126515e146dd39"

esutils@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b"
Expand Down Expand Up @@ -3500,7 +3508,7 @@ merge-stream@^1.0.0:
dependencies:
readable-stream "^2.0.1"

micromatch@^2.1.5, micromatch@^2.3.7:
micromatch@^2.1.5, micromatch@^2.3.11, micromatch@^2.3.7:
version "2.3.11"
resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-2.3.11.tgz#86677c97d1720b363431d04d0d15293bd38c1565"
dependencies:
Expand Down Expand Up @@ -4616,6 +4624,10 @@ requestretry@^1.2.2:
request "^2.74.0"
when "^3.7.7"

require-relative@0.8.7:
version "0.8.7"
resolved "https://registry.yarnpkg.com/require-relative/-/require-relative-0.8.7.tgz#7999539fc9e047a37928fa196f8e1563dabd36de"

requires-port@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/requires-port/-/requires-port-1.0.0.tgz#925d2601d39ac485e091cf0da5c6e694dc3dcaff"
Expand Down Expand Up @@ -4653,32 +4665,42 @@ rimraf@^2.2.8, rimraf@^2.5.4, rimraf@^2.6.0, rimraf@^2.6.1:
dependencies:
glob "^7.0.5"

rollup-plugin-node-resolve@^3.0.0:
rollup-plugin-node-resolve@^3.3.0:
version "3.3.0"
resolved "https://registry.yarnpkg.com/rollup-plugin-node-resolve/-/rollup-plugin-node-resolve-3.3.0.tgz#c26d110a36812cbefa7ce117cadcd3439aa1c713"
dependencies:
builtin-modules "^2.0.0"
is-module "^1.0.0"
resolve "^1.1.6"

rollup-watch@^2.5.0:
version "2.5.0"
resolved "https://registry.yarnpkg.com/rollup-watch/-/rollup-watch-2.5.0.tgz#852d660ddecc51696890aa8c22e95ed4558cc5f7"
rollup-pluginutils@^2.0.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-2.3.1.tgz#760d185ccc237dedc12d7ae48c6bcd127b4892d0"
dependencies:
semver "^5.1.0"
estree-walker "^0.5.2"
micromatch "^2.3.11"

rollup@^0.35.11:
version "0.35.15"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-0.35.15.tgz#f1df97205ea7c7ce79afbf113c7b1a61ec8300fd"
rollup-watch@^4.3.1:
version "4.3.1"
resolved "https://registry.yarnpkg.com/rollup-watch/-/rollup-watch-4.3.1.tgz#5aa1eaeab787addf368905d102b39d6fc5ce4a8b"
dependencies:
source-map-support "^0.4.0"
chokidar "^1.7.0"
require-relative "0.8.7"
rollup-pluginutils "^2.0.1"

rollup@^0.36.3:
version "0.36.4"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-0.36.4.tgz#a224494c5386c1d73d38f7bb86f69f5eb011a3d2"
dependencies:
source-map-support "^0.4.0"

rollup@^0.64.1:
version "0.64.1"
resolved "https://registry.yarnpkg.com/rollup/-/rollup-0.64.1.tgz#9188ee368e5fcd43ffbc00ec414e72eeb5de87ba"
dependencies:
"@types/estree" "0.0.39"
"@types/node" "*"

rsvp@^3.0.13:
version "3.6.2"
resolved "https://registry.yarnpkg.com/rsvp/-/rsvp-3.6.2.tgz#2e96491599a96cde1b515d5674a8f7a91452926a"
Expand Down Expand Up @@ -4731,7 +4753,7 @@ selenium-webdriver@2.48.2:
ws "^0.8.0"
xml2js "0.4.4"

"semver@2 || 3 || 4 || 5", semver@^5.1.0, semver@^5.3.0, semver@^5.4.1, semver@^5.5.0:
"semver@2 || 3 || 4 || 5", semver@^5.3.0, semver@^5.4.1, semver@^5.5.0:
version "5.5.0"
resolved "https://registry.yarnpkg.com/semver/-/semver-5.5.0.tgz#dc4bbc7a6ca9d916dee5d43516f0092b58f7b8ab"

Expand Down

1 comment on commit 36a8ff8

@ahmedfaisall
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why i have error not find firebase
i tried :(

Please sign in to comment.