Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1177c07

Browse files
authored
Add ability to remove hotfixes temporarily (refined-github#9875)
1 parent 2282ee2 commit 1177c07

11 files changed

Lines changed: 78 additions & 81 deletions

package-lock.json

Lines changed: 7 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"webext-options-sync-per-domain": "^4.3.2",
7474
"webext-permission-toggle": "^7.0.1",
7575
"webext-storage": "^3.1.0",
76-
"webext-storage-cache": "^6.0.3",
76+
"webext-storage-cache": "^7.0.0",
7777
"webext-tools": "^4.1.0",
7878
"zip-text-nodes": "^1.0.0"
7979
},

source/feature-manager.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {isFeaturePrivate, type RunConditions, shouldFeatureRun} from './helpers/
1818
import {
1919
applyStyleHotfixes,
2020
brokenFeatures,
21-
getLocalHotfixesAsOptions,
21+
brokenFeaturesAsOptions,
2222
preloadSyncLocalStrings,
2323
} from './helpers/hotfix.js';
2424
import ArrayMap from './helpers/map-of-arrays.js';
@@ -81,7 +81,7 @@ const globalReady = new Promise<RghOptions>(async resolve => {
8181
const [options, willLoadContentScripts, localHotfixes, bisectedFeatures] = await Promise.all([
8282
optionsStorage.getAll(),
8383
contentScriptToggle.get(),
84-
getLocalHotfixesAsOptions(),
84+
brokenFeatures.getCached(), // Cached first, they're fetched asynchronously down below
8585
bisectFeatures(),
8686
preloadSyncLocalStrings(),
8787
]);
@@ -128,9 +128,11 @@ const globalReady = new Promise<RghOptions>(async resolve => {
128128
if (bisectedFeatures) {
129129
Object.assign(options, bisectedFeatures);
130130
} else {
131-
// If features are remotely marked as "seriously breaking" by the maintainers, disable them without having to wait for proper updates to propagate #3529
131+
// Use cached first
132+
Object.assign(options, brokenFeaturesAsOptions(localHotfixes));
133+
134+
// Asynchronously fetch the rest, if expired
132135
void brokenFeatures.get();
133-
Object.assign(options, localHotfixes);
134136
}
135137

136138
if (elementExists('body.logged-out')) {

source/helpers/hotfix.tsx

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import {CachedFunction} from 'webext-storage-cache';
66
import type {RghOptions} from '../options-storage.js';
77
import {getNewFeatureName} from '../feature-data.js';
88
import isDevelopmentVersion from './is-development-version.js';
9-
import {isomorphicFetchText} from './isomorphic-fetch.js';
9+
import {webextFetch} from './isomorphic-fetch.js';
1010
import {type BrokenFeatureEntry, parseBrokenFeaturesCsv} from './hotfix-parse.js';
1111

1212
const {version: currentVersion} = chrome.runtime.getManifest();
1313

1414
async function fetchHotfix(path: string): Promise<string> {
1515
// Use GitHub Pages host because the API is rate-limited
16-
return isomorphicFetchText(`https://refined-github.github.io/yolo/${path}`, {
16+
return webextFetch(`https://refined-github.github.io/yolo/${path}`, {
1717
cache: 'no-store', // Disable caching altogether
1818
});
1919
}
@@ -22,6 +22,12 @@ type HotfixStorage = BrokenFeatureEntry[];
2222

2323
export const brokenFeatures = new CachedFunction('broken-features', {
2424
async updater(): Promise<HotfixStorage> {
25+
// To facilitate debugging, ignore hotfixes during development.
26+
// Change the version in manifest.json to test hotfixes
27+
if (isDevelopmentVersion()) {
28+
return [];
29+
}
30+
2531
const content = await fetchHotfix('broken-features.csv');
2632
return parseBrokenFeaturesCsv(content, currentVersion);
2733
},
@@ -30,26 +36,19 @@ export const brokenFeatures = new CachedFunction('broken-features', {
3036
});
3137

3238
export const styleHotfixes = new CachedFunction('style-hotfixes', {
33-
updater: async (version: string): Promise<string> => fetchHotfix(`style/${version}.css`),
39+
// To facilitate debugging, ignore hotfixes during development.
40+
// Change the version in manifest.json to test hotfixes
41+
updater: async (version: string): Promise<string> =>
42+
isDevelopmentVersion() ? '' : fetchHotfix(`style/${version}.css`),
3443

3544
maxAge: {hours: 6},
3645
staleWhileRevalidate: {days: 300},
3746
cacheKey: () => '',
3847
});
3948

40-
export async function getLocalHotfixes(): Promise<HotfixStorage> {
41-
// To facilitate debugging, ignore hotfixes during development.
42-
// Change the version in manifest.json to test hotfixes
43-
if (isDevelopmentVersion()) {
44-
return [];
45-
}
46-
47-
return await brokenFeatures.get() ?? [];
48-
}
49-
50-
export async function getLocalHotfixesAsOptions(): Promise<Partial<RghOptions>> {
49+
export function brokenFeaturesAsOptions(brokenFeaturesStorage: HotfixStorage = []): Partial<RghOptions> {
5150
const options: Partial<RghOptions> = {};
52-
for (const [feature] of await getLocalHotfixes()) {
51+
for (const [feature] of brokenFeaturesStorage) {
5352
const currentFeature = getNewFeatureName(feature);
5453
if (currentFeature) {
5554
options[`feature:${currentFeature}`] = false;
@@ -60,7 +59,7 @@ export async function getLocalHotfixesAsOptions(): Promise<Partial<RghOptions>>
6059
}
6160

6261
export async function applyStyleHotfixes(style: string): Promise<void> {
63-
if (!style || isDevelopmentVersion() || isEnterprise()) {
62+
if (!style || isEnterprise()) {
6463
return;
6564
}
6665

source/helpers/isomorphic-fetch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export async function fetchText({url, options}: FetchParameters): Promise<string
1313
: ''; // Likely a 404. Either way the response isn't the CSS we expect #8142
1414
}
1515

16-
export async function isomorphicFetchText(url: string, options: RequestInit): Promise<string> {
16+
export async function webextFetch(url: string, options: RequestInit): Promise<string> {
1717
return isWebPage()
1818
// Firefox CSP issue: https://github.com/refined-github/refined-github/issues/8144
1919
? messageRuntime({fetchText: {url, options}})

source/options.css

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,12 @@ summary:hover {
9797
background: light-dark(#e3e9ef, #0e1012);
9898
}
9999

100-
[name='customCss'] {
100+
.text-code {
101101
font-size: 11px;
102102
}
103+
.text-italics {
104+
font-style: italic;
105+
}
103106

104107
.error-banner {
105108
padding: 1em;

source/options.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@
119119
<!-- eslint-disable-next-line @html-eslint/require-input-label -->
120120
<p>
121121
<textarea
122-
class="monospace-field"
122+
class="monospace-field text-code"
123123
name="customCss"
124124
rows="2"
125125
spellcheck="false"

source/options.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function informComponentOfExternalUpdate(field: HTMLInputElement | HTMLTextAreaE
4747
assertDefined(
4848
await elementReady('.js-features', {
4949
stopOnDomReady: false,
50-
signal: AbortSignal.timeout(500),
50+
signal: AbortSignal.timeout(1000),
5151
}),
5252
);
5353

source/options/feature-list.svelte

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<script lang="ts">
22
import {featuresMeta, importedFeatures} from '../feature-data.js';
3-
import {getLocalHotfixes} from '../helpers/hotfix.js';
3+
import {brokenFeatures} from '../helpers/hotfix.js';
44
55
import FeatureItem from './feature-item.svelte';
66
77
let filterText = $state('');
8-
const hotfixesPromise = getLocalHotfixes();
8+
// This will attempt to load the hotfixes because we do want an up-to-date options page
9+
const hotfixesPromise = brokenFeatures.get();
910
1011
// Pre-filter valid imported features
1112
const activeFeatures = featuresMeta.filter(feature =>

source/options/handle-expand.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
}
1414
1515
if (details.open) {
16-
querySelector('input, textarea', details)?.focus({preventScroll: true});
16+
querySelector('input:read-write, textarea:read-write', details)?.focus({
17+
preventScroll: true,
18+
});
1719
}
1820
}
1921

0 commit comments

Comments
 (0)