Skip to content

Commit ecc9331

Browse files
committed
refresh styles on bfcache restoration
1 parent 3fd1e87 commit ecc9331

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/content/apply.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ addEventListener(kPageShow, onBFCache);
8181
async function init() {
8282
if (isUnstylable) return API.styleViaAPI({method: 'styleApply'});
8383
let data;
84-
if (__.ENTRY && (data = global.clientData)) {
84+
if (__.ENTRY && (data = global[__.CLIENT_DATA])) {
8585
data = (/**@type{StylusClientData}*/__.MV3 ? data : await data).apply;
8686
} else {
8787
data = isFrameNoUrl && !FF && clone(parent[parent.Symbol.for(SYM_ID)]);
@@ -90,11 +90,11 @@ async function init() {
9090
// XML in Chrome will be auto-converted to html later, so we can't style it via XHR now
9191
}
9292
if (!chrome.runtime.id) return selfDestruct();
93-
await applyStyles(data);
93+
await applyStyles(data, true);
9494
}
9595

96-
async function applyStyles(data) {
97-
if (!data) data = await API.styles.getSectionsByUrl(matchUrl, null, !own.sections);
96+
async function applyStyles(data, isInitial = !own.sections) {
97+
if (!data) data = await API.styles.getSectionsByUrl(matchUrl, null, isInitial);
9898
if (!data.cfg) data.cfg = own.cfg;
9999
Object.assign(own, window[Symbol.for(SYM_ID)] = data);
100100
if (!isFrame && own.cfg.top === '') own.cfg.top = location.origin; // used by child frames via parentStyles
@@ -229,7 +229,7 @@ function updateCount() {
229229

230230
function onFrameElementInView(cb) {
231231
parent[parent.Symbol.for('xo')](frameElement, cb);
232-
(offscreen || (offscreen = [])).push(cb);
232+
(offscreen ??= []).push(cb);
233233
}
234234

235235
/** @param {IntersectionObserverEntry[]} entries */
@@ -247,7 +247,7 @@ function onBFCache(e) {
247247
if (!chrome.runtime.id) return selfDestruct();
248248
if (e.isTrusted && e.persisted) {
249249
throttledCount = '';
250-
updateCount();
250+
init(); // styles may have been toggled while we were in bfcache
251251
}
252252
}
253253

0 commit comments

Comments
 (0)