diff --git a/hyperion/renderer/browser-shim.js b/hyperion/renderer/browser-shim.js index e854c532f2..929adb9865 100644 --- a/hyperion/renderer/browser-shim.js +++ b/hyperion/renderer/browser-shim.js @@ -20,4 +20,3 @@ global.navigator = { global.CSS = { escape: require('css.escape'), }; -global.IS_SERVER = true; diff --git a/src/helpers/p-queue.js b/src/helpers/p-queue.js deleted file mode 100644 index 8cec3f6af8..0000000000 --- a/src/helpers/p-queue.js +++ /dev/null @@ -1,101 +0,0 @@ -// @flow -// based on https://github.com/zeit/next.js/blob/82d56e063aad12ac8fee5b9d5ed24ccf725b1a5b/packages/next-server/lib/p-queue.js -// with adapted code style and flow types added -// which is itself based on https://github.com/sindresorhus/p-queue (MIT) -// modified for browser support - -class Queue { - _queue: Array; - - constructor() { - this._queue = []; - } - enqueue(run) { - this._queue.push(run); - } - dequeue() { - return this._queue.shift(); - } - size() { - return this._queue.length; - } -} - -type Options = { - concurrency: number, -}; - -export default class PQueue { - queue: any; - _pendingCount: number; - _concurrency: number; - _resolveEmpty: Function; - - constructor(opts: Options) { - opts = Object.assign( - { - concurrency: Infinity, - }, - opts - ); - - if (opts.concurrency < 1) { - throw new TypeError( - 'Expected `concurrency` to be a number from 1 and up' - ); - } - - this.queue = new Queue(); - this._pendingCount = 0; - this._concurrency = opts.concurrency; - this._resolveEmpty = () => {}; - } - _next() { - this._pendingCount--; - - if (this.queue.size() > 0) { - this.queue.dequeue()(); - } else { - this._resolveEmpty(); - } - } - add(fn: () => Promise): Promise { - return new Promise((resolve, reject) => { - const run = () => { - this._pendingCount++; - - fn().then( - val => { - resolve(val); - this._next(); - }, - err => { - reject(err); - this._next(); - } - ); - }; - - if (this._pendingCount < this._concurrency) { - run(); - } else { - this.queue.enqueue(run); - } - }); - } - onEmpty(): Promise { - return new Promise(resolve => { - const existingResolve = this._resolveEmpty; - this._resolveEmpty = () => { - existingResolve(); - resolve(); - }; - }); - } - size() { - return this.queue.size(); - } - pending() { - return this._pendingCount; - } -} diff --git a/src/routes.js b/src/routes.js index 4a0d40a70c..065b74ac27 100644 --- a/src/routes.js +++ b/src/routes.js @@ -1,7 +1,6 @@ // @flow import * as React from 'react'; import compose from 'recompose/compose'; -import PromiseQueue from './helpers/p-queue'; import { Route, Switch, Redirect } from 'react-router'; import styled, { ThemeProvider } from 'styled-components'; import Loadable from 'react-loadable'; @@ -154,47 +153,6 @@ const ComposerFallback = signedOutFallback(Composer, () => ( )); -// On the client, preload the important routes when browser is idle and users has been using the app -// for > 5s (i.e. all the data should hopefully have been loaded) -if (!global || global.IS_SERVER !== true) { - const preload = [ - FullscreenThreadView, - CommunityView, - CommunityLoginView, - UserView, - ChannelView, - Dashboard, - Notifications, - ]; - - requestAnimationFrame(() => { - // Fallback to setTimeout for older browsers with no requestIdleCallback support - const idle = window.requestIdleCallback || window.setTimeout; - const queue = new PromiseQueue({ - concurrency: 2, - }); - idle(() => { - // Wait 5 seconds to make sure the data has loaded - setTimeout(() => { - preload.forEach(bundle => { - queue - .add(() => { - return new Promise(res => { - idle(() => { - bundle - .preload() - .then(res) - .catch(err => console.error(err)); - }); - }); - }) - .catch(err => console.error(err)); - }); - }, 5000); - }); - }); -} - type Props = { currentUser: ?GetUserType, isLoadingCurrentUser: boolean,