Skip to content

Commit

Permalink
Load features faster /2 (#4352)
Browse files Browse the repository at this point in the history
  • Loading branch information
yakov116 committed May 17, 2021
1 parent 653cd95 commit 4254b5c
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 39 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"element-ready": "^6.0.0",
"fit-textarea": "^2.0.0",
"flat-zip": "^1.0.1",
"github-url-detection": "^5.0.0",
"github-url-detection": "^5.2.0",
"image-promise": "^7.0.1",
"indent-textarea": "^2.1.0",
"js-abbreviation-number": "^1.1.2",
Expand Down
60 changes: 29 additions & 31 deletions source/features/index.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import delay from 'delay';
import React from 'dom-chef';
import cache from 'webext-storage-cache';
import select from 'select-dom';
import domLoaded from 'dom-loaded';
import stripIndent from 'strip-indent';
import {Promisable} from 'type-fest';
import elementReady from 'element-ready';
import compareVersions from 'tiny-version-compare';
import * as pageDetect from 'github-url-detection';

Expand Down Expand Up @@ -82,20 +82,34 @@ let logError = (id: FeatureID, error: unknown): void => {

// eslint-disable-next-line no-async-promise-executor -- Rule assumes we don't want to leave it pending
const globalReady: Promise<RGHOptions> = new Promise(async resolve => {
await elementReady('body', {waitForChildren: false});
const [options, hotfix, bisectedFeatures] = await Promise.all([
optionsStorage.getAll(),
version === '0.0.0' || await cache.get('hotfix'), // Ignores the cache when loaded locally
bisectFeatures()
]);

if (pageDetect.is500()) {
return;
if (options.customCSS.trim().length > 0) {
document.head.append(<style>{options.customCSS}</style>);
}

if (document.title === 'Confirm password' || document.title === 'Confirm access') {
return;
if (bisectedFeatures) {
Object.assign(options, bisectedFeatures);
} else {
// If features are remotely marked as "seriously breaking" by the maintainers, disable them without having to wait for proper updates to propagate #3529
void checkForHotfixes();
Object.assign(options, hotfix);
}

if (document.body.classList.contains('logged-out')) {
console.warn('Refined GitHub is only expected to work when you’re logged in to GitHub. Errors will not be shown.');
features.error = () => {/* No logging */};
logError = () => {/* No logging */};
// Create logging function
log = options.logging ? console.log : () => {/* No logging */};

while (!document.body) {
// eslint-disable-next-line no-await-in-loop
await delay(10);
}

if (pageDetect.is500() || pageDetect.isPasswordConfirmation()) {
return;
}

if (select.exists('html.refined-github')) {
Expand All @@ -110,29 +124,13 @@ const globalReady: Promise<RGHOptions> = new Promise(async resolve => {
return;
}

document.documentElement.classList.add('refined-github');

// Options defaults
const [options, hotfix, bisectedFeatures] = await Promise.all([
optionsStorage.getAll(),
version === '0.0.0' || await cache.get('hotfix'), // Ignores the cache when loaded locally
bisectFeatures()
]);

if (bisectedFeatures) {
Object.assign(options, bisectedFeatures);
} else {
// If features are remotely marked as "seriously breaking" by the maintainers, disable them without having to wait for proper updates to propagate #3529
void checkForHotfixes();
Object.assign(options, hotfix);
}

if (options.customCSS.trim().length > 0) {
document.head.append(<style>{options.customCSS}</style>);
if (select.exists('body.logged-out')) {
console.warn('Refined GitHub is only expected to work when you’re logged in to GitHub. Errors will not be shown.');
features.error = () => {/* No logging */};
logError = () => {/* No logging */};
}

// Create logging function
log = options.logging ? console.log : () => {/* No logging */};
document.documentElement.classList.add('refined-github');

resolve(options);
});
Expand Down

0 comments on commit 4254b5c

Please sign in to comment.